Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / taxonomy / tests / src / Functional / Update / TaxonomyParentUpdateTest.php
1 <?php
2
3 namespace Drupal\Tests\taxonomy\Functional\Update;
4
5 use Drupal\FunctionalTests\Update\UpdatePathTestBase;
6 use Drupal\taxonomy\Entity\Term;
7
8 /**
9  * Ensure that the taxonomy updates are running as expected.
10  *
11  * @group taxonomy
12  * @group Update
13  * @group legacy
14  */
15 class TaxonomyParentUpdateTest extends UpdatePathTestBase {
16
17   /**
18    * The database connection.
19    *
20    * @var \Drupal\Core\Database\Connection
21    */
22   protected $db;
23
24   /**
25    * {@inheritdoc}
26    */
27   protected function setUp() {
28     parent::setUp();
29     $this->db = $this->container->get('database');
30   }
31
32   /**
33    * {@inheritdoc}
34    */
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',
39     ];
40   }
41
42   /**
43    * Tests taxonomy term parents update.
44    *
45    * @see taxonomy_update_8501()
46    * @see taxonomy_update_8502()
47    * @see taxonomy_update_8503()
48    */
49   public function testTaxonomyUpdateParents() {
50     // Force the update hook to only run one term per batch.
51     drupal_rewrite_settings([
52       'settings' => [
53         'entity_update_batch_size' => (object) [
54           'value' => 1,
55           'required' => TRUE,
56         ],
57       ],
58     ]);
59
60     // Run updates.
61     $this->runUpdates();
62
63     /** @var \Drupal\taxonomy\TermInterface $term */
64     $term = Term::load(1);
65     $parents = [2, 3];
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));
69
70     $term = Term::load(2);
71     $parents = [0, 3];
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));
75
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);
80
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");
84
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"));
88
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"));
92
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"));
96
97     // The {taxonomy_term_hierarchy} table has been removed.
98     $this->assertFalse($this->db->schema()->tableExists('taxonomy_term_hierarchy'));
99   }
100
101 }