function NodeRevisionsTest::setUp
Same name in other branches
- 9 core/modules/node/tests/src/Functional/NodeRevisionsTest.php \Drupal\Tests\node\Functional\NodeRevisionsTest::setUp()
- 10 core/modules/node/tests/src/Functional/NodeRevisionsTest.php \Drupal\Tests\node\Functional\NodeRevisionsTest::setUp()
- 11.x core/modules/node/tests/src/Functional/NodeRevisionsTest.php \Drupal\Tests\node\Functional\NodeRevisionsTest::setUp()
Overrides NodeTestBase::setUp
File
-
core/
modules/ node/ tests/ src/ Functional/ NodeRevisionsTest.php, line 55
Class
- NodeRevisionsTest
- Create a node with revisions and test viewing, saving, reverting, and deleting revisions for users with access for this content type.
Namespace
Drupal\Tests\node\FunctionalCode
protected function setUp() {
parent::setUp();
// Enable additional languages.
ConfigurableLanguage::createFromLangcode('de')->save();
ConfigurableLanguage::createFromLangcode('it')->save();
$field_storage_definition = [
'field_name' => 'untranslatable_string_field',
'entity_type' => 'node',
'type' => 'string',
'cardinality' => 1,
'translatable' => FALSE,
];
$field_storage = FieldStorageConfig::create($field_storage_definition);
$field_storage->save();
$field_definition = [
'field_storage' => $field_storage,
'bundle' => 'page',
];
$field = FieldConfig::create($field_definition);
$field->save();
// Enable translation for page nodes.
\Drupal::service('content_translation.manager')->setEnabled('node', 'page', TRUE);
// Create and log in user.
$web_user = $this->drupalCreateUser([
'view page revisions',
'revert page revisions',
'delete page revisions',
'edit any page content',
'delete any page content',
'access contextual links',
'translate any entity',
'administer content types',
]);
$this->drupalLogin($web_user);
// Create initial node.
$node = $this->drupalCreateNode();
$settings = get_object_vars($node);
$settings['revision'] = 1;
$settings['isDefaultRevision'] = TRUE;
$nodes = [];
$logs = [];
// Get original node.
$nodes[] = clone $node;
// Create three revisions.
$revision_count = 3;
for ($i = 0; $i < $revision_count; $i++) {
$logs[] = $node->revision_log = $this->randomMachineName(32);
// Create revision with a random title and body and update variables.
$node->title = $this->randomMachineName();
$node->body = [
'value' => $this->randomMachineName(32),
'format' => filter_default_format(),
];
$node->untranslatable_string_field->value = $this->randomString();
$node->setNewRevision();
// Edit the 1st and 2nd revision with a different user.
if ($i < 2) {
$editor = $this->drupalCreateUser();
$node->setRevisionUserId($editor->id());
}
else {
$node->setRevisionUserId($web_user->id());
}
$node->save();
// Make sure we get revision information.
$node = Node::load($node->id());
$nodes[] = clone $node;
}
$this->nodes = $nodes;
$this->revisionLogs = $logs;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.