public function TaxonomyTermUpdatePathTest::testPublishable in Drupal 8
Tests the conversion of taxonomy terms to be publishable.
See also
File
- core/
modules/ taxonomy/ tests/ src/ Functional/ Update/ TaxonomyTermUpdatePathTest.php, line 37  
Class
- TaxonomyTermUpdatePathTest
 - Tests the upgrade path for taxonomy terms.
 
Namespace
Drupal\Tests\taxonomy\Functional\UpdateCode
public function testPublishable() {
  $this
    ->runUpdates();
  // Log in as user 1.
  $account = User::load(1);
  $account->passRaw = 'drupal';
  $this
    ->drupalLogin($account);
  // Make sure our vocabulary exists.
  $this
    ->drupalGet('admin/structure/taxonomy/manage/test_vocabulary/overview');
  // Make sure our terms exist.
  $assert_session = $this
    ->assertSession();
  $assert_session
    ->pageTextContains('Test root term');
  $assert_session
    ->pageTextContains('Test child term');
  $this
    ->drupalGet('taxonomy/term/3');
  $assert_session
    ->statusCodeEquals('200');
  // Make sure the terms are still translated.
  $this
    ->drupalGet('taxonomy/term/2/translations');
  $assert_session
    ->linkExists('Test root term - Spanish');
  $storage = \Drupal::entityTypeManager()
    ->getStorage('taxonomy_term');
  // Check that the 'content_translation_status' field has been updated
  // correctly.
  /** @var \Drupal\taxonomy\TermInterface $term */
  $term = $storage
    ->load(2);
  $translation = $term
    ->getTranslation('es');
  $this
    ->assertTrue($translation
    ->isPublished());
  // Check that taxonomy terms can be created, saved and then loaded.
  $term = $storage
    ->create([
    'name' => 'Test term',
    'vid' => 'tags',
  ]);
  $term
    ->save();
  $term = $storage
    ->loadUnchanged($term
    ->id());
  $this
    ->assertEquals('Test term', $term
    ->label());
  $this
    ->assertEquals('tags', $term
    ->bundle());
  $this
    ->assertTrue($term
    ->isPublished());
  // Check that the term can be unpublished.
  $term
    ->setUnpublished();
  $term
    ->save();
  $term = $storage
    ->loadUnchanged($term
    ->id());
  $this
    ->assertFalse($term
    ->isPublished());
  // Test the update does not run when a status field already exists.
  module_load_install('taxonomy');
  $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());
  // Test the message can be overridden.
  \Drupal::state()
    ->set('taxonomy_update_8601_skip_message', 'Another message');
  $this
    ->assertEquals('Another message', (string) taxonomy_update_8601());
}