protected function BulkFormTest::setUp in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/node/src/Tests/Views/BulkFormTest.php \Drupal\node\Tests\Views\BulkFormTest::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/ Views/ BulkFormTest.php, line 46 - Contains \Drupal\node\Tests\Views\BulkFormTest.
Class
- BulkFormTest
- Tests a node bulk form.
Namespace
Drupal\node\Tests\ViewsCode
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
ConfigurableLanguage::createFromLangcode('en-gb')
->save();
ConfigurableLanguage::createFromLangcode('it')
->save();
// Create some test nodes.
$this->nodes = [];
$langcodes = [
'en',
'en-gb',
'it',
];
for ($i = 1; $i <= 5; $i++) {
$langcode = $langcodes[($i - 1) % 3];
$values = [
'title' => $this
->randomMachineName() . ' [' . $i . ':' . $langcode . ']',
'langcode' => $langcode,
'promote' => FALSE,
];
$node = $this
->drupalCreateNode($values);
$this
->pass(SafeMarkup::format('Node %title created with language %langcode.', [
'%title' => $node
->label(),
'%langcode' => $node
->language()
->getId(),
]));
$this->nodes[] = $node;
}
// Create translations for all languages for some nodes.
for ($i = 0; $i < 2; $i++) {
$node = $this->nodes[$i];
foreach ($langcodes as $langcode) {
if (!$node
->hasTranslation($langcode)) {
$title = $this
->randomMachineName() . ' [' . $node
->id() . ':' . $langcode . ']';
$translation = $node
->addTranslation($langcode, [
'title' => $title,
'promote' => FALSE,
]);
$this
->pass(SafeMarkup::format('Translation %title created with language %langcode.', [
'%title' => $translation
->label(),
'%langcode' => $translation
->language()
->getId(),
]));
}
}
$node
->save();
}
// Create a node with only one translation.
$node = $this->nodes[2];
$langcode = 'en';
$title = $this
->randomMachineName() . ' [' . $node
->id() . ':' . $langcode . ']';
$translation = $node
->addTranslation($langcode, [
'title' => $title,
]);
$this
->pass(SafeMarkup::format('Translation %title created with language %langcode.', [
'%title' => $translation
->label(),
'%langcode' => $translation
->language()
->getId(),
]));
$node
->save();
// Check that all created translations are selected by the test view.
$view = Views::getView('test_node_bulk_form');
$view
->execute();
$this
->assertEqual(count($view->result), 10, 'All created translations are selected.');
// Check the operations are accessible to the logged in user.
$this
->drupalLogin($this
->drupalCreateUser(array(
'administer nodes',
'access content overview',
'bypass node access',
)));
$this
->drupalGet('test-node-bulk-form');
$elements = $this
->xpath('//select[@id="edit-action"]//option');
$this
->assertIdentical(count($elements), 8, 'All node operations are found.');
}