Skip to content

Commit

Permalink
EZP-32283: Minor tweaks to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
barw4 committed Feb 10, 2021
1 parent 923e080 commit 920c2ed
Showing 1 changed file with 21 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,15 @@ class BinaryBaseStorageTest extends TestCase
/** @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
{
$this->gatewayMock = $this->getStorageGateway();
$this->pathGeneratorMock = $this->createMock(PathGenerator::class);
$this->ioServiceMock = $this->createMock(IOServiceInterface::class);
}

/**
* @return \eZ\Publish\Core\FieldType\BinaryBase\BinaryBaseStorage|\PHPUnit\Framework\MockObject\MockObject
*/
protected function getPartlyMockedStorage(): BinaryBaseStorage
{
return $this->getMockBuilder(BinaryBaseStorage::class)
$this->storage = $this->getMockBuilder(BinaryBaseStorage::class)
->setMethods(null)
->setConstructorArgs(
[
Expand All @@ -63,18 +59,14 @@ protected function getContext(): array

public function testHasFieldData(): void
{
$storage = $this->getPartlyMockedStorage();

$this->assertTrue($storage->hasFieldData());
$this->assertTrue($this->storage->hasFieldData());
}

/**
* @dataProvider providerOfFieldData
*/
public function testStoreFieldData(VersionInfo $versionInfo, Field $field): void
{
$storage = $this->getPartlyMockedStorage();

$binaryFileCreateStruct = new BinaryFileCreateStruct([
'id' => 'qwerty12345',
'size' => '372949',
Expand All @@ -98,54 +90,49 @@ public function testStoreFieldData(VersionInfo $versionInfo, Field $field): void
->with($binaryFileCreateStruct)
->willReturn(new BinaryFile());

$this->ioServiceMock
->expects($this->any())
->method('loadBinaryFile')
->with($field->value->externalData['id'])
->willReturn(new BinaryFile());

$storage->storeFieldData($versionInfo, $field, $this->getContext());
$this->storage->storeFieldData($versionInfo, $field, $this->getContext());

$this->doesNotPerformAssertions();
$this->expectNotToPerformAssertions();
}

/**
* @depends testStoreFieldData
*
* @dataProvider providerOfFieldData
*/
public function testCopyLegacyField(VersionInfo $versionInfo, Field $originalField): void
{
$storage = $this->getPartlyMockedStorage();

$field = clone $originalField;
$field->id = 124;
$field->versionNo = 2;
$field->value = new FieldValue([
'externalData' => [
'fileName' => '1.jpg',
'fileName' => '123.jpg',
'downloadCount' => 0,
'mimeType' => null,
'uri' => null,
],
]);

$storage->copyLegacyField($versionInfo, $field, $originalField, $this->getContext());
$flag = $this->storage->copyLegacyField($versionInfo, $field, $originalField, $this->getContext());

$this->doesNotPerformAssertions();
$this->assertFalse($flag);
}

public function providerOfFieldData(): array
{
$field = new Field();
$field->id = 123;
$field->id = 124;
$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',
'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,
Expand All @@ -154,7 +141,8 @@ public function providerOfFieldData(): array

$versionInfo = new VersionInfo([
'contentInfo' => new ContentInfo([
'id' => 1,
'id' => 235,
'contentTypeId' => 24,
]),
'versionNo' => 1,
]);
Expand Down

0 comments on commit 920c2ed

Please sign in to comment.