Skip to content

Commit

Permalink
fixup! Added tests for DB gateway service
Browse files Browse the repository at this point in the history
  • Loading branch information
vidarl committed Oct 17, 2018
1 parent be735ef commit ea0b972
Showing 1 changed file with 39 additions and 59 deletions.
98 changes: 39 additions & 59 deletions tests/bundle/Command/GatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,37 +48,34 @@ public function testGetContentTypeIds($identifiers, $expected)
$this->assertEquals($expected, $ids);
}

public function convertFieldDefinitionsProvider()
public function testCountContentTypeFieldsByFieldType()
{
return [
[
true,
],
[
false,
],
];
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/contentclass_attribute.php');
$gatewayService = $this->getGatewayService();

$count = $gatewayService->countContentTypeFieldsByFieldType('ezxmltext');
$this->assertEquals(2, $count, 'Expected to find 2 content type fields');

$count = $gatewayService->countContentTypeFieldsByFieldType('ezstring');
$this->assertEquals(1, $count, 'Expected to find 1 content type field');

$count = $gatewayService->countContentTypeFieldsByFieldType('foobar');
$this->assertEquals(0, $count, 'Expected to find 0 content type fields');
}

/**
* @dataProvider convertFieldDefinitionsProvider
* @param $dry boolean
*/
public function testConvertFieldDefinitions($dry)
public function testGetContentTypeFieldTypeUpdateQuery()
{
$outputStub = $this->createMock(OutputInterface::class);
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/contentclass_attribute.php');
$gatewayService = $this->getGatewayService();
$count1 = $gatewayService->convertFieldDefinitions($dry, $outputStub);
$count2 = $gatewayService->convertFieldDefinitions($dry, $outputStub);

if ($dry) {
$this->assertEquals(2, $count1, 'Expected to find 2 field definitions subject for conversion');
$this->assertEquals(2, $count2, 'Expected to find 2 field definitions subject for conversion after running in dry mode');
} else {
$this->assertEquals(2, $count1, 'Expected to find 2 field definitions subject for conversion');
$this->assertEquals(0, $count2, 'Expected all field definitions to be converted');
}

$count1 = $gatewayService->countContentTypeFieldsByFieldType('ezxmltext');
$this->assertEquals(2, $count1, 'Expected to find 2 field definitions subject for conversion');

$updateQuery = $gatewayService->getContentTypeFieldTypeUpdateQuery('ezxmltext', 'ezrichtext');
$updateQuery->execute();

$count2 = $gatewayService->countContentTypeFieldsByFieldType('ezxmltext');
$this->assertEquals(0, $count2, 'Expected all field definitions to be converted');
}

public function getRowCountOfContentObjectAttributesProvider()
Expand Down Expand Up @@ -301,29 +298,15 @@ public function getAllFieldRows()
return $rows;
}

public function updateFieldRowProvider()
public function getUpdateFieldRowQueryProvider()
{
return [
[
true,
283,
1,
'foobar',
],
[
false,
283,
1,
'foobar',
],
[
true,
295,
1,
'foobar',
],
[
false,
295,
1,
'foobar',
Expand All @@ -332,41 +315,38 @@ public function updateFieldRowProvider()
}

/**
* @dataProvider updateFieldRowProvider
* @dataProvider getUpdateFieldRowQueryProvider
* @param $dryRun
* @param $id
* @param $version
* @param $datatext
*/
public function testUpdateFieldRow($dryRun, $id, $version, $datatext)
public function testGetUpdateFieldRowQuery($id, $version, $datatext)
{
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/contentobject_attribute.php');

$gatewayService = $this->getGatewayService();
$originalRows = $this->getAllFieldRows();

$gatewayService->updateFieldRow($dryRun, $id, $version, $datatext);
$updateQuery = $gatewayService->getUpdateFieldRowQuery($id, $version, $datatext);
$updateQuery->execute();

$updatedRows = $this->getAllFieldRows();
if ($dryRun) {
$this->assertEquals($originalRows, $updatedRows, 'Rows should not have been updated by updateFieldRow()');
} else {
foreach ($originalRows as $key => $expectedRow) {
if ($expectedRow['id'] == $id && $expectedRow['version'] == $version) {
$expectedRow['data_text'] = $datatext;
$expectedRow['data_type_string'] = 'ezrichtext';
}
foreach ($originalRows as $key => $expectedRow) {
if ($expectedRow['id'] == $id && $expectedRow['version'] == $version) {
$expectedRow['data_text'] = $datatext;
$expectedRow['data_type_string'] = 'ezrichtext';
}

$rowFound = false;
foreach ($updatedRows as $updatedRow) {
if ($expectedRow['id'] == $updatedRow['id'] && $expectedRow['version'] == $updatedRow['version'] && $expectedRow['language_code'] == $updatedRow['language_code']) {
$this->assertEquals($expectedRow, $updatedRow, 'Table row is not correct');
$rowFound = true;
break;
}
$rowFound = false;
foreach ($updatedRows as $updatedRow) {
if ($expectedRow['id'] == $updatedRow['id'] && $expectedRow['version'] == $updatedRow['version'] && $expectedRow['language_code'] == $updatedRow['language_code']) {
$this->assertEquals($expectedRow, $updatedRow, 'Table row is not correct');
$rowFound = true;
break;
}
$this->assertTrue($rowFound, "Row seems to have disappeared from db where id=$id and version=$version");
}
$this->assertTrue($rowFound, "Row seems to have disappeared from db where id=$id and version=$version");
}
}

Expand Down

0 comments on commit ea0b972

Please sign in to comment.