Skip to content

Commit

Permalink
[Unit Tests] Replaced DatabaseHandler usages with Doctrine\DBAL
Browse files Browse the repository at this point in the history
  • Loading branch information
alongosz committed Mar 27, 2020
1 parent a385b16 commit 130c80e
Show file tree
Hide file tree
Showing 16 changed files with 548 additions and 484 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public function testInsertContentObject()
'status' => ContentInfo::STATUS_DRAFT,
],
],
$this->getDatabaseHandler()
->createSelectQuery()
$this->getDatabaseConnection()
->createQueryBuilder()
->select(
[
'name',
Expand Down Expand Up @@ -154,7 +154,7 @@ protected function getVersionFixture()
$version->status = 0;
$version->creationDate = 1312278322;
$version->modificationDate = 1312278323;
$version->initialLanguageCode = 'eng-GB';
$version->initialLanguageCode = self::ENG_GB;
$version->contentInfo = new ContentInfo(
[
'id' => 2342,
Expand Down Expand Up @@ -192,8 +192,8 @@ public function testInsertVersion()
// 'user_id',
],
],
$this->getDatabaseHandler()
->createSelectQuery()
$this->getDatabaseConnection()
->createQueryBuilder()
->select(
[
'contentobject_id',
Expand Down Expand Up @@ -232,17 +232,17 @@ public function testSetStatus()

$this->assertQueryResult(
[[VersionInfo::STATUS_PENDING]],
$this->getDatabaseHandler()
->createSelectQuery()
$this->getDatabaseConnection()
->createQueryBuilder()
->select('status')
->from('ezcontentobject_version')
);

// check that content status has not been set to published
$this->assertQueryResult(
[[VersionInfo::STATUS_DRAFT]],
$this->getDatabaseHandler()
->createSelectQuery()
$this->getDatabaseConnection()
->createQueryBuilder()
->select('status')
->from('ezcontentobject')
);
Expand Down Expand Up @@ -270,17 +270,17 @@ public function testSetStatusPublished()

$this->assertQueryResult(
[[VersionInfo::STATUS_PUBLISHED]],
$this->getDatabaseHandler()
->createSelectQuery()
$this->getDatabaseConnection()
->createQueryBuilder()
->select('status')
->from('ezcontentobject_version')
);

// check that content status has been set to published
$this->assertQueryResult(
[[ContentInfo::STATUS_PUBLISHED]],
$this->getDatabaseHandler()
->createSelectQuery()
$this->getDatabaseConnection()
->createQueryBuilder()
->select('status')
->from('ezcontentobject')
);
Expand Down Expand Up @@ -324,7 +324,7 @@ public function testUpdateContent()
'name' => 'Thoth',
],
],
$this->getDatabaseHandler()->createSelectQuery()
$this->getDatabaseConnection()->createQueryBuilder()
->select(
'initial_language_id',
'modified',
Expand Down Expand Up @@ -384,7 +384,8 @@ public function testUpdateVersion()

$gateway->updateVersion(10, 2, $this->getUpdateStructFixture());

$query = $this->getDatabaseHandler()->createSelectQuery();
$query = $this->getDatabaseConnection()->createQueryBuilder();
$expr = $query->expr();
$this->assertQueryResult(
[
[
Expand All @@ -402,9 +403,9 @@ public function testUpdateVersion()
]
)->from('ezcontentobject_version')
->where(
$query->expr->lAnd(
$query->expr->eq('contentobject_id', 10),
$query->expr->eq('version', 2)
$expr->andX(
$expr->eq('contentobject_id', 10),
$expr->eq('version', 2)
)
)
);
Expand Down Expand Up @@ -433,15 +434,15 @@ public function testInsertNewField()
'data_int' => '42',
'data_text' => 'Test text',
'data_type_string' => 'ezstring',
'language_code' => 'eng-GB',
'language_code' => self::ENG_GB,
'language_id' => '4',
'sort_key_int' => '23',
'sort_key_string' => 'Test',
'version' => '1',
],
],
$this->getDatabaseHandler()
->createSelectQuery()
$this->getDatabaseConnection()
->createQueryBuilder()
->select(
[
'contentclassattribute_id',
Expand All @@ -468,7 +469,7 @@ public function testInsertNewAlwaysAvailableField()
$content = $this->getContentFixture();
$content->versionInfo->contentInfo->id = 2342;
// Set main language to the one used in the field fixture
$content->versionInfo->contentInfo->mainLanguageCode = 'eng-GB';
$content->versionInfo->contentInfo->mainLanguageCode = self::ENG_GB;

$field = $this->getFieldFixture();
$value = $this->getStorageValueFixture();
Expand All @@ -485,15 +486,15 @@ public function testInsertNewAlwaysAvailableField()
'data_int' => '42',
'data_text' => 'Test text',
'data_type_string' => 'ezstring',
'language_code' => 'eng-GB',
'language_code' => self::ENG_GB,
'language_id' => '5',
'sort_key_int' => '23',
'sort_key_string' => 'Test',
'version' => '1',
],
],
$this->getDatabaseHandler()
->createSelectQuery()
$this->getDatabaseConnection()
->createQueryBuilder()
->select(
[
'contentclassattribute_id',
Expand Down Expand Up @@ -549,8 +550,8 @@ public function testUpdateField()
'sort_key_string' => 'new_text',
],
],
$this->getDatabaseHandler()
->createSelectQuery()
$this->getDatabaseConnection()
->createQueryBuilder()
->select(
[
'data_float',
Expand Down Expand Up @@ -612,8 +613,8 @@ public function testUpdateNonTranslatableField()
'sort_key_string' => 'new_text',
],
],
$this->getDatabaseHandler()
->createSelectQuery()
$this->getDatabaseConnection()
->createQueryBuilder()
->select(
[
'data_float',
Expand Down Expand Up @@ -732,7 +733,7 @@ public function testLoadWithAllTranslations()

$this->assertValuesInRows(
'ezcontentobject_attribute_language_code',
['eng-US', 'eng-GB'],
['eng-US', self::ENG_GB],
$res
);

Expand Down Expand Up @@ -805,11 +806,11 @@ public function testLoadWithSingleTranslation()
);

$gateway = $this->getDatabaseGateway();
$res = $gateway->load(226, 2, ['eng-GB']);
$res = $gateway->load(226, 2, [self::ENG_GB]);

$this->assertValuesInRows(
'ezcontentobject_attribute_language_code',
['eng-GB'],
[self::ENG_GB],
$res
);
$this->assertValuesInRows(
Expand Down Expand Up @@ -1183,11 +1184,11 @@ public function testSetName()

$gateway = $this->getDatabaseGateway();

$gateway->setName(14, 2, 'Hello world!', 'eng-GB');
$gateway->setName(14, 2, 'Hello world!', self::ENG_GB);

$query = $this->getDatabaseHandler()->createSelectQuery();
$query = $this->getDatabaseConnection()->createQueryBuilder();
$this->assertQueryResult(
[['eng-GB', 2, 14, 4, 'Hello world!', 'eng-GB']],
[[self::ENG_GB, 2, 14, 4, 'Hello world!', self::ENG_GB]],
$query
->select(
[
Expand All @@ -1200,13 +1201,12 @@ public function testSetName()
]
)
->from('ezcontentobject_name')
->where(
$query->expr->lAnd(
$query->expr->eq('contentobject_id', 14),
$query->expr->eq('content_version', 2),
$query->expr->eq('content_translation', $query->bindValue('eng-GB'))
)
)
->where('contentobject_id = :content_id')
->andWhere('content_version = :version_no')
->andWhere('content_translation = :language_code')
->setParameter('content_id', 14, ParameterType::INTEGER)
->setParameter('version_no', 2, ParameterType::INTEGER)
->setParameter('language_code', self::ENG_GB, ParameterType::STRING)
);
}

Expand Down Expand Up @@ -1482,8 +1482,8 @@ public function testInsertRelation()
'relation_type' => $struct->type,
],
],
$this->getDatabaseHandler()
->createSelectQuery()
$this->getDatabaseConnection()
->createQueryBuilder()
->select(
[
'id',
Expand Down Expand Up @@ -2007,7 +2007,7 @@ protected function getFieldFixture()

$field->fieldDefinitionId = 231;
$field->type = 'ezstring';
$field->languageCode = 'eng-GB';
$field->languageCode = self::ENG_GB;
$field->versionNo = 1;

return $field;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function testInsertLanguage()
'disabled' => '0',
],
],
$this->getDatabaseHandler()->createSelectQuery()
$this->getDatabaseConnection()->createQueryBuilder()
->select('id', 'locale', 'name', 'disabled')
->from('ezcontent_language')
->where('id=8')
Expand Down Expand Up @@ -97,7 +97,7 @@ public function testUpdateLanguage()
'disabled' => '0',
],
],
$this->getDatabaseHandler()->createSelectQuery()
$this->getDatabaseConnection()->createQueryBuilder()
->select('id', 'locale', 'name', 'disabled')
->from('ezcontent_language')
->where('id=2')
Expand Down Expand Up @@ -171,7 +171,7 @@ public function testDeleteLanguage()
'count' => '1',
],
],
$this->getDatabaseHandler()->createSelectQuery()
$this->getDatabaseConnection()->createQueryBuilder()
->select('COUNT( * ) AS count')
->from('ezcontent_language')
);
Expand All @@ -182,7 +182,7 @@ public function testDeleteLanguage()
'count' => '0',
],
],
$this->getDatabaseHandler()->createSelectQuery()
$this->getDatabaseConnection()->createQueryBuilder()
->select('COUNT( * ) AS count')
->from('ezcontent_language')
->where('id=2')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php

/**
* File contains: eZ\Publish\Core\Persistence\Legacy\Tests\Content\LanguageAwareTestCase class.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
Expand All @@ -20,6 +18,8 @@
*/
abstract class LanguageAwareTestCase extends TestCase
{
protected const ENG_GB = 'eng-GB';

/**
* Language handler.
*
Expand Down
Loading

0 comments on commit 130c80e

Please sign in to comment.