3 namespace Drupal\Tests\taxonomy\Functional\Update;
5 use Drupal\FunctionalTests\Update\UpdatePathTestBase;
6 use Drupal\user\Entity\User;
7 use Drupal\views\Entity\View;
10 * Tests the upgrade path for taxonomy terms.
16 class TaxonomyTermUpdatePathTest extends UpdatePathTestBase {
21 protected function setDatabaseDumpFiles() {
22 $this->databaseDumpFiles = [
23 __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.filled.standard.php.gz',
24 __DIR__ . '/../../../fixtures/update/drupal-8.views-taxonomy-term-publishing-status-2981887.php',
29 * Tests the conversion of taxonomy terms to be publishable.
31 * @see taxonomy_update_8601()
33 public function testPublishable() {
37 $account = User::load(1);
38 $account->passRaw = 'drupal';
39 $this->drupalLogin($account);
41 // Make sure our vocabulary exists.
42 $this->drupalGet('admin/structure/taxonomy/manage/test_vocabulary/overview');
44 // Make sure our terms exist.
45 $assert_session = $this->assertSession();
46 $assert_session->pageTextContains('Test root term');
47 $assert_session->pageTextContains('Test child term');
49 $this->drupalGet('taxonomy/term/3');
50 $assert_session->statusCodeEquals('200');
52 // Make sure the terms are still translated.
53 $this->drupalGet('taxonomy/term/2/translations');
54 $assert_session->linkExists('Test root term - Spanish');
56 $storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term');
58 // Check that the 'content_translation_status' field has been updated
60 /** @var \Drupal\taxonomy\TermInterface $term */
61 $term = $storage->load(2);
62 $translation = $term->getTranslation('es');
63 $this->assertTrue($translation->isPublished());
65 // Check that taxonomy terms can be created, saved and then loaded.
66 $term = $storage->create([
67 'name' => 'Test term',
72 $term = $storage->loadUnchanged($term->id());
74 $this->assertEquals('Test term', $term->label());
75 $this->assertEquals('tags', $term->bundle());
76 $this->assertTrue($term->isPublished());
78 // Check that the term can be unpublished.
79 $term->setUnpublished();
81 $term = $storage->loadUnchanged($term->id());
82 $this->assertFalse($term->isPublished());
84 // Test the update does not run when a status field already exists.
85 module_load_install('taxonomy');
86 $this->assertEquals('The publishing status field has <strong>not</strong> been added to taxonomy terms. See <a href="https://www.drupal.org/node/2985366">this page</a> for more information on how to install it.', (string) taxonomy_update_8601());
87 // Test the message can be overridden.
88 \Drupal::state()->set('taxonomy_update_8601_skip_message', 'Another message');
89 $this->assertEquals('Another message', (string) taxonomy_update_8601());
93 * Tests handling of the publishing status in taxonomy term views updates.
95 * @see taxonomy_post_update_handle_publishing_status_addition_in_views()
97 public function testPublishingStatusUpdateForTaxonomyTermViews() {
98 // Check that the test view was previously using the
99 // 'content_translation_status' field.
100 $config = \Drupal::config('views.view.test_taxonomy_term_view_with_content_translation_status');
101 $display_options = $config->get('display.default.display_options');
102 $this->assertEquals('content_translation_status', $display_options['fields']['content_translation_status']['field']);
103 $this->assertEquals('content_translation_status', $display_options['filters']['content_translation_status']['field']);
104 $this->assertEquals('content_translation_status', $display_options['sorts']['content_translation_status']['field']);
106 // Check a test view without any filter.
107 $config = \Drupal::config('views.view.test_taxonomy_term_view_without_content_translation_status');
108 $display_options = $config->get('display.default.display_options');
109 $this->assertEmpty($display_options['filters']);
113 // Check that a view which had a field, filter and a sort on the
114 // 'content_translation_status' field has been updated to use the new
116 $view = View::load('test_taxonomy_term_view_with_content_translation_status');
117 foreach ($view->get('display') as $display) {
118 $this->assertEquals('status', $display['display_options']['fields']['content_translation_status']['field']);
119 $this->assertEquals('status', $display['display_options']['sorts']['content_translation_status']['field']);
120 $this->assertEquals('status', $display['display_options']['filters']['content_translation_status']['field']);
123 // Check that a view without any filters has been updated to include a
124 // filter for the 'status' field.
125 $view = View::load('test_taxonomy_term_view_without_content_translation_status');
126 foreach ($view->get('display') as $display) {
127 $this->assertNotEmpty($display['display_options']['filters']);
128 $this->assertEquals('status', $display['display_options']['filters']['status']['field']);
135 protected function replaceUser1() {
136 // Do not replace the user from our dump.