function BulkFormTest::setUp

Same name in this branch
  1. 10 core/modules/views/tests/src/Functional/BulkFormTest.php \Drupal\Tests\views\Functional\BulkFormTest::setUp()
Same name in other branches
  1. 9 core/modules/node/tests/src/Functional/Views/BulkFormTest.php \Drupal\Tests\node\Functional\Views\BulkFormTest::setUp()
  2. 8.9.x core/modules/node/tests/src/Functional/Views/BulkFormTest.php \Drupal\Tests\node\Functional\Views\BulkFormTest::setUp()
  3. 11.x core/modules/node/tests/src/Functional/Views/BulkFormTest.php \Drupal\Tests\node\Functional\Views\BulkFormTest::setUp()
  4. 11.x core/modules/views/tests/src/Functional/BulkFormTest.php \Drupal\Tests\views\Functional\BulkFormTest::setUp()

Overrides NodeTestBase::setUp

File

core/modules/node/tests/src/Functional/Views/BulkFormTest.php, line 47

Class

BulkFormTest
Tests a node bulk form.

Namespace

Drupal\Tests\node\Functional\Views

Code

protected function setUp($import_test_views = TRUE, $modules = [
    'node_test_views',
]) : void {
    parent::setUp($import_test_views, $modules);
    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->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 . ']';
                $node->addTranslation($langcode, [
                    'title' => $title,
                    'promote' => FALSE,
                ]);
            }
        }
        $node->save();
    }
    // Create a node with only one translation.
    $node = $this->nodes[2];
    $langcode = 'en';
    $title = $this->randomMachineName() . ' [' . $node->id() . ':' . $langcode . ']';
    $node->addTranslation($langcode, [
        'title' => $title,
    ]);
    $node->save();
    // Check that all created translations are selected by the test view.
    $view = Views::getView('test_node_bulk_form');
    $view->execute();
    $this->assertCount(10, $view->result, 'All created translations are selected.');
    // Check the operations are accessible to the logged in user.
    $this->drupalLogin($this->drupalCreateUser([
        'administer nodes',
        'access content overview',
        'bypass node access',
    ]));
    $this->drupalGet('test-node-bulk-form');
    $elements = $this->assertSession()
        ->selectExists('edit-action')
        ->findAll('css', 'option');
    $this->assertCount(9, $elements, 'All node operations are found.');
}

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