-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
261 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...FieldType/Tests/Integration/BinaryBase/BinaryBaseStorage/BinaryBaseStorageGatewayTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace eZ\Publish\Core\FieldType\Tests\Integration\BinaryBase\BinaryBaseStorage; | ||
|
||
use eZ\Publish\API\Repository\Values\Content\ContentInfo; | ||
use eZ\Publish\Core\FieldType\BinaryBase\BinaryBaseStorage\Gateway as BinaryBaseStorageGateway; | ||
use eZ\Publish\Core\FieldType\BinaryFile\BinaryFileStorage\Gateway\DoctrineStorage; | ||
use eZ\Publish\Core\FieldType\Tests\Integration\BaseCoreFieldTypeIntegrationTest; | ||
use eZ\Publish\SPI\Persistence\Content\Field; | ||
use eZ\Publish\SPI\Persistence\Content\FieldValue; | ||
use eZ\Publish\SPI\Persistence\Content\VersionInfo; | ||
use eZ\Publish\SPI\Tests\Persistence\FixtureImporter; | ||
use eZ\Publish\SPI\Tests\Persistence\YamlFixture; | ||
|
||
/** | ||
* BinaryBase Field Type external storage gateway tests. | ||
*/ | ||
class BinaryBaseStorageGatewayTest extends BaseCoreFieldTypeIntegrationTest | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$importer = new FixtureImporter($this->getDatabaseConnection()); | ||
$importer->import(new YamlFixture(__DIR__ . '/_fixtures/ezbinaryfile.yaml')); | ||
} | ||
|
||
protected function getGateway(): BinaryBaseStorageGateway | ||
{ | ||
return new DoctrineStorage($this->getDatabaseConnection()); | ||
} | ||
|
||
public function testGetFileReferenceWithFixture(): void | ||
{ | ||
$data = $this->getGateway()->getFileReferenceData(10, 1); | ||
|
||
$expected = [ | ||
'id' => 'image/a6bbf351175ad9c2f27e5b17c2c5d105.png', | ||
'mimeType' => 'image/png', | ||
'fileName' => 'test.png', | ||
'downloadCount' => 0, | ||
]; | ||
|
||
self::assertEquals($expected, $data); | ||
} | ||
|
||
public function testStoreFileReference(): void | ||
{ | ||
$field = new Field(); | ||
$field->id = 123; | ||
$field->fieldDefinitionId = 231; | ||
$field->type = 'ezbinaryfile'; | ||
$field->versionNo = 1; | ||
$field->value = new FieldValue([ | ||
'externalData' => [ | ||
'id' => 'image/809c753a26e11f363cd8c14d824d162a.jpg', | ||
'path' => '/tmp/phpR4tNSI', | ||
'inputUri' => '/tmp/phpR4tNSI', | ||
'fileName' => '1.jpg', | ||
'fileSize' => '372949', | ||
'mimeType' => 'image/jpg', | ||
'uri' => '/admin/content/download/75/320?version=1', | ||
'downloadCount' => 0, | ||
], | ||
]); | ||
|
||
$versionInfo = new VersionInfo([ | ||
'contentInfo' => new ContentInfo([ | ||
'id' => 1, | ||
]), | ||
'versionNo' => 1, | ||
]); | ||
|
||
$this->getGateway()->storeFileReference($versionInfo, $field); | ||
|
||
$data = $this->getGateway()->getFileReferenceData(123, 1); | ||
|
||
$expected = [ | ||
'id' => 'image/809c753a26e11f363cd8c14d824d162a.jpg', | ||
'mimeType' => 'image/jpg', | ||
'fileName' => '1.jpg', | ||
'downloadCount' => 0, | ||
]; | ||
|
||
self::assertEquals($expected, $data); | ||
} | ||
} |
163 changes: 163 additions & 0 deletions
163
...h/Core/FieldType/Tests/Integration/BinaryBase/BinaryBaseStorage/BinaryBaseStorageTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace eZ\Publish\Core\FieldType\Tests\Integration\BinaryBase\BinaryBaseStorage; | ||
|
||
use eZ\Publish\API\Repository\Values\Content\ContentInfo; | ||
use eZ\Publish\Core\FieldType\BinaryBase\BinaryBaseStorage; | ||
use eZ\Publish\Core\FieldType\BinaryBase\BinaryBaseStorage\Gateway; | ||
use eZ\Publish\Core\FieldType\BinaryFile\BinaryFileStorage\Gateway\DoctrineStorage; | ||
use eZ\Publish\Core\FieldType\Tests\Integration\BaseCoreFieldTypeIntegrationTest; | ||
use eZ\Publish\Core\IO\IOServiceInterface; | ||
use eZ\Publish\Core\IO\Values\BinaryFile; | ||
use eZ\Publish\Core\IO\Values\BinaryFileCreateStruct; | ||
use eZ\Publish\SPI\FieldType\BinaryBase\PathGenerator; | ||
use eZ\Publish\SPI\IO\MimeTypeDetector; | ||
use eZ\Publish\SPI\Persistence\Content\Field; | ||
use eZ\Publish\SPI\Persistence\Content\FieldValue; | ||
use eZ\Publish\SPI\Persistence\Content\VersionInfo; | ||
|
||
class BinaryBaseStorageTest extends BaseCoreFieldTypeIntegrationTest | ||
{ | ||
/** @var \eZ\Publish\Core\FieldType\BinaryBase\BinaryBaseStorage\Gateway|\PHPUnit\Framework\MockObject\MockObject */ | ||
protected $gateway; | ||
|
||
/** @var \eZ\Publish\SPI\FieldType\BinaryBase\PathGenerator|\PHPUnit\Framework\MockObject\MockObject */ | ||
protected $pathGeneratorMock; | ||
|
||
/** @var \eZ\Publish\Core\IO\IOServiceInterface|\PHPUnit\Framework\MockObject\MockObject */ | ||
protected $ioServiceMock; | ||
|
||
/** @var \eZ\Publish\Core\FieldType\BinaryBase\BinaryBaseStorage|\PHPUnit\Framework\MockObject\MockObject */ | ||
protected $storage; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->gateway = $this->getStorageGateway(); | ||
$this->pathGeneratorMock = $this->createMock(PathGenerator::class); | ||
$this->ioServiceMock = $this->createMock(IOServiceInterface::class); | ||
$this->storage = $this->getMockBuilder(BinaryBaseStorage::class) | ||
->onlyMethods([]) | ||
->setConstructorArgs( | ||
[ | ||
$this->gateway, | ||
$this->ioServiceMock, | ||
$this->pathGeneratorMock, | ||
$this->createMock(MimeTypeDetector::class), | ||
] | ||
) | ||
->getMock(); | ||
} | ||
|
||
protected function getContext(): array | ||
{ | ||
return ['context']; | ||
} | ||
|
||
public function testHasFieldData(): void | ||
{ | ||
self::assertTrue($this->storage->hasFieldData()); | ||
} | ||
|
||
/** | ||
* @dataProvider providerOfFieldData | ||
*/ | ||
public function testStoreFieldData(VersionInfo $versionInfo, Field $field): void | ||
{ | ||
$binaryFileCreateStruct = new BinaryFileCreateStruct([ | ||
'id' => 'qwerty12345', | ||
'size' => '372949', | ||
'mimeType' => 'image/jpeg', | ||
]); | ||
|
||
$this->ioServiceMock | ||
->expects(self::once()) | ||
->method('newBinaryCreateStructFromLocalFile') | ||
->will($this->returnValue($binaryFileCreateStruct)); | ||
|
||
$this->pathGeneratorMock | ||
->expects(self::once()) | ||
->method('getStoragePathForField') | ||
->with($field, $versionInfo) | ||
->willReturn('image/qwerty12345.jpg'); | ||
|
||
$this->ioServiceMock | ||
->expects(self::once()) | ||
->method('createBinaryFile') | ||
->with($binaryFileCreateStruct) | ||
->willReturn(new BinaryFile()); | ||
|
||
$this->storage->storeFieldData($versionInfo, $field, $this->getContext()); | ||
|
||
$this->expectNotToPerformAssertions(); | ||
} | ||
|
||
/** | ||
* @depends testStoreFieldData | ||
* | ||
* @dataProvider providerOfFieldData | ||
*/ | ||
public function testCopyLegacyField(VersionInfo $versionInfo, Field $originalField): void | ||
{ | ||
$field = clone $originalField; | ||
$field->id = 124; | ||
$field->versionNo = 2; | ||
$field->value = new FieldValue([ | ||
'externalData' => [ | ||
'fileName' => '123.jpg', | ||
'downloadCount' => 0, | ||
'mimeType' => null, | ||
'uri' => null, | ||
], | ||
]); | ||
|
||
$flag = $this->storage->copyLegacyField($versionInfo, $field, $originalField, $this->getContext()); | ||
|
||
self::assertFalse($flag); | ||
} | ||
|
||
public function providerOfFieldData(): array | ||
{ | ||
$field = new Field(); | ||
$field->id = 124; | ||
$field->fieldDefinitionId = 231; | ||
$field->type = 'ezbinaryfile'; | ||
$field->versionNo = 1; | ||
$field->value = new FieldValue([ | ||
'externalData' => [ | ||
'id' => 'image/aaac753a26e11f363cd8c14d824d162a.jpg', | ||
'path' => '/tmp/phpR4tNSV', | ||
'inputUri' => '/tmp/phpR4tNSV', | ||
'fileName' => '123.jpg', | ||
'fileSize' => '12345', | ||
'mimeType' => 'image/jpeg', | ||
'uri' => '/admin/content/download/75/320?version=1', | ||
'downloadCount' => 0, | ||
], | ||
]); | ||
|
||
$versionInfo = new VersionInfo([ | ||
'contentInfo' => new ContentInfo([ | ||
'id' => 235, | ||
'contentTypeId' => 24, | ||
]), | ||
'versionNo' => 1, | ||
]); | ||
|
||
return [ | ||
[$versionInfo, $field], | ||
]; | ||
} | ||
|
||
protected function getStorageGateway(): Gateway | ||
{ | ||
return new DoctrineStorage($this->getDatabaseConnection()); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
...Core/FieldType/Tests/Integration/BinaryBase/BinaryBaseStorage/_fixtures/ezbinaryfile.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ezbinaryfile: | ||
- { contentobject_attribute_id: 10, version: 1, download_count: 0, filename: a6bbf351175ad9c2f27e5b17c2c5d105.png, mime_type: image/png, original_filename: test.png } |