diff --git a/core/modules/taxonomy/tests/fixtures/update/drupal-8.taxonomy-index-2889486.php b/core/modules/taxonomy/tests/fixtures/update/drupal-8.taxonomy-index-2889486.php new file mode 100644 index 0000000000..2409b38447 --- /dev/null +++ b/core/modules/taxonomy/tests/fixtures/update/drupal-8.taxonomy-index-2889486.php @@ -0,0 +1,127 @@ +insert('node_field_data') + ->fields([ + 'nid', + 'vid', + 'type', + 'langcode', + 'title', + 'uid', + 'status', + 'created', + 'changed', + 'promote', + 'sticky', + 'revision_translation_affected', + 'default_langcode', + 'content_translation_source', + 'content_translation_outdated', + ]) + ->values([ + 'nid' => 1, + 'vid' => 2, + 'type' => 'article', + 'langcode' => 'es', + 'title' => 'Test Article - New title', + 'uid' => 1, + 'status' => 1, + 'created' => 1439730300, + 'changed' => 1439730369, + 'promote' => 1, + 'sticky' => 1, + 'revision_translation_affected' => 1, + 'default_langcode' => 0, + 'content_translation_source' => 'en', + 'content_translation_outdated' => 0, + ]) + ->execute(); + +$connection->insert('node_field_revision') + ->fields([ + 'nid', + 'vid', + 'langcode', + 'title', + 'uid', + 'status', + 'created', + 'changed', + 'promote', + 'sticky', + 'revision_translation_affected', + 'default_langcode', + 'content_translation_source', + 'content_translation_outdated', + ]) + ->values([ + 'nid' => 1, + 'vid' => 2, + 'langcode' => 'es', + 'title' => 'Test Article - New title', + 'uid' => 1, + 'status' => 1, + 'created' => 1439730300, + 'changed' => 1439730369, + 'promote' => 1, + 'sticky' => 1, + 'revision_translation_affected' => 1, + 'default_langcode' => 0, + 'content_translation_source' => 'en', + 'content_translation_outdated' => 0, + ]) + ->execute(); + +$connection->insert('node__field_tags') + ->fields([ + 'bundle', + 'deleted', + 'entity_id', + 'revision_id', + 'langcode', + 'delta', + 'field_tags_target_id', + ]) + ->values([ + 'bundle' => 'article', + 'deleted' => 0, + 'entity_id' => 1, + 'revision_id' => 2, + 'langcode' => 'es', + 'delta' => 0, + 'field_tags_target_id' => 5, + ]) + ->execute(); + +$connection->insert('node_revision__field_tags') + ->fields([ + 'bundle', + 'deleted', + 'entity_id', + 'revision_id', + 'langcode', + 'delta', + 'field_tags_target_id', + ]) + ->values([ + 'bundle' => 'article', + 'deleted' => 0, + 'entity_id' => 1, + 'revision_id' => 2, + 'langcode' => 'es', + 'delta' => 0, + 'field_tags_target_id' => 5, + ]) + ->execute(); diff --git a/core/modules/taxonomy/tests/src/Functional/Update/TaxonomyIndexUpdateTest.php b/core/modules/taxonomy/tests/src/Functional/Update/TaxonomyIndexUpdateTest.php new file mode 100644 index 0000000000..2ae4a847fc --- /dev/null +++ b/core/modules/taxonomy/tests/src/Functional/Update/TaxonomyIndexUpdateTest.php @@ -0,0 +1,66 @@ +db = $this->container->get('database'); + } + + /** + * {@inheritdoc} + */ + public function setDatabaseDumpFiles() { + $this->databaseDumpFiles = [ + __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.filled.standard.php.gz', + __DIR__ . '/../../../../../taxonomy/tests/fixtures/update/drupal-8.taxonomy-index-2889486.php', + ]; + } + + /** + * Tests taxonomy term parents update. + * + * @see taxonomy_update_8703() + * @see taxonomy_post_update_populate_taxonomy_index_langcode() + */ + public function testTaxonomyIndexLangcodeUpdate() { + $this->assertFalse($this->db->schema()->fieldExists('taxonomy_index', 'langcode'), 'The taxonomy_index table does not have a langcode column.'); + $index_count = $this->db->query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [ + ':nid' => 1, + ':tid' => 5, + ])->fetchField(); + $this->assertEquals(1, $index_count, '1 entry while two translations reference the same tid.'); + + // Run updates. + $this->runUpdates(); + + $this->assertTrue($this->db->schema()->fieldExists('taxonomy_index', 'langcode'), 'The taxonomy_index table has a langcode column.'); + $index_count = $this->db->query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [ + ':nid' => 1, + ':tid' => 5, + ])->fetchField(); + $this->assertEquals(2, $index_count, '2 entries after the update, one for each translation.'); + } + +}