3 namespace Drupal\Tests\taxonomy\Functional\Update;
5 use Drupal\FunctionalTests\Update\UpdatePathTestBase;
6 use Drupal\taxonomy\Entity\Term;
9 * Ensure that the taxonomy updates are running as expected.
15 class TaxonomyParentUpdateTest extends UpdatePathTestBase {
18 * The database connection.
20 * @var \Drupal\Core\Database\Connection
27 protected function setUp() {
29 $this->db = $this->container->get('database');
35 public function setDatabaseDumpFiles() {
36 $this->databaseDumpFiles = [
37 __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8-rc1.bare.standard.php.gz',
38 __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.views-taxonomy-parent-2543726.php',
43 * Tests taxonomy term parents update.
45 * @see taxonomy_update_8501()
46 * @see taxonomy_update_8502()
47 * @see taxonomy_update_8503()
49 public function testTaxonomyUpdateParents() {
50 // Force the update hook to only run one term per batch.
51 drupal_rewrite_settings([
53 'entity_update_batch_size' => (object) [
63 /** @var \Drupal\taxonomy\TermInterface $term */
64 $term = Term::load(1);
66 $this->assertCount(2, $term->parent);
67 $this->assertTrue(in_array($term->parent[0]->entity->id(), $parents));
68 $this->assertTrue(in_array($term->parent[1]->entity->id(), $parents));
70 $term = Term::load(2);
72 $this->assertCount(2, $term->parent);
73 $this->assertTrue(in_array($term->parent[0]->target_id, $parents));
74 $this->assertTrue(in_array($term->parent[1]->target_id, $parents));
76 $term = Term::load(3);
77 $this->assertCount(1, $term->parent);
78 // Target ID is returned as string.
79 $this->assertSame(0, (int) $term->get('parent')[0]->target_id);
81 // Test if the view has been converted to use the {taxonomy_term__parent}
82 // table instead of the {taxonomy_term_hierarchy} table.
83 $view = $this->config("views.view.test_taxonomy_parent");
85 $relationship_base_path = 'display.default.display_options.relationships.parent';
86 $this->assertSame('taxonomy_term__parent', $view->get("$relationship_base_path.table"));
87 $this->assertSame('parent_target_id', $view->get("$relationship_base_path.field"));
89 $filters_base_path_1 = 'display.default.display_options.filters.parent';
90 $this->assertSame('taxonomy_term__parent', $view->get("$filters_base_path_1.table"));
91 $this->assertSame('parent_target_id', $view->get("$filters_base_path_1.field"));
93 $filters_base_path_2 = 'display.default.display_options.filters.parent';
94 $this->assertSame('taxonomy_term__parent', $view->get("$filters_base_path_2.table"));
95 $this->assertSame('parent_target_id', $view->get("$filters_base_path_2.field"));
97 // The {taxonomy_term_hierarchy} table has been removed.
98 $this->assertFalse($this->db->schema()->tableExists('taxonomy_term_hierarchy'));