reverted: --- b/core/modules/taxonomy/src/Tests/TaxonomyQueryAlterTest.php +++ a/core/modules/taxonomy/src/Tests/TaxonomyQueryAlterTest.php @@ -32,7 +32,7 @@ } // Set up hierarchy. Term 2 is a child of 1. + $terms[2]->parent = $terms[1]->id(); - $terms[2]->parent->setValue($terms[1]->id()); $terms[2]->save(); $term_storage = \Drupal::entityManager()->getStorage('taxonomy_term'); @@ -50,12 +50,12 @@ $this->setupQueryTagTestHooks(); $loaded_terms = $term_storage->loadParents($terms[2]->id()); $this->assertEqual(count($loaded_terms), 1, 'All parent terms were loaded'); + $this->assertQueryTagTestResult(2, 1, 'TermStorage::loadParents()'); - $this->assertQueryTagTestResult(3, 1, 'TermStorage::loadParents()'); $this->setupQueryTagTestHooks(); $loaded_terms = $term_storage->loadChildren($terms[1]->id()); $this->assertEqual(count($loaded_terms), 1, 'All child terms were loaded'); + $this->assertQueryTagTestResult(2, 1, 'TermStorage::loadChildren()'); - $this->assertQueryTagTestResult(3, 1, 'TermStorage::loadChildren()'); $this->setupQueryTagTestHooks(); $query = db_select('taxonomy_term_data', 't'); reverted: --- b/core/modules/taxonomy/src/Tests/Update/TaxonomyUpdateTest.php +++ /dev/null @@ -1,148 +0,0 @@ -databaseDumpFiles = [ - __DIR__ . '/../../../../system/tests/fixtures/update/drupal-8-rc1.bare.standard.php.gz', - ]; - } - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - $this->db = $this->container->get('database'); - } - - /** - * Tests taxonomy term parents update. - * - * @see taxonomy_update_8201() - * @see taxonomy_update_8202() - * @see taxonomy_update_8203() - */ - public function testTaxonomyUpdateParents() { - $tids = $this->createTerms(); - $vid = $this->createView(); - - // Run updates. - $this->runUpdates(); - - /** @var \Drupal\taxonomy\TermInterface $term */ - $term = Term::load($tids[1]); - $parents = [$tids[2], $tids[3]]; - $this->assertIdentical(count($term->parent), 2); - $this->assertTrue(in_array($term->parent[0]->entity->id(), $parents)); - $this->assertTrue(in_array($term->parent[1]->entity->id(), $parents)); - - $term = Term::load($tids[2]); - $parents = [0, $tids[3]]; - $this->assertIdentical(count($term->parent), 2); - $this->assertTrue(in_array($term->parent[0]->target_id, $parents)); - $this->assertTrue(in_array($term->parent[1]->target_id, $parents)); - - $term = Term::load($tids[3]); - $this->assertIdentical(count($term->parent), 1); - // Target ID is returned as string. - $this->assertIdentical((int) $term->get('parent')[0]->target_id, 0); - - // Test if the view has been converted to use {taxonomy_term__parent} table - // instead of {taxonomy_term_hierarchy}. - $view = $this->config("views.view.$vid"); - $path = 'display.default.display_options.relationships.parent.table'; - $this->assertIdentical($view->get($path), 'taxonomy_term__parent'); - - // The {taxonomy_term_hierarchy} table has been removed. - $this->assertFalse($this->db->schema()->tableExists('taxonomy_term_hierarchy')); - } - - /** - * Creates some terms on a very low level, bypassing the API. - * - * @return array - * A list of created term IDs. - */ - protected function createTerms() { - /** @var \Drupal\Component\Uuid\UuidInterface $uuid */ - $uuid = \Drupal::service('uuid'); - - $tids = [0]; // The root tid. - for ($i = 0; $i < 4; $i++) { - $name = $this->randomString(); - $tid = $this->db->insert('taxonomy_term_data') - ->fields(['vid', 'uuid', 'langcode']) - ->values(['vid' => 'tags', 'uuid' => $uuid->generate(), 'langcode' => 'en']) - ->execute(); - $this->db->insert('taxonomy_term_field_data') - ->fields(['tid', 'vid', 'langcode', 'name', 'weight', 'changed', 'default_langcode']) - ->values(['tid' => $tid, 'vid' => 'tags', 'langcode' => 'en', 'name' => $name, 'weight' => 0, 'changed' => REQUEST_TIME, 'default_langcode' => 1]) - ->execute(); - $tids[] = $tid; - } - - $hierarchy = [ - // This reads as: tid with index 1 has tids with index 2 and 3 as parents. - 1 => [2, 3], - 2 => [3, 0], - 3 => [0], - ]; - - $query = $this->db->insert('taxonomy_term_hierarchy')->fields(['tid', 'parent']); - foreach ($hierarchy as $tid => $parents) { - foreach ($parents as $parent) { - $query->values(['tid' => $tids[$tid], 'parent' => $tids[$parent]]); - } - } - $query->execute(); - - return $tids; - } - - /** - * Creates a test view using a low level API. - * - * @return string - * The view id. - */ - protected function createView() { - $vid = Unicode::strtolower($this->randomMachineName()); - $file = __DIR__ . '/../../../tests/modules/taxonomy_test_views/test_views/views.view.test_taxonomy_parent.yml'; - $config = Yaml::decode(file_get_contents($file)); - - $this->db->insert('config') - ->fields(['collection', 'name', 'data']) - ->values([ - 'collection' => '', - 'name' => "views.view.$vid", - 'data' => serialize($config), - ]) - ->execute(); - - return $vid; - } - -} reverted: --- b/core/modules/taxonomy/src/Tests/Views/TaxonomyRelationshipTest.php +++ a/core/modules/taxonomy/src/Tests/Views/TaxonomyRelationshipTest.php @@ -61,19 +61,19 @@ $this->assertEqual($views_data['table']['join']['taxonomy_term_field_data']['field'], 'tid'); $this->assertEqual($views_data['table']['join']['node_field_data']['left_field'], 'nid'); $this->assertEqual($views_data['table']['join']['node_field_data']['field'], 'nid'); + $this->assertEqual($views_data['table']['join']['taxonomy_term_hierarchy']['left_field'], 'tid'); + $this->assertEqual($views_data['table']['join']['taxonomy_term_hierarchy']['field'], 'tid'); - $this->assertEqual($views_data['table']['join']['taxonomy_term__parent']['left_field'], 'entity_id'); - $this->assertEqual($views_data['table']['join']['taxonomy_term__parent']['field'], 'tid'); + // Check the generated views data of taxonomy_term_hierarchy. + $views_data = Views::viewsData()->get('taxonomy_term_hierarchy'); - // Check the generated views data of taxonomy_term__parent. - $views_data = Views::viewsData()->get('taxonomy_term__parent'); // Check the table join data. + $this->assertEqual($views_data['table']['join']['taxonomy_term_hierarchy']['left_field'], 'tid'); + $this->assertEqual($views_data['table']['join']['taxonomy_term_hierarchy']['field'], 'parent'); - $this->assertEqual($views_data['table']['join']['taxonomy_term__parent']['left_field'], 'entity_id'); - $this->assertEqual($views_data['table']['join']['taxonomy_term__parent']['field'], 'parent_target_id'); $this->assertEqual($views_data['table']['join']['taxonomy_term_field_data']['left_field'], 'tid'); + $this->assertEqual($views_data['table']['join']['taxonomy_term_field_data']['field'], 'tid'); - $this->assertEqual($views_data['table']['join']['taxonomy_term_field_data']['field'], 'entity_id'); // Check the parent relationship data. $this->assertEqual($views_data['parent']['relationship']['base'], 'taxonomy_term_field_data'); + $this->assertEqual($views_data['parent']['relationship']['field'], 'parent'); - $this->assertEqual($views_data['parent']['relationship']['field'], 'parent_target_id'); $this->assertEqual($views_data['parent']['relationship']['label'], t('Parent')); $this->assertEqual($views_data['parent']['relationship']['id'], 'standard'); // Check the parent filter and argument data. @@ -95,7 +95,7 @@ if (!$index) { $this->assertTrue($row->_relationship_entities['parent'] instanceof TermInterface); $this->assertEqual($row->_relationship_entities['parent']->id(), $this->term2->id()); + $this->assertEqual($row->taxonomy_term_field_data_taxonomy_term_hierarchy_tid, $this->term2->id()); - $this->assertEqual($row->taxonomy_term_field_data_taxonomy_term__parent_tid, $this->term2->id()); } $this->assertTrue($row->_relationship_entities['nid'] instanceof NodeInterface); $this->assertEqual($row->_relationship_entities['nid']->id(), $this->nodes[$index]->id()); only in patch2: unchanged: --- a/core/modules/taxonomy/tests/src/Functional/TaxonomyQueryAlterTest.php +++ b/core/modules/taxonomy/tests/src/Functional/TaxonomyQueryAlterTest.php @@ -32,7 +32,7 @@ public function testTaxonomyQueryAlter() { } // Set up hierarchy. Term 2 is a child of 1. - $terms[2]->parent = $terms[1]->id(); + $terms[2]->parent->setValue($terms[1]->id()); $terms[2]->save(); $term_storage = \Drupal::entityManager()->getStorage('taxonomy_term'); @@ -50,12 +50,12 @@ public function testTaxonomyQueryAlter() { $this->setupQueryTagTestHooks(); $loaded_terms = $term_storage->loadParents($terms[2]->id()); $this->assertEqual(count($loaded_terms), 1, 'All parent terms were loaded'); - $this->assertQueryTagTestResult(2, 1, 'TermStorage::loadParents()'); + $this->assertQueryTagTestResult(3, 1, 'TermStorage::loadParents()'); $this->setupQueryTagTestHooks(); $loaded_terms = $term_storage->loadChildren($terms[1]->id()); $this->assertEqual(count($loaded_terms), 1, 'All child terms were loaded'); - $this->assertQueryTagTestResult(2, 1, 'TermStorage::loadChildren()'); + $this->assertQueryTagTestResult(3, 1, 'TermStorage::loadChildren()'); $this->setupQueryTagTestHooks(); $query = db_select('taxonomy_term_data', 't'); only in patch2: unchanged: --- /dev/null +++ b/core/modules/taxonomy/tests/src/Functional/Update/TaxonomyUpdateTest.php @@ -0,0 +1,148 @@ +databaseDumpFiles = [ + __DIR__ . '/../../../../system/tests/fixtures/update/drupal-8-rc1.bare.standard.php.gz', + ]; + } + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + $this->db = $this->container->get('database'); + } + + /** + * Tests taxonomy term parents update. + * + * @see taxonomy_update_8201() + * @see taxonomy_update_8202() + * @see taxonomy_update_8203() + */ + public function testTaxonomyUpdateParents() { + $tids = $this->createTerms(); + $vid = $this->createView(); + + // Run updates. + $this->runUpdates(); + + /** @var \Drupal\taxonomy\TermInterface $term */ + $term = Term::load($tids[1]); + $parents = [$tids[2], $tids[3]]; + $this->assertIdentical(count($term->parent), 2); + $this->assertTrue(in_array($term->parent[0]->entity->id(), $parents)); + $this->assertTrue(in_array($term->parent[1]->entity->id(), $parents)); + + $term = Term::load($tids[2]); + $parents = [0, $tids[3]]; + $this->assertIdentical(count($term->parent), 2); + $this->assertTrue(in_array($term->parent[0]->target_id, $parents)); + $this->assertTrue(in_array($term->parent[1]->target_id, $parents)); + + $term = Term::load($tids[3]); + $this->assertIdentical(count($term->parent), 1); + // Target ID is returned as string. + $this->assertIdentical((int) $term->get('parent')[0]->target_id, 0); + + // Test if the view has been converted to use {taxonomy_term__parent} table + // instead of {taxonomy_term_hierarchy}. + $view = $this->config("views.view.$vid"); + $path = 'display.default.display_options.relationships.parent.table'; + $this->assertIdentical($view->get($path), 'taxonomy_term__parent'); + + // The {taxonomy_term_hierarchy} table has been removed. + $this->assertFalse($this->db->schema()->tableExists('taxonomy_term_hierarchy')); + } + + /** + * Creates some terms on a very low level, bypassing the API. + * + * @return array + * A list of created term IDs. + */ + protected function createTerms() { + /** @var \Drupal\Component\Uuid\UuidInterface $uuid */ + $uuid = \Drupal::service('uuid'); + + $tids = [0]; // The root tid. + for ($i = 0; $i < 4; $i++) { + $name = $this->randomString(); + $tid = $this->db->insert('taxonomy_term_data') + ->fields(['vid', 'uuid', 'langcode']) + ->values(['vid' => 'tags', 'uuid' => $uuid->generate(), 'langcode' => 'en']) + ->execute(); + $this->db->insert('taxonomy_term_field_data') + ->fields(['tid', 'vid', 'langcode', 'name', 'weight', 'changed', 'default_langcode']) + ->values(['tid' => $tid, 'vid' => 'tags', 'langcode' => 'en', 'name' => $name, 'weight' => 0, 'changed' => REQUEST_TIME, 'default_langcode' => 1]) + ->execute(); + $tids[] = $tid; + } + + $hierarchy = [ + // This reads as: tid with index 1 has tids with index 2 and 3 as parents. + 1 => [2, 3], + 2 => [3, 0], + 3 => [0], + ]; + + $query = $this->db->insert('taxonomy_term_hierarchy')->fields(['tid', 'parent']); + foreach ($hierarchy as $tid => $parents) { + foreach ($parents as $parent) { + $query->values(['tid' => $tids[$tid], 'parent' => $tids[$parent]]); + } + } + $query->execute(); + + return $tids; + } + + /** + * Creates a test view using a low level API. + * + * @return string + * The view id. + */ + protected function createView() { + $vid = Unicode::strtolower($this->randomMachineName()); + $file = __DIR__ . '/../../../tests/modules/taxonomy_test_views/test_views/views.view.test_taxonomy_parent.yml'; + $config = Yaml::decode(file_get_contents($file)); + + $this->db->insert('config') + ->fields(['collection', 'name', 'data']) + ->values([ + 'collection' => '', + 'name' => "views.view.$vid", + 'data' => serialize($config), + ]) + ->execute(); + + return $vid; + } + +} only in patch2: unchanged: --- a/core/modules/taxonomy/tests/src/Functional/Views/TaxonomyRelationshipTest.php +++ b/core/modules/taxonomy/tests/src/Functional/Views/TaxonomyRelationshipTest.php @@ -61,19 +61,19 @@ public function testTaxonomyRelationships() { $this->assertEqual($views_data['table']['join']['taxonomy_term_field_data']['field'], 'tid'); $this->assertEqual($views_data['table']['join']['node_field_data']['left_field'], 'nid'); $this->assertEqual($views_data['table']['join']['node_field_data']['field'], 'nid'); - $this->assertEqual($views_data['table']['join']['taxonomy_term_hierarchy']['left_field'], 'tid'); - $this->assertEqual($views_data['table']['join']['taxonomy_term_hierarchy']['field'], 'tid'); + $this->assertEqual($views_data['table']['join']['taxonomy_term__parent']['left_field'], 'entity_id'); + $this->assertEqual($views_data['table']['join']['taxonomy_term__parent']['field'], 'tid'); - // Check the generated views data of taxonomy_term_hierarchy. - $views_data = Views::viewsData()->get('taxonomy_term_hierarchy'); + // Check the generated views data of taxonomy_term__parent. + $views_data = Views::viewsData()->get('taxonomy_term__parent'); // Check the table join data. - $this->assertEqual($views_data['table']['join']['taxonomy_term_hierarchy']['left_field'], 'tid'); - $this->assertEqual($views_data['table']['join']['taxonomy_term_hierarchy']['field'], 'parent'); + $this->assertEqual($views_data['table']['join']['taxonomy_term__parent']['left_field'], 'entity_id'); + $this->assertEqual($views_data['table']['join']['taxonomy_term__parent']['field'], 'parent_target_id'); $this->assertEqual($views_data['table']['join']['taxonomy_term_field_data']['left_field'], 'tid'); - $this->assertEqual($views_data['table']['join']['taxonomy_term_field_data']['field'], 'tid'); + $this->assertEqual($views_data['table']['join']['taxonomy_term_field_data']['field'], 'entity_id'); // Check the parent relationship data. $this->assertEqual($views_data['parent']['relationship']['base'], 'taxonomy_term_field_data'); - $this->assertEqual($views_data['parent']['relationship']['field'], 'parent'); + $this->assertEqual($views_data['parent']['relationship']['field'], 'parent_target_id'); $this->assertEqual($views_data['parent']['relationship']['label'], t('Parent')); $this->assertEqual($views_data['parent']['relationship']['id'], 'standard'); // Check the parent filter and argument data. @@ -95,7 +95,7 @@ public function testTaxonomyRelationships() { if (!$index) { $this->assertTrue($row->_relationship_entities['parent'] instanceof TermInterface); $this->assertEqual($row->_relationship_entities['parent']->id(), $this->term2->id()); - $this->assertEqual($row->taxonomy_term_field_data_taxonomy_term_hierarchy_tid, $this->term2->id()); + $this->assertEqual($row->taxonomy_term_field_data_taxonomy_term__parent_tid, $this->term2->id()); } $this->assertTrue($row->_relationship_entities['nid'] instanceof NodeInterface); $this->assertEqual($row->_relationship_entities['nid']->id(), $this->nodes[$index]->id());