class TaxonomyRevisionRevertTest
Same name and namespace in other branches
- 11.x core/modules/taxonomy/tests/src/Functional/TaxonomyRevisionRevertTest.php \Drupal\Tests\taxonomy\Functional\TaxonomyRevisionRevertTest
Taxonomy term revision form test.
@group taxonomy
@coversDefaultClass \Drupal\Core\Entity\Form\RevisionRevertForm
Hierarchy
- class \Drupal\Tests\taxonomy\Functional\TaxonomyRevisionRevertTest
Expanded class hierarchy of TaxonomyRevisionRevertTest
File
-
core/
modules/ taxonomy/ tests/ src/ Functional/ TaxonomyRevisionRevertTest.php, line 17
Namespace
Drupal\Tests\taxonomy\FunctionalView source
class TaxonomyRevisionRevertTest extends BrowserTestBase {
use TaxonomyTestTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'system',
'taxonomy',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected $permissions = [
'view term revisions in test',
'revert all taxonomy revisions',
];
/**
* Vocabulary for testing.
*
* @var \Drupal\taxonomy\VocabularyInterface
*/
private $vocabulary;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->vocabulary = $this->createVocabulary([
'vid' => 'test',
'name' => 'Test',
]);
}
/**
* Tests revision revert.
*/
public function testRevertForm() : void {
$termName = $this->randomMachineName();
$entity = Term::create([
'vid' => $this->vocabulary
->id(),
'name' => $termName,
]);
$entity->setRevisionCreationTime((new \DateTimeImmutable('11 January 2009 4pm'))->getTimestamp())
->setRevisionTranslationAffected(TRUE);
$entity->setNewRevision();
$entity->save();
$revisionId = $entity->getRevisionId();
$this->drupalLogin($this->drupalCreateUser($this->permissions));
// Cannot revert latest revision.
$this->drupalGet($entity->toUrl('revision-revert-form'));
$this->assertSession()
->statusCodeEquals(403);
// Create a new latest revision.
$entity->setRevisionCreationTime((new \DateTimeImmutable('11 January 2009 5pm'))->getTimestamp())
->setRevisionTranslationAffected(TRUE)
->setNewRevision();
$entity->save();
// Reload the entity.
$revision = \Drupal::entityTypeManager()->getStorage('taxonomy_term')
->loadRevision($revisionId);
$this->drupalGet($revision->toUrl('revision-revert-form'));
$this->assertSession()
->pageTextContains('Are you sure you want to revert to the revision from Sun, 01/11/2009 - 16:00?');
$this->assertSession()
->buttonExists('Revert');
$this->assertSession()
->linkExists('Cancel');
$countRevisions = static function () : int {
return (int) \Drupal::entityTypeManager()->getStorage('taxonomy_term')
->getQuery()
->accessCheck(FALSE)
->allRevisions()
->count()
->execute();
};
$count = $countRevisions();
$this->submitForm([], 'Revert');
$this->assertEquals($count + 1, $countRevisions());
$this->assertSession()
->statusCodeEquals(200);
$this->assertSession()
->addressEquals(sprintf('taxonomy/term/%s/revisions', $entity->id()));
$this->assertSession()
->pageTextContains(sprintf('Test %s has been reverted to the revision from Sun, 01/11/2009 - 16:00.', $termName));
$this->assertSession()
->elementsCount('css', 'table tbody tr', 3);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
StorageCopyTrait::replaceStorageContents | protected static | function | Copy the configuration from one storage to another and remove stale items. |
TaxonomyRevisionRevertTest::$defaultTheme | protected | property | The theme to install as the default for testing. |
TaxonomyRevisionRevertTest::$modules | protected static | property | Modules to install. |
TaxonomyRevisionRevertTest::$permissions | protected | property | |
TaxonomyRevisionRevertTest::$vocabulary | private | property | Vocabulary for testing. |
TaxonomyRevisionRevertTest::setUp | protected | function | |
TaxonomyRevisionRevertTest::testRevertForm | public | function | Tests revision revert. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.