class ModerationStateTaxonomyTermTest

Same name and namespace in other branches
  1. 11.x core/modules/content_moderation/tests/src/Functional/ModerationStateTaxonomyTermTest.php \Drupal\Tests\content_moderation\Functional\ModerationStateTaxonomyTermTest

Tests the taxonomy term moderation handler.

@group content_moderation

Hierarchy

Expanded class hierarchy of ModerationStateTaxonomyTermTest

File

core/modules/content_moderation/tests/src/Functional/ModerationStateTaxonomyTermTest.php, line 16

Namespace

Drupal\Tests\content_moderation\Functional
View source
class ModerationStateTaxonomyTermTest extends ModerationStateTestBase {
  
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';
  
  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    // Create a "Tags" vocabulary.
    $bundle = Vocabulary::create([
      'vid' => 'tags',
      'name' => 'Tags',
      'new_revision' => FALSE,
    ])->save();
  }
  
  /**
   * Tests the taxonomy term moderation handler alters the forms as intended.
   *
   * @covers \Drupal\content_moderation\Entity\Handler\TaxonomyTermModerationHandler::enforceRevisionsEntityFormAlter
   * @covers \Drupal\content_moderation\Entity\Handler\TaxonomyTermModerationHandler::enforceRevisionsBundleFormAlter
   */
  public function testEnforceRevisionsEntityFormAlter() : void {
    $this->drupalLogin($this->adminUser);
    // Enable moderation for the tags vocabulary.
    $edit['bundles[tags]'] = TRUE;
    $this->drupalGet('/admin/config/workflow/workflows/manage/editorial/type/taxonomy_term');
    $this->submitForm($edit, 'Save');
    // Check that revision is checked by default when content moderation is
    // enabled for the vocabulary.
    $this->drupalGet('/admin/structure/taxonomy/manage/tags');
    $this->assertSession()
      ->checkboxChecked('revision');
    $this->assertSession()
      ->pageTextContains('Revisions must be required when moderation is enabled.');
    $this->assertSession()
      ->fieldDisabled('revision');
    // Create a taxonomy term and save it as draft.
    $term = Term::create([
      'name' => 'Test tag',
      'vid' => 'tags',
      'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
    ]);
    $term->save();
    // Check that revision is checked by default when editing a term and
    // content moderation is enabled for the term's vocabulary.
    $this->drupalGet($term->toUrl('edit-form'));
    $this->assertSession()
      ->checkboxChecked('revision');
    $this->assertSession()
      ->pageTextContains('Revisions must be required when moderation is enabled.');
    $this->assertSession()
      ->fieldDisabled('revision');
  }

}

Members

Title Sort descending Modifiers Object type Summary
ModerationStateTaxonomyTermTest::$defaultTheme protected property The theme to install as the default for testing.
ModerationStateTaxonomyTermTest::setUp protected function Sets the test up.
ModerationStateTaxonomyTermTest::testEnforceRevisionsEntityFormAlter public function Tests the taxonomy term moderation handler alters the forms as intended.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.