protected function NodeRevisionsTest::setUp in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/node/src/Tests/NodeRevisionsTest.php \Drupal\node\Tests\NodeRevisionsTest::setUp()
Sets up a Drupal site for running functional and integration tests.
Installs Drupal with the installation profile specified in \Drupal\simpletest\WebTestBase::$profile into the prefixed database.
Afterwards, installs any additional modules specified in the static \Drupal\simpletest\WebTestBase::$modules property of each class in the class hierarchy.
After installation all caches are flushed and several configuration values are reset to the values of the parent site executing the test, since the default values may be incompatible with the environment in which tests are being executed.
Overrides NodeTestBase::setUp
File
- core/
modules/ node/ src/ Tests/ NodeRevisionsTest.php, line 47 - Contains \Drupal\node\Tests\NodeRevisionsTest.
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\node\TestsCode
protected function setUp() {
parent::setUp();
ConfigurableLanguage::createFromLangcode('it')
->save();
$field_storage_definition = array(
'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 = array(
'field_storage' => $field_storage,
'bundle' => 'page',
);
$field = FieldConfig::create($field_definition);
$field
->save();
// Create and log in user.
$web_user = $this
->drupalCreateUser(array(
'view page revisions',
'revert page revisions',
'delete page revisions',
'edit any page content',
'delete any page content',
'translate any entity',
));
$this
->drupalLogin($web_user);
// Create initial node.
$node = $this
->drupalCreateNode();
$settings = get_object_vars($node);
$settings['revision'] = 1;
$settings['isDefaultRevision'] = TRUE;
$nodes = array();
$logs = array();
// 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 = array(
'value' => $this
->randomMachineName(32),
'format' => filter_default_format(),
);
$node->untranslatable_string_field->value = $this
->randomString();
$node
->setNewRevision();
// Edit the 2nd revision with a different user.
if ($i == 1) {
$editor = $this
->drupalCreateUser();
$node
->setRevisionAuthorId($editor
->id());
}
else {
$node
->setRevisionAuthorId($web_user
->id());
}
$node
->save();
$node = Node::load($node
->id());
// Make sure we get revision information.
$nodes[] = clone $node;
}
$this->nodes = $nodes;
$this->revisionLogs = $logs;
}