diff --git a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/Gateway/DoctrineDatabaseTest.php b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/Gateway/DoctrineDatabaseTest.php index 5e36d1c03a..4d8afe35b1 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/Gateway/DoctrineDatabaseTest.php +++ b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/Gateway/DoctrineDatabaseTest.php @@ -61,8 +61,8 @@ public function testInsertContentObject() 'status' => ContentInfo::STATUS_DRAFT, ], ], - $this->getDatabaseHandler() - ->createSelectQuery() + $this->getDatabaseConnection() + ->createQueryBuilder() ->select( [ 'name', @@ -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, @@ -192,8 +192,8 @@ public function testInsertVersion() // 'user_id', ], ], - $this->getDatabaseHandler() - ->createSelectQuery() + $this->getDatabaseConnection() + ->createQueryBuilder() ->select( [ 'contentobject_id', @@ -232,8 +232,8 @@ public function testSetStatus() $this->assertQueryResult( [[VersionInfo::STATUS_PENDING]], - $this->getDatabaseHandler() - ->createSelectQuery() + $this->getDatabaseConnection() + ->createQueryBuilder() ->select('status') ->from('ezcontentobject_version') ); @@ -241,8 +241,8 @@ public function testSetStatus() // 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') ); @@ -270,8 +270,8 @@ public function testSetStatusPublished() $this->assertQueryResult( [[VersionInfo::STATUS_PUBLISHED]], - $this->getDatabaseHandler() - ->createSelectQuery() + $this->getDatabaseConnection() + ->createQueryBuilder() ->select('status') ->from('ezcontentobject_version') ); @@ -279,8 +279,8 @@ public function testSetStatusPublished() // check that content status has been set to published $this->assertQueryResult( [[ContentInfo::STATUS_PUBLISHED]], - $this->getDatabaseHandler() - ->createSelectQuery() + $this->getDatabaseConnection() + ->createQueryBuilder() ->select('status') ->from('ezcontentobject') ); @@ -324,7 +324,7 @@ public function testUpdateContent() 'name' => 'Thoth', ], ], - $this->getDatabaseHandler()->createSelectQuery() + $this->getDatabaseConnection()->createQueryBuilder() ->select( 'initial_language_id', 'modified', @@ -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( [ [ @@ -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) ) ) ); @@ -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', @@ -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(); @@ -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', @@ -549,8 +550,8 @@ public function testUpdateField() 'sort_key_string' => 'new_text', ], ], - $this->getDatabaseHandler() - ->createSelectQuery() + $this->getDatabaseConnection() + ->createQueryBuilder() ->select( [ 'data_float', @@ -612,8 +613,8 @@ public function testUpdateNonTranslatableField() 'sort_key_string' => 'new_text', ], ], - $this->getDatabaseHandler() - ->createSelectQuery() + $this->getDatabaseConnection() + ->createQueryBuilder() ->select( [ 'data_float', @@ -732,7 +733,7 @@ public function testLoadWithAllTranslations() $this->assertValuesInRows( 'ezcontentobject_attribute_language_code', - ['eng-US', 'eng-GB'], + ['eng-US', self::ENG_GB], $res ); @@ -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( @@ -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( [ @@ -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) ); } @@ -1482,8 +1482,8 @@ public function testInsertRelation() 'relation_type' => $struct->type, ], ], - $this->getDatabaseHandler() - ->createSelectQuery() + $this->getDatabaseConnection() + ->createQueryBuilder() ->select( [ 'id', @@ -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; diff --git a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/Language/Gateway/DoctrineDatabaseTest.php b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/Language/Gateway/DoctrineDatabaseTest.php index 95d5253137..6a666c7aef 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/Language/Gateway/DoctrineDatabaseTest.php +++ b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/Language/Gateway/DoctrineDatabaseTest.php @@ -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') @@ -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') @@ -171,7 +171,7 @@ public function testDeleteLanguage() 'count' => '1', ], ], - $this->getDatabaseHandler()->createSelectQuery() + $this->getDatabaseConnection()->createQueryBuilder() ->select('COUNT( * ) AS count') ->from('ezcontent_language') ); @@ -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') diff --git a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/LanguageAwareTestCase.php b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/LanguageAwareTestCase.php index 9287bafe7c..7288fed7b2 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/LanguageAwareTestCase.php +++ b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/LanguageAwareTestCase.php @@ -1,8 +1,6 @@ insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); - $handler = $this->getLocationGateway(); - $data = $handler->getBasicNodeDataByRemoteId('dbc2f3c8716c12f32c379dbf0b1cb133'); + $gateway = $this->getLocationGateway(); + $data = $gateway->getBasicNodeDataByRemoteId('dbc2f3c8716c12f32c379dbf0b1cb133'); self::assertLoadLocationProperties($data); } @@ -71,8 +72,8 @@ public function testLoadLocationByRemoteId() public function testLoadLocation() { $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); - $handler = $this->getLocationGateway(); - $data = $handler->getBasicNodeData(77); + $gateway = $this->getLocationGateway(); + $data = $gateway->getBasicNodeData(77); self::assertLoadLocationProperties($data); } @@ -80,8 +81,8 @@ public function testLoadLocation() public function testLoadLocationList() { $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); - $handler = $this->getLocationGateway(); - $locationsData = $handler->getNodeDataList([77]); + $gateway = $this->getLocationGateway(); + $locationsData = $gateway->getNodeDataList([77]); self::assertCount(1, $locationsData); @@ -95,8 +96,8 @@ public function testLoadInvalidLocation() $this->expectException(\eZ\Publish\API\Repository\Exceptions\NotFoundException::class); $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); - $handler = $this->getLocationGateway(); - $handler->getBasicNodeData(1337); + $gateway = $this->getLocationGateway(); + $gateway->getBasicNodeData(1337); } public function testLoadLocationDataByContent() @@ -143,8 +144,8 @@ public function testLoadLocationDataByContentLimitSubtree() public function testMoveSubtreePathUpdate() { $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); - $handler = $this->getLocationGateway(); - $handler->moveSubtreeNodes( + $gateway = $this->getLocationGateway(); + $gateway->moveSubtreeNodes( [ 'path_string' => '/1/2/69/', 'path_identification_string' => 'products', @@ -159,8 +160,7 @@ public function testMoveSubtreePathUpdate() ] ); - /** @var $query \eZ\Publish\Core\Persistence\Database\SelectQuery */ - $query = $this->handler->createSelectQuery(); + $query = $this->getDatabaseConnection()->createQueryBuilder(); $this->assertQueryResult( [ [65, '/1/2/', '', 1, 1, 0, 0], @@ -170,9 +170,17 @@ public function testMoveSubtreePathUpdate() [75, '/1/2/77/', 'solutions', 2, 2, 0, 0], ], $query - ->select('contentobject_id', 'path_string', 'path_identification_string', 'parent_node_id', 'depth', 'is_hidden', 'is_invisible') + ->select( + 'contentobject_id', + 'path_string', + 'path_identification_string', + 'parent_node_id', + 'depth', + 'is_hidden', + 'is_invisible' + ) ->from('ezcontentobject_tree') - ->where($query->expr->in('node_id', [69, 71, 75, 77, 2])) + ->where($query->expr()->in('node_id', [69, 71, 75, 77, 2])) ->orderBy('contentobject_id') ); } @@ -180,9 +188,9 @@ public function testMoveSubtreePathUpdate() public function testMoveHiddenDestinationUpdate() { $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); - $handler = $this->getLocationGateway(); - $handler->hideSubtree('/1/2/77/'); - $handler->moveSubtreeNodes( + $gateway = $this->getLocationGateway(); + $gateway->hideSubtree('/1/2/77/'); + $gateway->moveSubtreeNodes( [ 'path_string' => '/1/2/69/', 'path_identification_string' => 'products', @@ -197,8 +205,7 @@ public function testMoveHiddenDestinationUpdate() ] ); - /** @var $query \eZ\Publish\Core\Persistence\Database\SelectQuery */ - $query = $this->handler->createSelectQuery(); + $query = $this->getDatabaseConnection()->createQueryBuilder(); $this->assertQueryResult( [ [65, '/1/2/', '', 1, 1, 0, 0], @@ -208,9 +215,17 @@ public function testMoveHiddenDestinationUpdate() [75, '/1/2/77/', 'solutions', 2, 2, 1, 1], ], $query - ->select('contentobject_id', 'path_string', 'path_identification_string', 'parent_node_id', 'depth', 'is_hidden', 'is_invisible') + ->select( + 'contentobject_id', + 'path_string', + 'path_identification_string', + 'parent_node_id', + 'depth', + 'is_hidden', + 'is_invisible' + ) ->from('ezcontentobject_tree') - ->where($query->expr->in('node_id', [69, 71, 75, 77, 2])) + ->where($query->expr()->in('node_id', [69, 71, 75, 77, 2])) ->orderBy('contentobject_id') ); } @@ -218,9 +233,9 @@ public function testMoveHiddenDestinationUpdate() public function testMoveHiddenSourceUpdate() { $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); - $handler = $this->getLocationGateway(); - $handler->hideSubtree('/1/2/69/'); - $handler->moveSubtreeNodes( + $gateway = $this->getLocationGateway(); + $gateway->hideSubtree('/1/2/69/'); + $gateway->moveSubtreeNodes( [ 'path_string' => '/1/2/69/', 'path_identification_string' => 'products', @@ -235,8 +250,7 @@ public function testMoveHiddenSourceUpdate() ] ); - /** @var $query \eZ\Publish\Core\Persistence\Database\SelectQuery */ - $query = $this->handler->createSelectQuery(); + $query = $this->getDatabaseConnection()->createQueryBuilder(); $this->assertQueryResult( [ [65, '/1/2/', '', 1, 1, 0, 0], @@ -246,9 +260,17 @@ public function testMoveHiddenSourceUpdate() [75, '/1/2/77/', 'solutions', 2, 2, 0, 0], ], $query - ->select('contentobject_id', 'path_string', 'path_identification_string', 'parent_node_id', 'depth', 'is_hidden', 'is_invisible') + ->select( + 'contentobject_id', + 'path_string', + 'path_identification_string', + 'parent_node_id', + 'depth', + 'is_hidden', + 'is_invisible' + ) ->from('ezcontentobject_tree') - ->where($query->expr->in('node_id', [69, 71, 75, 77, 2])) + ->where($query->expr()->in('node_id', [69, 71, 75, 77, 2])) ->orderBy('contentobject_id') ); } @@ -256,10 +278,10 @@ public function testMoveHiddenSourceUpdate() public function testMoveHiddenSourceChildUpdate() { $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); - $handler = $this->getLocationGateway(); - $handler->hideSubtree('/1/2/69/70/'); + $gateway = $this->getLocationGateway(); + $gateway->hideSubtree('/1/2/69/70/'); - $handler->moveSubtreeNodes( + $gateway->moveSubtreeNodes( [ 'path_string' => '/1/2/69/', 'path_identification_string' => 'products', @@ -274,8 +296,7 @@ public function testMoveHiddenSourceChildUpdate() ] ); - /** @var $query \eZ\Publish\Core\Persistence\Database\SelectQuery */ - $query = $this->handler->createSelectQuery(); + $query = $this->getDatabaseConnection()->createQueryBuilder(); $this->assertQueryResult( [ [65, '/1/2/', '', 1, 1, 0, 0], @@ -286,9 +307,17 @@ public function testMoveHiddenSourceChildUpdate() [75, '/1/2/77/', 'solutions', 2, 2, 0, 0], ], $query - ->select('contentobject_id', 'path_string', 'path_identification_string', 'parent_node_id', 'depth', 'is_hidden', 'is_invisible') + ->select( + 'contentobject_id', + 'path_string', + 'path_identification_string', + 'parent_node_id', + 'depth', + 'is_hidden', + 'is_invisible' + ) ->from('ezcontentobject_tree') - ->where($query->expr->in('node_id', [69, 70, 71, 75, 77, 2])) + ->where($query->expr()->in('node_id', [69, 70, 71, 75, 77, 2])) ->orderBy('contentobject_id') ); } @@ -299,10 +328,10 @@ public function testMoveHiddenSourceChildUpdate() public function testMoveSubtreeAssignmentUpdate() { $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); - $handler = $this->getLocationGateway(); - $handler->updateNodeAssignment(67, 2, 77, 5); + $gateway = $this->getLocationGateway(); + $gateway->updateNodeAssignment(67, 2, 77, 5); - $query = $this->handler->createSelectQuery(); + $query = $this->getDatabaseConnection()->createQueryBuilder(); $this->assertQueryResult( [ [67, 1, 0, 53, 1, 5, 77, '9cec85d730eec7578190ee95ce5a36f5', 0, 2, 1, 0, 0], @@ -326,18 +355,18 @@ public function testMoveSubtreeAssignmentUpdate() ] ) ->from('eznode_assignment') - ->where($query->expr->eq('contentobject_id', 67)) + ->where($query->expr()->eq('contentobject_id', 67)) ); } public function testUpdateSubtreeModificationTime() { $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); - $handler = $this->getLocationGateway(); + $gateway = $this->getLocationGateway(); $time = time(); - $handler->updateSubtreeModificationTime('/1/2/69/'); + $gateway->updateSubtreeModificationTime('/1/2/69/'); - $query = $this->handler->createSelectQuery(); + $query = $this->getDatabaseConnection()->createQueryBuilder(); $this->assertQueryResult( [ ['/1/'], @@ -347,7 +376,7 @@ public function testUpdateSubtreeModificationTime() $query ->select('path_string') ->from('ezcontentobject_tree') - ->where($query->expr->gte('modified_subnode', $time)) + ->where($query->expr()->gte('modified_subnode', $time)) ->orderBy('path_string') ); } @@ -355,10 +384,10 @@ public function testUpdateSubtreeModificationTime() public function testHideUpdateHidden() { $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); - $handler = $this->getLocationGateway(); - $handler->hideSubtree('/1/2/69/'); + $gateway = $this->getLocationGateway(); + $gateway->hideSubtree('/1/2/69/'); - $query = $this->handler->createSelectQuery(); + $query = $this->getDatabaseConnection()->createQueryBuilder(); $this->assertQueryResult( [ [1, 0, 0], @@ -369,7 +398,7 @@ public function testHideUpdateHidden() $query ->select('node_id', 'is_hidden', 'is_invisible') ->from('ezcontentobject_tree') - ->where($query->expr->in('node_id', [1, 2, 69, 75])) + ->where($query->expr()->in('node_id', [1, 2, 69, 75])) ->orderBy('node_id') ); } @@ -380,11 +409,11 @@ public function testHideUpdateHidden() public function testHideUnhideUpdateHidden() { $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); - $handler = $this->getLocationGateway(); - $handler->hideSubtree('/1/2/69/'); - $handler->unhideSubtree('/1/2/69/'); + $gateway = $this->getLocationGateway(); + $gateway->hideSubtree('/1/2/69/'); + $gateway->unhideSubtree('/1/2/69/'); - $query = $this->handler->createSelectQuery(); + $query = $this->getDatabaseConnection()->createQueryBuilder(); $this->assertQueryResult( [ [1, 0, 0], @@ -395,7 +424,7 @@ public function testHideUnhideUpdateHidden() $query ->select('node_id', 'is_hidden', 'is_invisible') ->from('ezcontentobject_tree') - ->where($query->expr->in('node_id', [1, 2, 69, 75])) + ->where($query->expr()->in('node_id', [1, 2, 69, 75])) ->orderBy('node_id') ); } @@ -406,12 +435,12 @@ public function testHideUnhideUpdateHidden() public function testHideUnhideParentTree() { $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); - $handler = $this->getLocationGateway(); - $handler->hideSubtree('/1/2/69/'); - $handler->hideSubtree('/1/2/69/70/'); - $handler->unhideSubtree('/1/2/69/'); + $gateway = $this->getLocationGateway(); + $gateway->hideSubtree('/1/2/69/'); + $gateway->hideSubtree('/1/2/69/70/'); + $gateway->unhideSubtree('/1/2/69/'); - $query = $this->handler->createSelectQuery(); + $query = $this->getDatabaseConnection()->createQueryBuilder(); $this->assertQueryResult( [ [1, 0, 0], @@ -424,7 +453,7 @@ public function testHideUnhideParentTree() $query ->select('node_id', 'is_hidden', 'is_invisible') ->from('ezcontentobject_tree') - ->where($query->expr->in('node_id', [1, 2, 69, 70, 71, 75])) + ->where($query->expr()->in('node_id', [1, 2, 69, 70, 71, 75])) ->orderBy('node_id') ); } @@ -435,12 +464,12 @@ public function testHideUnhideParentTree() public function testHideUnhidePartialSubtree() { $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); - $handler = $this->getLocationGateway(); - $handler->hideSubtree('/1/2/69/'); - $handler->hideSubtree('/1/2/69/70/'); - $handler->unhideSubtree('/1/2/69/70/'); + $gateway = $this->getLocationGateway(); + $gateway->hideSubtree('/1/2/69/'); + $gateway->hideSubtree('/1/2/69/70/'); + $gateway->unhideSubtree('/1/2/69/70/'); - $query = $this->handler->createSelectQuery(); + $query = $this->getDatabaseConnection()->createQueryBuilder(); $this->assertQueryResult( [ [1, 0, 0], @@ -453,7 +482,7 @@ public function testHideUnhidePartialSubtree() $query ->select('node_id', 'is_hidden', 'is_invisible') ->from('ezcontentobject_tree') - ->where($query->expr->in('node_id', [1, 2, 69, 70, 71, 75])) + ->where($query->expr()->in('node_id', [1, 2, 69, 70, 71, 75])) ->orderBy('node_id') ); } @@ -461,10 +490,10 @@ public function testHideUnhidePartialSubtree() public function testSwapLocations() { $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); - $handler = $this->getLocationGateway(); - $handler->swap(70, 78); + $gateway = $this->getLocationGateway(); + $gateway->swap(70, 78); - $query = $this->handler->createSelectQuery(); + $query = $this->getDatabaseConnection()->createQueryBuilder(); $this->assertQueryResult( [ [70, 76], @@ -473,7 +502,7 @@ public function testSwapLocations() $query ->select('node_id', 'contentobject_id') ->from('ezcontentobject_tree') - ->where($query->expr->in('node_id', [70, 78])) + ->where($query->expr()->in('node_id', [70, 78])) ->orderBy('node_id') ); } @@ -481,8 +510,8 @@ public function testSwapLocations() public function testCreateLocation() { $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); - $handler = $this->getLocationGateway(); - $handler->create( + $gateway = $this->getLocationGateway(); + $gateway->create( new CreateStruct( [ 'contentId' => 68, @@ -496,7 +525,7 @@ public function testCreateLocation() ] ); - $query = $this->handler->createSelectQuery(); + $query = $this->getDatabaseConnection()->createQueryBuilder(); $this->assertQueryResult( [ [70, '/1/2/69/70/'], @@ -506,19 +535,18 @@ public function testCreateLocation() $query ->select('node_id', 'path_string') ->from('ezcontentobject_tree') - ->where($query->expr->in('contentobject_id', [68, 75])) + ->where($query->expr()->in('contentobject_id', [68, 75])) ->orderBy('node_id') ); } /** - * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase::getMainNodeId + * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase::getMainNodeId * @depends testCreateLocation */ public function testGetMainNodeId() { - // $this->insertDatabaseFixture( __DIR__ . '/_fixtures/full_example_tree.php' ); - $handler = $this->getLocationGateway(); + $gateway = $this->getLocationGateway(); $parentLocationData = [ 'node_id' => '77', @@ -527,7 +555,7 @@ public function testGetMainNodeId() ]; // main location - $mainLocation = $handler->create( + $mainLocation = $gateway->create( new CreateStruct( [ 'contentId' => 68, @@ -540,7 +568,7 @@ public function testGetMainNodeId() ); // secondary location - $handler->create( + $gateway->create( new CreateStruct( [ 'contentId' => 68, @@ -552,10 +580,10 @@ public function testGetMainNodeId() $parentLocationData ); - $handlerReflection = new \ReflectionObject($handler); - $methodReflection = $handlerReflection->getMethod('getMainNodeId'); + $gatewayReflection = new \ReflectionObject($gateway); + $methodReflection = $gatewayReflection->getMethod('getMainNodeId'); $methodReflection->setAccessible(true); - self::assertEquals($mainLocation->id, $res = $methodReflection->invoke($handler, 68)); + self::assertEquals($mainLocation->id, $res = $methodReflection->invoke($gateway, 68)); } public static function getCreateLocationValues() @@ -578,7 +606,7 @@ public static function getCreateLocationValues() } /** - * @depends testCreateLocation + * @depends testCreateLocation * @dataProvider getCreateLocationValues */ public function testCreateLocationValues($field, $value) @@ -588,8 +616,8 @@ public function testCreateLocationValues($field, $value) } $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); - $handler = $this->getLocationGateway(); - $handler->create( + $gateway = $this->getLocationGateway(); + $gateway->create( new CreateStruct( [ 'contentId' => 68, @@ -608,13 +636,13 @@ public function testCreateLocationValues($field, $value) ] ); - $query = $this->handler->createSelectQuery(); + $query = $this->getDatabaseConnection()->createQueryBuilder(); $this->assertQueryResult( [[$value]], $query ->select($field) ->from('ezcontentobject_tree') - ->where($query->expr->eq('node_id', 228)) + ->where($query->expr()->eq('node_id', 228)) ); } @@ -637,7 +665,7 @@ public static function getCreateLocationReturnValues() } /** - * @depends testCreateLocation + * @depends testCreateLocation * @dataProvider getCreateLocationReturnValues */ public function testCreateLocationReturnValues($field, $value) @@ -647,8 +675,8 @@ public function testCreateLocationReturnValues($field, $value) } $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); - $handler = $this->getLocationGateway(); - $location = $handler->create( + $gateway = $this->getLocationGateway(); + $location = $gateway->create( new CreateStruct( [ 'contentId' => 68, @@ -687,8 +715,8 @@ public static function getUpdateLocationData() public function testUpdateLocation($field, $value) { $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); - $handler = $this->getLocationGateway(); - $handler->update( + $gateway = $this->getLocationGateway(); + $gateway->update( new Location\UpdateStruct( [ 'priority' => 23, @@ -700,44 +728,103 @@ public function testUpdateLocation($field, $value) 70 ); - $query = $this->handler->createSelectQuery(); + $query = $this->getDatabaseConnection()->createQueryBuilder(); $this->assertQueryResult( [[$value]], $query ->select($field) ->from('ezcontentobject_tree') - ->where($query->expr->in('node_id', [70])) + ->where($query->expr()->in('node_id', [70])) ); } public static function getNodeAssignmentValues() { return [ - ['contentobject_version', 1], - ['from_node_id', 0], - ['id', 215], - ['is_main', 0], - ['op_code', 3], - ['parent_node', 77], - ['parent_remote_id', 'some_id'], - ['remote_id', '0'], - ['sort_field', 2], - ['sort_order', 0], - ['is_main', 0], - ['priority', 1], - ['is_hidden', 1], + ['contentobject_version', [1]], + ['from_node_id', [0]], + ['id', [215]], + ['is_main', [0]], + ['op_code', [3]], + ['parent_node', [77]], + ['parent_remote_id', ['some_id']], + ['remote_id', ['0']], + ['sort_field', [2]], + ['sort_order', [0]], + ['is_main', [0]], + ['priority', [1]], + ['is_hidden', [1]], ]; } + private function buildGenericNodeSelectContentWithParentQuery( + int $contentId, + int $parentLocationId, + string $nodeTable, + string $parentNodeIdColumnName, + array $fields + ): QueryBuilder { + $query = $this->getDatabaseConnection()->createQueryBuilder(); + $expr = $query->expr(); + $query + ->select($fields) + ->from($nodeTable) + ->where( + $expr->eq( + 'contentobject_id', + $query->createPositionalParameter($contentId, ParameterType::INTEGER) + ) + ) + ->andWhere( + $expr->eq( + $parentNodeIdColumnName, + $query->createPositionalParameter($parentLocationId, ParameterType::INTEGER) + ) + ); + + return $query; + } + + private function buildNodeAssignmentSelectContentWithParentQuery( + int $contentId, + int $parentLocationId, + array $fields + ): QueryBuilder { + return $this->buildGenericNodeSelectContentWithParentQuery( + $contentId, + $parentLocationId, + 'eznode_assignment', + 'parent_node', + $fields + ); + } + + private function buildContentTreeSelectContentWithParentQuery( + int $contentId, + int $parentLocationId, + array $fields + ): QueryBuilder { + return $this->buildGenericNodeSelectContentWithParentQuery( + $contentId, + $parentLocationId, + Gateway::CONTENT_TREE_TABLE, + 'parent_node_id', + $fields + ); + } + /** - * @depends testCreateLocation + * @depends testCreateLocation * @dataProvider getNodeAssignmentValues + * + * @param string $field + * @param array $expectedResult */ - public function testCreateLocationNodeAssignmentCreation($field, $value) + public function testCreateLocationNodeAssignmentCreation(string $field, array $expectedResult) { $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); - $handler = $this->getLocationGateway(); - $handler->createNodeAssignment( + $gateway = $this->getLocationGateway(); + $gateway->createNodeAssignment( new CreateStruct( [ 'contentId' => 68, @@ -750,22 +837,13 @@ public function testCreateLocationNodeAssignmentCreation($field, $value) 'hidden' => 1, ] ), - '77', + 77, DoctrineDatabase::NODE_ASSIGNMENT_OP_CODE_CREATE ); - $query = $this->handler->createSelectQuery(); $this->assertQueryResult( - [[$value]], - $query - ->select($field) - ->from('eznode_assignment') - ->where( - $query->expr->lAnd( - $query->expr->eq('contentobject_id', 68), - $query->expr->eq('parent_node', 77) - ) - ) + [$expectedResult], + $this->buildNodeAssignmentSelectContentWithParentQuery(68, 77, [$field]) ); } @@ -775,8 +853,8 @@ public function testCreateLocationNodeAssignmentCreation($field, $value) public function testCreateLocationNodeAssignmentCreationMainLocation() { $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); - $handler = $this->getLocationGateway(); - $handler->createNodeAssignment( + $gateway = $this->getLocationGateway(); + $gateway->createNodeAssignment( new CreateStruct( [ 'contentId' => 68, @@ -792,18 +870,9 @@ public function testCreateLocationNodeAssignmentCreationMainLocation() DoctrineDatabase::NODE_ASSIGNMENT_OP_CODE_CREATE ); - $query = $this->handler->createSelectQuery(); $this->assertQueryResult( [[1]], - $query - ->select('is_main') - ->from('eznode_assignment') - ->where( - $query->expr->lAnd( - $query->expr->eq('contentobject_id', 68), - $query->expr->eq('parent_node', 77) - ) - ) + $this->buildNodeAssignmentSelectContentWithParentQuery(68, 77, ['is_main']) ); } @@ -832,7 +901,7 @@ public function testUpdateLocationsContentVersionNo() $gateway->updateLocationsContentVersionNo(4096, 2); - $query = $this->handler->createSelectQuery(); + $query = $this->getDatabaseConnection()->createQueryBuilder(); $this->assertQueryResult( [ [2], @@ -842,7 +911,7 @@ public function testUpdateLocationsContentVersionNo() )->from( 'ezcontentobject_tree' )->where( - $query->expr->eq( + $query->expr()->eq( 'contentobject_id', 4096 ) @@ -856,20 +925,18 @@ public function testUpdateLocationsContentVersionNo() public function testDeleteNodeAssignment() { $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); - $handler = $this->getLocationGateway(); + $gateway = $this->getLocationGateway(); - $handler->deleteNodeAssignment(11); + $gateway->deleteNodeAssignment(11); - $query = $this->handler->createSelectQuery(); + $query = $this->getDatabaseConnection()->createQueryBuilder(); $this->assertQueryResult( [[0]], $query ->select('count(*)') ->from('eznode_assignment') ->where( - $query->expr->lAnd( - $query->expr->eq('contentobject_id', 11) - ) + $query->expr()->eq('contentobject_id', 11) ) ); } @@ -880,33 +947,28 @@ public function testDeleteNodeAssignment() public function testDeleteNodeAssignmentWithSecondArgument() { $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); - $handler = $this->getLocationGateway(); + $gateway = $this->getLocationGateway(); - $query = $this->handler->createSelectQuery(); + $query = $this->getDatabaseConnection()->createQueryBuilder(); $query ->select('count(*)') ->from('eznode_assignment') ->where( - $query->expr->lAnd( - $query->expr->eq('contentobject_id', 11) - ) + $query->expr()->eq('contentobject_id', 11) ); - $statement = $query->prepare(); - $statement->execute(); + $statement = $query->execute(); $nodeAssignmentsCount = (int)$statement->fetchColumn(); - $handler->deleteNodeAssignment(11, 1); + $gateway->deleteNodeAssignment(11, 1); - $query = $this->handler->createSelectQuery(); + $query = $this->getDatabaseConnection()->createQueryBuilder(); $this->assertQueryResult( [[$nodeAssignmentsCount - 1]], $query ->select('count(*)') ->from('eznode_assignment') ->where( - $query->expr->lAnd( - $query->expr->eq('contentobject_id', 11) - ) + $query->expr()->eq('contentobject_id', 11) ) ); } @@ -934,15 +996,15 @@ public static function getConvertNodeAssignmentsLocationValues() } /** - * @depends testCreateLocationNodeAssignmentCreation + * @depends testCreateLocationNodeAssignmentCreation * @dataProvider getConvertNodeAssignmentsLocationValues */ public function testConvertNodeAssignments($field, $value) { $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); - $handler = $this->getLocationGateway(); - $handler->createNodeAssignment( + $gateway = $this->getLocationGateway(); + $gateway->createNodeAssignment( new CreateStruct( [ 'contentId' => 68, @@ -962,23 +1024,29 @@ public function testConvertNodeAssignments($field, $value) DoctrineDatabase::NODE_ASSIGNMENT_OP_CODE_CREATE ); - $handler->createLocationsFromNodeAssignments(68, 1); + $gateway->createLocationsFromNodeAssignments(68, 1); - $query = $this->handler->createSelectQuery(); + $query = $this->getDatabaseConnection()->createQueryBuilder(); + $expr = $query->expr(); $query ->select($field) - ->from('ezcontentobject_tree') + ->from(Gateway::CONTENT_TREE_TABLE) ->where( - $query->expr->lAnd( - $query->expr->eq('contentobject_id', 68), - $query->expr->eq('parent_node_id', 77) + $expr->eq( + 'contentobject_id', + $query->createPositionalParameter(68, ParameterType::INTEGER) + ) + ) + ->andWhere( + $expr->eq( + 'parent_node_id', + $query->createPositionalParameter(77, ParameterType::INTEGER) ) ); if ($field === 'modified_subnode') { - $statement = $query->prepare(); - $statement->execute(); - $result = $statement->fetch(\PDO::FETCH_ASSOC); + $statement = $query->execute(); + $result = $statement->fetch(FetchMode::ASSOCIATIVE); $this->assertGreaterThanOrEqual($value, $result); } else { $this->assertQueryResult( @@ -995,8 +1063,8 @@ public function testConvertNodeAssignmentsMainLocation() { $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); - $handler = $this->getLocationGateway(); - $handler->createNodeAssignment( + $gateway = $this->getLocationGateway(); + $gateway->createNodeAssignment( new CreateStruct( [ 'contentId' => 68, @@ -1012,24 +1080,15 @@ public function testConvertNodeAssignmentsMainLocation() 'invisible' => false, ] ), - '77', + 77, DoctrineDatabase::NODE_ASSIGNMENT_OP_CODE_CREATE ); - $handler->createLocationsFromNodeAssignments(68, 1); + $gateway->createLocationsFromNodeAssignments(68, 1); - $query = $this->handler->createSelectQuery(); $this->assertQueryResult( [[228]], - $query - ->select('main_node_id') - ->from('ezcontentobject_tree') - ->where( - $query->expr->lAnd( - $query->expr->eq('contentobject_id', 68), - $query->expr->eq('parent_node_id', 77) - ) - ) + $this->buildContentTreeSelectContentWithParentQuery(68, 77, ['main_node_id']) ); } @@ -1040,8 +1099,8 @@ public function testConvertNodeAssignmentsParentHidden() { $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); - $handler = $this->getLocationGateway(); - $handler->createNodeAssignment( + $gateway = $this->getLocationGateway(); + $gateway->createNodeAssignment( new CreateStruct( [ 'contentId' => 68, @@ -1057,24 +1116,19 @@ public function testConvertNodeAssignmentsParentHidden() 'invisible' => false, ] ), - '224', + 224, DoctrineDatabase::NODE_ASSIGNMENT_OP_CODE_CREATE ); - $handler->createLocationsFromNodeAssignments(68, 1); + $gateway->createLocationsFromNodeAssignments(68, 1); - $query = $this->handler->createSelectQuery(); $this->assertQueryResult( [[0, 1]], - $query - ->select('is_hidden, is_invisible') - ->from('ezcontentobject_tree') - ->where( - $query->expr->lAnd( - $query->expr->eq('contentobject_id', 68), - $query->expr->eq('parent_node_id', 224) - ) - ) + $this->buildContentTreeSelectContentWithParentQuery( + 68, + 224, + ['is_hidden, is_invisible'] + ) ); } @@ -1085,8 +1139,8 @@ public function testConvertNodeAssignmentsParentInvisible() { $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); - $handler = $this->getLocationGateway(); - $handler->createNodeAssignment( + $gateway = $this->getLocationGateway(); + $gateway->createNodeAssignment( new CreateStruct( [ 'contentId' => 68, @@ -1102,24 +1156,19 @@ public function testConvertNodeAssignmentsParentInvisible() 'invisible' => false, ] ), - '225', + 225, DoctrineDatabase::NODE_ASSIGNMENT_OP_CODE_CREATE ); - $handler->createLocationsFromNodeAssignments(68, 1); + $gateway->createLocationsFromNodeAssignments(68, 1); - $query = $this->handler->createSelectQuery(); $this->assertQueryResult( [[0, 1]], - $query - ->select('is_hidden, is_invisible') - ->from('ezcontentobject_tree') - ->where( - $query->expr->lAnd( - $query->expr->eq('contentobject_id', 68), - $query->expr->eq('parent_node_id', 225) - ) - ) + $this->buildContentTreeSelectContentWithParentQuery( + 68, + 225, + ['is_hidden, is_invisible'] + ) ); } @@ -1130,8 +1179,8 @@ public function testConvertNodeAssignmentsUpdateAssignment() { $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); - $handler = $this->getLocationGateway(); - $handler->createNodeAssignment( + $gateway = $this->getLocationGateway(); + $gateway->createNodeAssignment( new CreateStruct( [ 'contentId' => 68, @@ -1147,20 +1196,11 @@ public function testConvertNodeAssignmentsUpdateAssignment() DoctrineDatabase::NODE_ASSIGNMENT_OP_CODE_CREATE ); - $handler->createLocationsFromNodeAssignments(68, 1); + $gateway->createLocationsFromNodeAssignments(68, 1); - $query = $this->handler->createSelectQuery(); $this->assertQueryResult( [[DoctrineDatabase::NODE_ASSIGNMENT_OP_CODE_CREATE_NOP]], - $query - ->select('op_code') - ->from('eznode_assignment') - ->where( - $query->expr->lAnd( - $query->expr->eq('contentobject_id', 68), - $query->expr->eq('parent_node', 77) - ) - ) + $this->buildNodeAssignmentSelectContentWithParentQuery(68, 77, ['op_code']) ); } @@ -1172,16 +1212,16 @@ public function testConvertNodeAssignmentsUpdateAssignment() public function testSetSectionForSubtree() { $this->insertDatabaseFixture(__DIR__ . '/../../_fixtures/contentobjects.php'); - $handler = $this->getLocationGateway(); - $handler->setSectionForSubtree('/1/2/69/70/', 23); + $gateway = $this->getLocationGateway(); + $gateway->setSectionForSubtree('/1/2/69/70/', 23); - $query = $this->handler->createSelectQuery(); + $query = $this->getDatabaseConnection()->createQueryBuilder(); $this->assertQueryResult( [[68], [69]], $query ->select('id') ->from('ezcontentobject') - ->where($query->expr->eq('section_id', 23)) + ->where($query->expr()->eq('section_id', 23)) ); } @@ -1202,13 +1242,28 @@ public function testChangeMainLocation() ->insert('ezcontentobject_tree') ->values( [ - 'contentobject_id' => $query->createPositionalParameter(10, ParameterType::INTEGER), - 'contentobject_version' => $query->createPositionalParameter(2, ParameterType::INTEGER), + 'contentobject_id' => $query->createPositionalParameter( + 10, + ParameterType::INTEGER + ), + 'contentobject_version' => $query->createPositionalParameter( + 2, + ParameterType::INTEGER + ), 'main_node_id' => $query->createPositionalParameter(15, ParameterType::INTEGER), 'node_id' => $query->createPositionalParameter(228, ParameterType::INTEGER), - 'parent_node_id' => $query->createPositionalParameter(227, ParameterType::INTEGER), - 'path_string' => $query->createPositionalParameter('/1/5/13/228/', ParameterType::STRING), - 'remote_id' => $query->createPositionalParameter('asdfg123437', ParameterType::STRING), + 'parent_node_id' => $query->createPositionalParameter( + 227, + ParameterType::INTEGER + ), + 'path_string' => $query->createPositionalParameter( + '/1/5/13/228/', + ParameterType::STRING + ), + 'remote_id' => $query->createPositionalParameter( + 'asdfg123437', + ParameterType::STRING + ), ] ); $query->execute(); @@ -1218,12 +1273,21 @@ public function testChangeMainLocation() ->insert('eznode_assignment') ->values( [ - 'contentobject_id' => $query->createPositionalParameter(10, ParameterType::INTEGER), - 'contentobject_version' => $query->createPositionalParameter(2, ParameterType::INTEGER), + 'contentobject_id' => $query->createPositionalParameter( + 10, + ParameterType::INTEGER + ), + 'contentobject_version' => $query->createPositionalParameter( + 2, + ParameterType::INTEGER + ), 'id' => $query->createPositionalParameter(0, ParameterType::INTEGER), 'is_main' => $query->createPositionalParameter(0, ParameterType::INTEGER), 'parent_node' => $query->createPositionalParameter(227, ParameterType::INTEGER), - 'parent_remote_id' => $query->createPositionalParameter('5238a276bf8231fbcf8a986cdc82a6a5', ParameterType::STRING), + 'parent_remote_id' => $query->createPositionalParameter( + '5238a276bf8231fbcf8a986cdc82a6a5', + ParameterType::STRING + ), ] ); $query->execute(); @@ -1258,12 +1322,21 @@ public function testChangeMainLocation() ->select('is_main') ->from('eznode_assignment') ->where( - $query->expr()->andX( - $query->expr()->eq('contentobject_id', $query->createPositionalParameter(10, ParameterType::INTEGER)), - $query->expr()->eq('contentobject_version', $query->createPositionalParameter(2, ParameterType::INTEGER)), - $query->expr()->eq('parent_node', $query->createPositionalParameter(227, ParameterType::INTEGER)) + $query->expr()->andX( + $query->expr()->eq( + 'contentobject_id', + $query->createPositionalParameter(10, ParameterType::INTEGER) + ), + $query->expr()->eq( + 'contentobject_version', + $query->createPositionalParameter(2, ParameterType::INTEGER) + ), + $query->expr()->eq( + 'parent_node', + $query->createPositionalParameter(227, ParameterType::INTEGER) + ) + ) ) - ) ); $query = $connection->createQueryBuilder(); @@ -1274,9 +1347,18 @@ public function testChangeMainLocation() ->from('eznode_assignment') ->where( $query->expr()->andX( - $query->expr()->eq('contentobject_id', $query->createPositionalParameter(10, ParameterType::INTEGER)), - $query->expr()->eq('contentobject_version', $query->createPositionalParameter(2, ParameterType::INTEGER)), - $query->expr()->eq('parent_node', $query->createPositionalParameter(44, ParameterType::INTEGER)) + $query->expr()->eq( + 'contentobject_id', + $query->createPositionalParameter(10, ParameterType::INTEGER) + ), + $query->expr()->eq( + 'contentobject_version', + $query->createPositionalParameter(2, ParameterType::INTEGER) + ), + $query->expr()->eq( + 'parent_node', + $query->createPositionalParameter(44, ParameterType::INTEGER) + ) ) ) ); @@ -1318,13 +1400,28 @@ public function testGetFallbackMainNodeData(): void ->insert('ezcontentobject_tree') ->values( [ - 'contentobject_id' => $query->createPositionalParameter(12, ParameterType::INTEGER), - 'contentobject_version' => $query->createPositionalParameter(1, ParameterType::INTEGER), + 'contentobject_id' => $query->createPositionalParameter( + 12, + ParameterType::INTEGER + ), + 'contentobject_version' => $query->createPositionalParameter( + 1, + ParameterType::INTEGER + ), 'main_node_id' => $query->createPositionalParameter(13, ParameterType::INTEGER), 'node_id' => $query->createPositionalParameter(228, ParameterType::INTEGER), - 'parent_node_id' => $query->createPositionalParameter(227, ParameterType::INTEGER), - 'path_string' => $query->createPositionalParameter('/1/5/13/228/', ParameterType::STRING), - 'remote_id' => $query->createPositionalParameter('asdfg123437', ParameterType::STRING), + 'parent_node_id' => $query->createPositionalParameter( + 227, + ParameterType::INTEGER + ), + 'path_string' => $query->createPositionalParameter( + '/1/5/13/228/', + ParameterType::STRING + ), + 'remote_id' => $query->createPositionalParameter( + 'asdfg123437', + ParameterType::STRING + ), ] ); $query->execute(); @@ -1368,17 +1465,21 @@ public function providerForTestUpdatePathIdentificationString() /** * Test for the updatePathIdentificationString() method. * - * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase::updatePathIdentificationString + * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase::updatePathIdentificationString * @dataProvider providerForTestUpdatePathIdentificationString */ - public function testUpdatePathIdentificationString($locationId, $parentLocationId, $text, $expected) - { + public function testUpdatePathIdentificationString( + $locationId, + $parentLocationId, + $text, + $expected + ) { $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); $gateway = $this->getLocationGateway(); $gateway->updatePathIdentificationString($locationId, $parentLocationId, $text); - $query = $this->handler->createSelectQuery(); + $query = $this->getDatabaseConnection()->createQueryBuilder(); $this->assertQueryResult( [[$expected]], $query->select( @@ -1386,7 +1487,7 @@ public function testUpdatePathIdentificationString($locationId, $parentLocationI )->from( 'ezcontentobject_tree' )->where( - $query->expr->eq('node_id', $locationId) + $query->expr()->eq('node_id', $locationId) ) ); } diff --git a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/Location/Gateway/DoctrineDatabaseTrashTest.php b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/Location/Gateway/DoctrineDatabaseTrashTest.php index 8ff3212ee9..3569217fb1 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/Location/Gateway/DoctrineDatabaseTrashTest.php +++ b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/Location/Gateway/DoctrineDatabaseTrashTest.php @@ -1,13 +1,12 @@ getLocationGateway(); $handler->trashLocation(71); - $query = $this->handler->createSelectQuery(); + $query = $this->getDatabaseConnection()->createQueryBuilder(); $this->assertQueryResult( [ [1, 0], @@ -48,7 +47,7 @@ public function testTrashLocation() $query ->select('node_id', 'priority') ->from('ezcontentobject_tree') - ->where($query->expr->in('node_id', [1, 2, 69, 70, 71])) + ->where($query->expr()->in('node_id', [1, 2, 69, 70, 71])) ); } @@ -61,7 +60,7 @@ public function testTrashLocationUpdateTrashTable() $handler = $this->getLocationGateway(); $handler->trashLocation(71); - $query = $this->handler->createSelectQuery(); + $query = $this->getDatabaseConnection()->createQueryBuilder(); $this->assertQueryResult( [ [71, '/1/2/69/70/71/'], @@ -104,13 +103,13 @@ public function testUntrashLocationDefault($property, $value) $handler->untrashLocation(71); - $query = $this->handler->createSelectQuery(); + $query = $this->getDatabaseConnection()->createQueryBuilder(); $this->assertQueryResult( [[$value]], $query ->select($property) ->from('ezcontentobject_tree') - ->where($query->expr->in('contentobject_id', [69])) + ->where($query->expr()->in('contentobject_id', [69])) ); } @@ -125,13 +124,13 @@ public function testUntrashLocationNewParent() $handler->untrashLocation(71, 1); - $query = $this->handler->createSelectQuery(); + $query = $this->getDatabaseConnection()->createQueryBuilder(); $this->assertQueryResult( [['228', '1', '/1/228/']], $query ->select('node_id', 'parent_node_id', 'path_string') ->from('ezcontentobject_tree') - ->where($query->expr->in('contentobject_id', [69])) + ->where($query->expr()->in('contentobject_id', [69])) ); } @@ -411,7 +410,7 @@ public function testCleanupTrash() $this->trashSubtree(); $handler->cleanupTrash(); - $query = $this->handler->createSelectQuery(); + $query = $this->getDatabaseConnection()->createQueryBuilder(); $this->assertQueryResult( [], $query @@ -430,13 +429,13 @@ public function testRemoveElementFromTrash() $this->trashSubtree(); $handler->removeElementFromTrash(71); - $query = $this->handler->createSelectQuery(); + $query = $this->getDatabaseConnection()->createQueryBuilder(); $this->assertQueryResult( [], $query ->select('*') ->from('ezcontentobject_trash') - ->where($query->expr->eq('node_id', 71)) + ->where($query->expr()->eq('node_id', 71)) ); } @@ -452,15 +451,34 @@ public function testCountLocationsByContentId() self::assertSame(1, $handler->countLocationsByContentId(67)); // Insert a new node and count again - $query = $this->handler->createInsertQuery(); + $query = $this->getDatabaseConnection()->createQueryBuilder(); $query - ->insertInto('ezcontentobject_tree') - ->set('contentobject_id', $query->bindValue(67, null, \PDO::PARAM_INT)) - ->set('contentobject_version', $query->bindValue(1, null, \PDO::PARAM_INT)) - ->set('path_string', $query->bindValue('/1/2/96')) - ->set('parent_node_id', $query->bindValue(96, null, \PDO::PARAM_INT)) - ->set('remote_id', $query->bindValue('some_remote_id')); - $query->prepare()->execute(); + ->insert('ezcontentobject_tree') + ->values( + [ + 'contentobject_id' => $query->createPositionalParameter( + 67, + ParameterType::INTEGER + ), + 'contentobject_version' => $query->createPositionalParameter( + 1, + ParameterType::INTEGER + ), + 'path_string' => $query->createPositionalParameter( + '/1/2/96', + ParameterType::INTEGER + ), + 'parent_node_id' => $query->createPositionalParameter( + 96, + ParameterType::INTEGER + ), + 'remote_id' => $query->createPositionalParameter( + 'some_remote_id', + ParameterType::STRING + ), + ] + ); + $query->execute(); self::assertSame(2, $handler->countLocationsByContentId(67)); } } diff --git a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/ObjectState/Gateway/DoctrineDatabaseTest.php b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/ObjectState/Gateway/DoctrineDatabaseTest.php index 75a9d46785..20d82b72fd 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/ObjectState/Gateway/DoctrineDatabaseTest.php +++ b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/ObjectState/Gateway/DoctrineDatabaseTest.php @@ -1,8 +1,6 @@ updateObjectStateLinks(1, 2); - $query = $this->getDatabaseHandler()->createSelectQuery(); - $query - ->select($query->expr->count('*')) - ->from('ezcobj_state_link') - ->where('contentobject_state_id = 1'); - - $statement = $query->prepare(); - $statement->execute(); - - $this->assertEquals( - 0, - $statement->fetchColumn() - ); - - $query = $this->getDatabaseHandler()->createSelectQuery(); - $query - ->select($query->expr->count('*')) - ->from('ezcobj_state_link') - ->where('contentobject_state_id = 2'); - - $statement = $query->prepare(); - $statement->execute(); - - $this->assertEquals( - // The number of objects in the fixtures - 185, - $statement->fetchColumn() - ); + self::assertSame(0, $gateway->getContentCount(1)); + self::assertSame(185, $gateway->getContentCount(2)); } /** @@ -385,19 +357,7 @@ public function testDeleteObjectStateLinks() $gateway->deleteObjectStateLinks(1); - $query = $this->getDatabaseHandler()->createSelectQuery(); - $query - ->select($query->expr->count('*')) - ->from('ezcobj_state_link') - ->where('contentobject_state_id = 1'); - - $statement = $query->prepare(); - $statement->execute(); - - $this->assertEquals( - 0, - $statement->fetchColumn() - ); + self::assertSame(0, $gateway->getContentCount(1)); } /** @@ -488,7 +448,7 @@ public function testSetContentState() 'contentobject_state_id' => 2, ], ], - $this->getDatabaseHandler()->createSelectQuery() + $this->getDatabaseConnection()->createQueryBuilder() ->select('contentobject_id', 'contentobject_state_id') ->from('ezcobj_state_link') ->where('contentobject_id = 42') diff --git a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/Section/Gateway/DoctrineDatabaseTest.php b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/Section/Gateway/DoctrineDatabaseTest.php index 07915b74cc..3dfb0d0b39 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/Section/Gateway/DoctrineDatabaseTest.php +++ b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/Section/Gateway/DoctrineDatabaseTest.php @@ -42,7 +42,7 @@ public function testInsertSection() $gateway = $this->getDatabaseGateway(); $gateway->insertSection('New Section', 'new_section'); - $query = $this->getDatabaseHandler()->createSelectQuery(); + $query = $this->getDatabaseConnection()->createQueryBuilder(); $this->assertQueryResult( [ @@ -56,7 +56,12 @@ public function testInsertSection() $query ->select('id', 'identifier', 'name', 'locale') ->from('ezsection') - ->where($query->expr->eq('identifier', $query->bindValue('new_section'))) + ->where( + $query->expr()->eq( + 'identifier', + $query->createPositionalParameter('new_section') + ) + ) ); } @@ -78,7 +83,7 @@ public function testUpdateSection() 'locale' => '', ], ], - $this->getDatabaseHandler()->createSelectQuery() + $this->getDatabaseConnection()->createQueryBuilder() ->select('id', 'identifier', 'name', 'locale') ->from('ezsection') ->where('id=2') @@ -224,7 +229,7 @@ public function testDeleteSection() { $gateway = $this->getDatabaseGateway(); - $result = $gateway->deleteSection(2); + $gateway->deleteSection(2); $this->assertQueryResult( [ @@ -232,7 +237,7 @@ public function testDeleteSection() 'count' => '5', ], ], - $this->getDatabaseHandler()->createSelectQuery() + $this->getDatabaseConnection()->createQueryBuilder() ->select('COUNT( * ) AS count') ->from('ezsection') ); @@ -243,7 +248,7 @@ public function testDeleteSection() 'count' => '0', ], ], - $this->getDatabaseHandler()->createSelectQuery() + $this->getDatabaseConnection()->createQueryBuilder() ->select('COUNT( * ) AS count') ->from('ezsection') ->where('id=2') diff --git a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/Type/Gateway/DoctrineDatabaseTest.php b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/Type/Gateway/DoctrineDatabaseTest.php index 74026f2947..66e394ae85 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/Type/Gateway/DoctrineDatabaseTest.php +++ b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/Type/Gateway/DoctrineDatabaseTest.php @@ -57,8 +57,7 @@ public function testInsertGroup() 'name' => 'Media', ], ], - $this->getDatabaseHandler() - ->createSelectQuery() + $this->getDatabaseConnection()->createQueryBuilder() ->select( 'id', 'created', @@ -116,13 +115,12 @@ public function testUpdateGroup() [ ['3'], ], - $this->getDatabaseHandler() - ->createSelectQuery() + $this->getDatabaseConnection()->createQueryBuilder() ->select('COUNT(*)') ->from('ezcontentclassgroup') ); - $q = $this->getDatabaseHandler()->createSelectQuery(); + $q = $this->getDatabaseConnection()->createQueryBuilder(); $q ->select( 'id', @@ -250,8 +248,7 @@ public function testDeleteGroup() ['1'], ['3'], ], - $this->getDatabaseHandler() - ->createSelectQuery() + $this->getDatabaseConnection()->createQueryBuilder() ->select('id') ->from('ezcontentclassgroup') ); @@ -485,8 +482,7 @@ public function testInsertType($column, $expectation) $this->assertQueryResult( [[$expectation]], - $this->getDatabaseHandler() - ->createSelectQuery() + $this->getDatabaseConnection()->createQueryBuilder() ->select($column) ->from('ezcontentclass'), 'Inserted Type data incorrect in column ' . $column @@ -527,8 +523,7 @@ function ($value) { }, $expectation ), - $this->getDatabaseHandler() - ->createSelectQuery() + $this->getDatabaseConnection()->createQueryBuilder() ->select($column) ->from('ezcontentclass_name'), 'Inserted Type data incorrect in column ' . $column @@ -618,8 +613,7 @@ public function testInsertFieldDefinition() 'serialized_data_text' => 'a:2:{i:0;s:3:"foo";i:1;s:3:"bar";}', ], ], - $this->getDatabaseHandler() - ->createSelectQuery() + $this->getDatabaseConnection()->createQueryBuilder() ->select( 'contentclass_id', 'serialized_name_list', @@ -732,8 +726,7 @@ public function testDeleteFieldDefinition() $this->assertQueryResult( [[5]], - $this->getDatabaseHandler() - ->createSelectQuery() + $this->getDatabaseConnection()->createQueryBuilder() ->select('COUNT(*)') ->from('ezcontentclass_attribute') ); @@ -784,8 +777,7 @@ public function testUpdateFieldDefinition() 'serialized_data_text' => 'a:2:{i:0;s:3:"foo";i:1;s:3:"bar";}', ], ], - $this->getDatabaseHandler() - ->createSelectQuery() + $this->getDatabaseConnection()->createQueryBuilder() ->select( 'category', 'contentclass_id', @@ -839,8 +831,7 @@ public function testInsertGroupAssignment() 'group_name' => 'Media', ], ], - $this->getDatabaseHandler() - ->createSelectQuery() + $this->getDatabaseConnection()->createQueryBuilder() ->select( 'contentclass_id', 'contentclass_version', @@ -865,8 +856,7 @@ public function testDeleteGroupAssignment() $this->assertQueryResult( [['1']], - $this->getDatabaseHandler() - ->createSelectQuery() + $this->getDatabaseConnection()->createQueryBuilder() ->select( 'COUNT(*)' )->from('ezcontentclass_classgroup') @@ -896,8 +886,7 @@ public function testUpdateType($fieldName, $expectedValue) $fieldName => $expectedValue, ], ], - $this->getDatabaseHandler() - ->createSelectQuery() + $this->getDatabaseConnection()->createQueryBuilder() ->select( $fieldName )->from('ezcontentclass') @@ -940,8 +929,7 @@ public function testUpdateTypeName() 'name' => 'New Folder for you', ], ], - $this->getDatabaseHandler() - ->createSelectQuery() + $this->getDatabaseConnection()->createQueryBuilder() ->select('*') ->from('ezcontentclass_name') ->where('contentclass_id = 1 AND contentclass_version = 0') @@ -1058,13 +1046,12 @@ public function testDeleteFieldDefinitionsForTypeExisting() $gateway->deleteFieldDefinitionsForType(1, 0); - $countAffectedAttr = $this->getDatabaseHandler() - ->createSelectQuery(); + $countAffectedAttr = $this->getDatabaseConnection()->createQueryBuilder(); $countAffectedAttr ->select('COUNT(*)') ->from('ezcontentclass_attribute') ->where( - $countAffectedAttr->expr->eq( + $countAffectedAttr->expr()->eq( 'contentclass_id', 1 ) @@ -1075,8 +1062,7 @@ public function testDeleteFieldDefinitionsForTypeExisting() $countAffectedAttr ); - $countNotAffectedAttr = $this->getDatabaseHandler() - ->createSelectQuery(); + $countNotAffectedAttr = $this->getDatabaseConnection()->createQueryBuilder(); $countNotAffectedAttr->select('COUNT(*)') ->from('ezcontentclass_attribute'); @@ -1099,8 +1085,7 @@ public function testDeleteFieldDefinitionsForTypeNotExisting() $gateway->deleteFieldDefinitionsForType(23, 1); - $countNotAffectedAttr = $this->getDatabaseHandler() - ->createSelectQuery(); + $countNotAffectedAttr = $this->getDatabaseConnection()->createQueryBuilder(); $countNotAffectedAttr->select('COUNT(*)') ->from('ezcontentclass_attribute'); @@ -1123,8 +1108,7 @@ public function testDeleteGroupAssignmentsForTypeExisting() $gateway->deleteGroupAssignmentsForType(1, 0); - $countAffectedAttr = $this->getDatabaseHandler() - ->createSelectQuery(); + $countAffectedAttr = $this->getDatabaseConnection()->createQueryBuilder(); $countAffectedAttr->select('COUNT(*)') ->from('ezcontentclass_classgroup'); @@ -1147,8 +1131,7 @@ public function testDeleteGroupAssignmentsForTypeNotExisting() $gateway->deleteType(23, 1); - $countAffectedAttr = $this->getDatabaseHandler() - ->createSelectQuery(); + $countAffectedAttr = $this->getDatabaseConnection()->createQueryBuilder(); $countAffectedAttr->select('COUNT(*)') ->from('ezcontentclass_classgroup'); @@ -1171,8 +1154,7 @@ public function testDeleteTypeExisting() $gateway->deleteType(1, 0); - $countAffectedAttr = $this->getDatabaseHandler() - ->createSelectQuery(); + $countAffectedAttr = $this->getDatabaseConnection()->createQueryBuilder(); $countAffectedAttr->select('COUNT(*)') ->from('ezcontentclass'); @@ -1195,8 +1177,7 @@ public function testDeleteTypeNotExisting() $gateway->deleteType(23, 1); - $countAffectedAttr = $this->getDatabaseHandler() - ->createSelectQuery(); + $countAffectedAttr = $this->getDatabaseConnection()->createQueryBuilder(); $countAffectedAttr->select('COUNT(*)') ->from('ezcontentclass'); @@ -1220,7 +1201,7 @@ public function testPublishTypeAndFields() $this->assertQueryResult( [[1]], - $this->getDatabaseHandler()->createSelectQuery() + $this->getDatabaseConnection()->createQueryBuilder() ->select('COUNT( * )') ->from('ezcontentclass') ->where('id = 1 AND version = 0') @@ -1228,7 +1209,7 @@ public function testPublishTypeAndFields() $this->assertQueryResult( [[2]], - $this->getDatabaseHandler()->createSelectQuery() + $this->getDatabaseConnection()->createQueryBuilder() ->select('COUNT( * )') ->from('ezcontentclass_classgroup') ->where('contentclass_id = 1 AND contentclass_version = 0') @@ -1236,7 +1217,7 @@ public function testPublishTypeAndFields() $this->assertQueryResult( [[3]], - $this->getDatabaseHandler()->createSelectQuery() + $this->getDatabaseConnection()->createQueryBuilder() ->select('COUNT( * )') ->from('ezcontentclass_attribute') ->where('contentclass_id = 1 AND version = 0') @@ -1244,7 +1225,7 @@ public function testPublishTypeAndFields() $this->assertQueryResult( [[1]], - $this->getDatabaseHandler()->createSelectQuery() + $this->getDatabaseConnection()->createQueryBuilder() ->select('COUNT( * )') ->from('ezcontentclass_name') ->where('contentclass_id = 1 AND contentclass_version = 0') diff --git a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/UrlAlias/UrlAliasHandlerTest.php b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/UrlAlias/UrlAliasHandlerTest.php index 07fc45cbb6..3d6926f08e 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Tests/Content/UrlAlias/UrlAliasHandlerTest.php +++ b/eZ/Publish/Core/Persistence/Legacy/Tests/Content/UrlAlias/UrlAliasHandlerTest.php @@ -6,6 +6,7 @@ */ namespace eZ\Publish\Core\Persistence\Legacy\Tests\Content; +use eZ\Publish\API\Repository\Exceptions\InvalidArgumentException; use eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Gateway as UrlAliasGateway; use eZ\Publish\Core\Persistence\Legacy\Tests\TestCase; use eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler; @@ -85,7 +86,7 @@ public function testLookupThrowsNotFoundException() */ public function testLookupThrowsInvalidArgumentException() { - $this->expectException(\eZ\Publish\API\Repository\Exceptions\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $handler = $this->getHandler(); $handler->lookup(str_repeat('/1', 99)); @@ -5291,41 +5292,20 @@ public function testLocationSwappedMultipleLanguagesUpdatesLocationPathIdentific self::assertEquals('jedan', $locationData['path_identification_string']); } - /** - * @return int - */ - protected function countRows() + protected function countRows(): int { /** @var \eZ\Publish\Core\Persistence\Database\SelectQuery $query */ - $query = $this->getDatabaseHandler()->createSelectQuery(); - $query->select( - $query->expr->count('*') - )->from( - $this->getDatabaseHandler()->quoteTable('ezurlalias_ml') - ); + $connection = $this->getDatabaseConnection(); + $query = $connection->createQueryBuilder(); + $query + ->select($connection->getDatabasePlatform()->getCountExpression('*')) + ->from(UrlAliasGateway::TABLE); - $statement = $query->prepare(); - $statement->execute(); + $statement = $query->execute(); return (int)$statement->fetchColumn(); } - protected function dump() - { - /** @var \eZ\Publish\Core\Persistence\Database\SelectQuery $query */ - $query = $this->getDatabaseHandler()->createSelectQuery(); - $query->select( - '*' - )->from( - $this->getDatabaseHandler()->quoteTable('ezurlalias_ml') - ); - - $statement = $query->prepare(); - $statement->execute(); - - var_dump($statement->fetchAll(\PDO::FETCH_ASSOC)); - } - /** * @var \eZ\Publish\Core\Persistence\Doctrine\ConnectionHandler * @deprecated Start to use DBAL $connection instead. diff --git a/eZ/Publish/Core/Persistence/Legacy/Tests/Notification/Gateway/DoctrineDatabaseTest.php b/eZ/Publish/Core/Persistence/Legacy/Tests/Notification/Gateway/DoctrineDatabaseTest.php index e378bd2937..0bee5a7829 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Tests/Notification/Gateway/DoctrineDatabaseTest.php +++ b/eZ/Publish/Core/Persistence/Legacy/Tests/Notification/Gateway/DoctrineDatabaseTest.php @@ -8,11 +8,11 @@ namespace eZ\Publish\Core\Persistence\Legacy\Tests\Notification\Gateway; +use Doctrine\DBAL\FetchMode; use eZ\Publish\Core\Persistence\Legacy\Notification\Gateway\DoctrineDatabase; use eZ\Publish\Core\Persistence\Legacy\Tests\TestCase; use eZ\Publish\SPI\Persistence\Notification\CreateStruct; use eZ\Publish\SPI\Persistence\Notification\Notification; -use PDO; class DoctrineDatabaseTest extends TestCase { @@ -175,7 +175,7 @@ public function testDelete() protected function getGateway(): DoctrineDatabase { return new DoctrineDatabase( - $this->getDatabaseHandler()->getConnection() + $this->getDatabaseConnection() ); } @@ -183,7 +183,7 @@ private function loadNotification(int $id): array { $data = $this->connection ->executeQuery('SELECT * FROM eznotification WHERE id = :id', ['id' => $id]) - ->fetch(PDO::FETCH_ASSOC); + ->fetch(FetchMode::ASSOCIATIVE); return is_array($data) ? $data : []; } diff --git a/eZ/Publish/Core/Persistence/Legacy/Tests/User/Gateway/DoctrineDatabaseTest.php b/eZ/Publish/Core/Persistence/Legacy/Tests/User/Gateway/DoctrineDatabaseTest.php index 69e307ef58..17978680c8 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Tests/User/Gateway/DoctrineDatabaseTest.php +++ b/eZ/Publish/Core/Persistence/Legacy/Tests/User/Gateway/DoctrineDatabaseTest.php @@ -8,6 +8,7 @@ namespace eZ\Publish\Core\Persistence\Legacy\Tests\User\Gateway; +use Doctrine\DBAL\ParameterType; use eZ\Publish\Core\Persistence\Legacy\Tests\TestCase; use eZ\Publish\Core\Persistence\Legacy\User\Gateway\DoctrineDatabase; @@ -43,7 +44,7 @@ public function testRemoveRoleByAssignmentId(): void $gateway = $this->getDatabaseGateway(); $gateway->removeRoleAssignmentById(38); - $query = $this->getDatabaseHandler()->createSelectQuery(); + $query = $this->getDatabaseConnection()->createQueryBuilder(); $this->assertQueryResult( [ @@ -72,7 +73,12 @@ public function testRemoveRoleByAssignmentId(): void $query ->select('contentobject_id', 'id', 'limit_identifier', 'limit_value', 'role_id') ->from('ezuser_role') - ->where($query->expr->eq('role_id', $query->bindValue('5'))) + ->where( + $query->expr()->eq( + 'role_id', + $query->createPositionalParameter(5, ParameterType::INTEGER) + ) + ) ); } diff --git a/eZ/Publish/Core/Persistence/Legacy/Tests/User/Role/Gateway/DoctrineDatabaseTest.php b/eZ/Publish/Core/Persistence/Legacy/Tests/User/Role/Gateway/DoctrineDatabaseTest.php index 70a71a5188..f8d083f606 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Tests/User/Role/Gateway/DoctrineDatabaseTest.php +++ b/eZ/Publish/Core/Persistence/Legacy/Tests/User/Role/Gateway/DoctrineDatabaseTest.php @@ -8,6 +8,7 @@ namespace eZ\Publish\Core\Persistence\Legacy\Tests\User\Role\Gateway; +use Doctrine\DBAL\ParameterType; use eZ\Publish\Core\Persistence\Legacy\Tests\TestCase; use eZ\Publish\Core\Persistence\Legacy\User\Role\Gateway\DoctrineDatabase; use eZ\Publish\SPI\Persistence\User\Role; @@ -52,7 +53,7 @@ public function testCreateRole(): void 'status' => Role::STATUS_DRAFT, ]); $gateway->createRole($spiRole); - $query = $this->getDatabaseHandler()->createSelectQuery(); + $query = $this->getDatabaseConnection()->createQueryBuilder(); $this->assertQueryResult( [ @@ -65,7 +66,12 @@ public function testCreateRole(): void $query ->select('id', 'name', 'version') ->from('ezrole') - ->where($query->expr->eq('name', $query->bindValue('new_role'))) + ->where( + $query->expr()->eq( + 'name', + $query->createPositionalParameter('new_role', ParameterType::STRING) + ) + ) ); } diff --git a/eZ/Publish/Core/Persistence/Legacy/Tests/User/UserHandlerTest.php b/eZ/Publish/Core/Persistence/Legacy/Tests/User/UserHandlerTest.php index 5732f874f6..30cbf5ba9e 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Tests/User/UserHandlerTest.php +++ b/eZ/Publish/Core/Persistence/Legacy/Tests/User/UserHandlerTest.php @@ -291,7 +291,7 @@ public function testUpdateUserToken() $this->assertQueryResult( [['0800fc577294c34e0b28ad2839435945', 1, 1234567890, self::TEST_USER_ID]], - $this->handler->createSelectQuery()->select( + $this->getDatabaseConnection()->createQueryBuilder()->select( ['hash_key', 'id', 'time', 'user_id'] )->from('ezuser_accountkey'), 'Expected user data to be updated.' @@ -301,7 +301,7 @@ public function testUpdateUserToken() $this->assertQueryResult( [['0800fc577294c34e0b28ad2839435945', 1, 2234567890, self::TEST_USER_ID]], - $this->handler->createSelectQuery()->select( + $this->getDatabaseConnection()->createQueryBuilder()->select( ['hash_key', 'id', 'time', 'user_id'] )->from('ezuser_accountkey'), 'Expected user token data to be updated.' @@ -316,7 +316,7 @@ public function testExpireUserToken() $this->assertQueryResult( [['0800fc577294c34e0b28ad2839435945', 1, 1234567890, self::TEST_USER_ID]], - $this->handler->createSelectQuery()->select( + $this->getDatabaseConnection()->createQueryBuilder()->select( ['hash_key', 'id', 'time', 'user_id'] )->from('ezuser_accountkey'), 'Expected user data to be updated.' @@ -326,7 +326,7 @@ public function testExpireUserToken() $this->assertQueryResult( [['0800fc577294c34e0b28ad2839435945', 1, 0, self::TEST_USER_ID]], - $this->handler->createSelectQuery()->select( + $this->getDatabaseConnection()->createQueryBuilder()->select( ['hash_key', 'id', 'time', 'user_id'] )->from('ezuser_accountkey'), 'Expected user token to be expired.' @@ -372,7 +372,7 @@ public function testCreateNewRoleWithoutPolicies() $this->assertQueryResult( [[1, 'Test', -1]], - $this->handler->createSelectQuery()->select('id', 'name', 'version')->from('ezrole'), + $this->getDatabaseConnection()->createQueryBuilder()->select('id', 'name', 'version')->from('ezrole'), 'Expected a new role draft.' ); } @@ -395,7 +395,7 @@ public function testCreateRoleDraftWithoutPolicies() [$publishedRoleId, 'Test', APIRole::STATUS_DEFINED], [2, 'Test', $publishedRoleId], ], - $this->handler->createSelectQuery()->select('id', 'name', 'version')->from('ezrole'), + $this->getDatabaseConnection()->createQueryBuilder()->select('id', 'name', 'version')->from('ezrole'), 'Expected a role and a role draft.' ); } @@ -573,7 +573,7 @@ public function testUpdateRole() $this->assertQueryResult( [[1, 'Changed']], - $this->handler->createSelectQuery()->select('id', 'name')->from('ezrole'), + $this->getDatabaseConnection()->createQueryBuilder()->select('id', 'name')->from('ezrole'), 'Expected a changed role.' ); } @@ -588,19 +588,19 @@ public function testDeleteRole() $this->assertQueryResult( [], - $this->handler->createSelectQuery()->select('id')->from('ezrole')->where('id = 3'), + $this->getDatabaseConnection()->createQueryBuilder()->select('id')->from('ezrole')->where('id = 3'), 'Expected an empty set.' ); $this->assertQueryResult( [], - $this->handler->createSelectQuery()->select('role_id')->from('ezpolicy')->where('role_id = 3'), + $this->getDatabaseConnection()->createQueryBuilder()->select('role_id')->from('ezpolicy')->where('role_id = 3'), 'Expected an empty set.' ); $this->assertQueryResult( [], - $this->handler->createSelectQuery()->select('role_id')->from('ezuser_role')->where('role_id = 3'), + $this->getDatabaseConnection()->createQueryBuilder()->select('role_id')->from('ezuser_role')->where('role_id = 3'), 'Expected an empty set.' ); } @@ -616,19 +616,19 @@ public function testDeleteRoleDraft() $this->assertQueryResult( [['3', APIRole::STATUS_DEFINED]], - $this->handler->createSelectQuery()->select('id, version')->from('ezrole')->where('id = 3'), + $this->getDatabaseConnection()->createQueryBuilder()->select('id, version')->from('ezrole')->where('id = 3'), 'Expected a published role.' ); $this->assertQueryResult( [[implode("\n", array_fill(0, 28, '3, ' . APIRole::STATUS_DEFINED))]], - $this->handler->createSelectQuery()->select('role_id, original_id')->from('ezpolicy')->where('role_id = 3'), + $this->getDatabaseConnection()->createQueryBuilder()->select('role_id, original_id')->from('ezpolicy')->where('role_id = 3'), 'Expected 28 policies for the published role.' ); $this->assertQueryResult( [[3], [3]], - $this->handler->createSelectQuery()->select('role_id')->from('ezuser_role')->where('role_id = 3'), + $this->getDatabaseConnection()->createQueryBuilder()->select('role_id')->from('ezuser_role')->where('role_id = 3'), 'Expected that role assignments still exist.' ); } @@ -647,7 +647,7 @@ public function testAddPolicyToRoleLimitations() $this->assertQueryResult( [[1, 'foo', 'bar', 1]], - $this->handler->createSelectQuery()->select('id', 'module_name', 'function_name', 'role_id')->from('ezpolicy'), + $this->getDatabaseConnection()->createQueryBuilder()->select('id', 'module_name', 'function_name', 'role_id')->from('ezpolicy'), 'Expected a new policy.' ); } @@ -676,7 +676,7 @@ public function testAddPolicyLimitations() [1, 'Subtree', 1], [2, 'Foo', 1], ], - $this->handler->createSelectQuery()->select('id', 'identifier', 'policy_id')->from('ezpolicy_limitation'), + $this->getDatabaseConnection()->createQueryBuilder()->select('id', 'identifier', 'policy_id')->from('ezpolicy_limitation'), 'Expected a new policy.' ); } @@ -691,7 +691,7 @@ public function testAddPolicyLimitationValues() [2, '/1/2', 1], [3, 'Bar', 2], ], - $this->handler->createSelectQuery()->select('id', 'value', 'limitation_id')->from('ezpolicy_limitation_value'), + $this->getDatabaseConnection()->createQueryBuilder()->select('id', 'value', 'limitation_id')->from('ezpolicy_limitation_value'), 'Expected a new policy.' ); } @@ -731,7 +731,7 @@ public function testImplicitlyCreatePolicies() [1, 'foo', 'bar', 1], [2, 'foo', 'blubb', 1], ], - $this->handler->createSelectQuery()->select('id', 'module_name', 'function_name', 'role_id')->from('ezpolicy'), + $this->getDatabaseConnection()->createQueryBuilder()->select('id', 'module_name', 'function_name', 'role_id')->from('ezpolicy'), 'Expected a new policy.' ); } @@ -748,7 +748,7 @@ public function testDeletePolicy() [ [2, 'foo', 'blubb', 1], ], - $this->handler->createSelectQuery()->select('id', 'module_name', 'function_name', 'role_id')->from('ezpolicy')->where('original_id = 0'), + $this->getDatabaseConnection()->createQueryBuilder()->select('id', 'module_name', 'function_name', 'role_id')->from('ezpolicy')->where('original_id = 0'), 'Expected a new policy.' ); } @@ -762,7 +762,7 @@ public function testDeletePolicyLimitations() $this->assertQueryResult( [[3, 'Foo', 2]], - $this->handler->createSelectQuery()->select('*')->from('ezpolicy_limitation') + $this->getDatabaseConnection()->createQueryBuilder()->select('*')->from('ezpolicy_limitation') ); } @@ -775,7 +775,7 @@ public function testDeletePolicyLimitationValues() $this->assertQueryResult( [[4, 3, 'Blubb']], - $this->handler->createSelectQuery()->select('*')->from('ezpolicy_limitation_value') + $this->getDatabaseConnection()->createQueryBuilder()->select('*')->from('ezpolicy_limitation_value') ); } @@ -797,7 +797,7 @@ public function testUpdatePolicies() [3, 'Foo', 2], [4, 'new', 1], ], - $this->handler->createSelectQuery()->select('*')->from('ezpolicy_limitation') + $this->getDatabaseConnection()->createQueryBuilder()->select('*')->from('ezpolicy_limitation') ); $this->assertQueryResult( @@ -805,7 +805,7 @@ public function testUpdatePolicies() [4, 3, 'Blubb'], [5, 4, 'something'], ], - $this->handler->createSelectQuery()->select('*')->from('ezpolicy_limitation_value') + $this->getDatabaseConnection()->createQueryBuilder()->select('*')->from('ezpolicy_limitation_value') ); } @@ -824,7 +824,7 @@ public function testAddRoleToUser() [ [1, self::TEST_USER_ID, 1, null, null], ], - $this->handler->createSelectQuery()->select('id', 'contentobject_id', 'role_id', 'limit_identifier', 'limit_value')->from('ezuser_role'), + $this->getDatabaseConnection()->createQueryBuilder()->select('id', 'contentobject_id', 'role_id', 'limit_identifier', 'limit_value')->from('ezuser_role'), 'Expected a new user policy association.' ); } @@ -850,7 +850,7 @@ public function testAddRoleToUserWithLimitation() [ [1, self::TEST_USER_ID, 1, 'Subtree', '/1'], ], - $this->handler->createSelectQuery()->select('id', 'contentobject_id', 'role_id', 'limit_identifier', 'limit_value')->from('ezuser_role'), + $this->getDatabaseConnection()->createQueryBuilder()->select('id', 'contentobject_id', 'role_id', 'limit_identifier', 'limit_value')->from('ezuser_role'), 'Expected a new user policy association.' ); } @@ -879,7 +879,7 @@ public function testAddRoleToUserWithComplexLimitation() [2, self::TEST_USER_ID, 1, 'Subtree', '/1/2'], [3, self::TEST_USER_ID, 1, 'Foo', 'Bar'], ], - $this->handler->createSelectQuery()->select('id', 'contentobject_id', 'role_id', 'limit_identifier', 'limit_value')->from('ezuser_role'), + $this->getDatabaseConnection()->createQueryBuilder()->select('id', 'contentobject_id', 'role_id', 'limit_identifier', 'limit_value')->from('ezuser_role'), 'Expected a new user policy association.' ); } @@ -906,7 +906,7 @@ public function testRemoveUserRoleAssociation() $this->assertQueryResult( [], - $this->handler->createSelectQuery()->select('id', 'contentobject_id', 'role_id', 'limit_identifier', 'limit_value')->from('ezuser_role'), + $this->getDatabaseConnection()->createQueryBuilder()->select('id', 'contentobject_id', 'role_id', 'limit_identifier', 'limit_value')->from('ezuser_role'), 'Expected no user policy associations.' ); } diff --git a/eZ/Publish/Core/Persistence/Legacy/Tests/UserPreference/Gateway/DoctrineDatabaseTest.php b/eZ/Publish/Core/Persistence/Legacy/Tests/UserPreference/Gateway/DoctrineDatabaseTest.php index 30c3bbcd05..4d2c5b5c53 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Tests/UserPreference/Gateway/DoctrineDatabaseTest.php +++ b/eZ/Publish/Core/Persistence/Legacy/Tests/UserPreference/Gateway/DoctrineDatabaseTest.php @@ -121,7 +121,7 @@ public function testLoadUserPreferences() protected function getGateway(): Gateway { return new DoctrineDatabase( - $this->getDatabaseHandler()->getConnection() + $this->getDatabaseConnection() ); } diff --git a/eZ/Publish/SPI/Tests/FieldType/ImageIntegrationTest.php b/eZ/Publish/SPI/Tests/FieldType/ImageIntegrationTest.php index 5e3bf514a3..6f530f520d 100644 --- a/eZ/Publish/SPI/Tests/FieldType/ImageIntegrationTest.php +++ b/eZ/Publish/SPI/Tests/FieldType/ImageIntegrationTest.php @@ -15,6 +15,7 @@ use eZ\Publish\Core\FieldType\Image\AliasCleanerInterface; use eZ\Publish\SPI\Persistence\Content; use eZ\Publish\SPI\Persistence\Content\Field; +use PHPUnit\Framework\MockObject\MockObject; use RecursiveIteratorIterator; use RecursiveDirectoryIterator; use FileSystemIterator; @@ -90,7 +91,7 @@ public function getCustomHandler() new FieldType\Image\ImageStorage( new FieldType\Image\ImageStorage\Gateway\DoctrineStorage( $urlRedecorator, - $this->getDatabaseHandler()->getConnection() + $this->getDatabaseConnection() ), $this->ioService, new FieldType\Image\PathGenerator\LegacyPathGenerator(), @@ -101,7 +102,10 @@ public function getCustomHandler() ); } - public function getDeprecationWarnerMock() + /** + * @return \eZ\Publish\Core\Base\Utils\DeprecationWarnerInterface|\PHPUnit\Framework\MockObject\MockObject + */ + public function getDeprecationWarnerMock(): MockObject { if (!isset($this->deprecationWarnerMock)) { $this->deprecationWarnerMock = $this->createMock(DeprecationWarnerInterface::class); @@ -110,7 +114,10 @@ public function getDeprecationWarnerMock() return $this->deprecationWarnerMock; } - public function getAliasCleanerMock() + /** + * @return \eZ\Publish\Core\FieldType\Image\AliasCleanerInterface|\PHPUnit\Framework\MockObject\MockObject + */ + public function getAliasCleanerMock(): MockObject { if (!isset($this->aliasCleanerMock)) { $this->aliasCleanerMock = $this->createMock(AliasCleanerInterface::class); diff --git a/eZ/Publish/SPI/Tests/FieldType/KeywordIntegrationTest.php b/eZ/Publish/SPI/Tests/FieldType/KeywordIntegrationTest.php index 3a797592df..6fe3f77977 100644 --- a/eZ/Publish/SPI/Tests/FieldType/KeywordIntegrationTest.php +++ b/eZ/Publish/SPI/Tests/FieldType/KeywordIntegrationTest.php @@ -61,7 +61,7 @@ public function getCustomHandler() new Legacy\Content\FieldValue\Converter\KeywordConverter(), new FieldType\Keyword\KeywordStorage( new FieldType\Keyword\KeywordStorage\Gateway\DoctrineStorage( - $this->getDatabaseHandler()->getConnection() + $this->getDatabaseConnection() ) ) );