function BulkFormTest::testBulkForm
Same name in this branch
- 11.x core/modules/views/tests/src/Functional/BulkFormTest.php \Drupal\Tests\views\Functional\BulkFormTest::testBulkForm()
- 11.x core/modules/user/tests/src/Functional/Views/BulkFormTest.php \Drupal\Tests\user\Functional\Views\BulkFormTest::testBulkForm()
Same name in other branches
- 9 core/modules/node/tests/src/Functional/Views/BulkFormTest.php \Drupal\Tests\node\Functional\Views\BulkFormTest::testBulkForm()
- 9 core/modules/views/tests/src/Functional/BulkFormTest.php \Drupal\Tests\views\Functional\BulkFormTest::testBulkForm()
- 9 core/modules/user/tests/src/Functional/Views/BulkFormTest.php \Drupal\Tests\user\Functional\Views\BulkFormTest::testBulkForm()
- 8.9.x core/modules/node/tests/src/Functional/Views/BulkFormTest.php \Drupal\Tests\node\Functional\Views\BulkFormTest::testBulkForm()
- 8.9.x core/modules/views/tests/src/Functional/BulkFormTest.php \Drupal\Tests\views\Functional\BulkFormTest::testBulkForm()
- 8.9.x core/modules/user/tests/src/Functional/Views/BulkFormTest.php \Drupal\Tests\user\Functional\Views\BulkFormTest::testBulkForm()
- 10 core/modules/node/tests/src/Functional/Views/BulkFormTest.php \Drupal\Tests\node\Functional\Views\BulkFormTest::testBulkForm()
- 10 core/modules/views/tests/src/Functional/BulkFormTest.php \Drupal\Tests\views\Functional\BulkFormTest::testBulkForm()
- 10 core/modules/user/tests/src/Functional/Views/BulkFormTest.php \Drupal\Tests\user\Functional\Views\BulkFormTest::testBulkForm()
Tests the node bulk form.
File
-
core/
modules/ node/ tests/ src/ Functional/ Views/ BulkFormTest.php, line 105
Class
- BulkFormTest
- Tests a node bulk form.
Namespace
Drupal\Tests\node\Functional\ViewsCode
public function testBulkForm() : void {
// Unpublish a node using the bulk form.
$node = reset($this->nodes);
$this->assertTrue($node->isPublished(), 'Node is initially published');
$this->assertTrue($node->getTranslation('en-gb')
->isPublished(), 'Node translation is published');
$this->assertTrue($node->getTranslation('it')
->isPublished(), 'Node translation is published');
$edit = [
'node_bulk_form[0]' => TRUE,
'action' => 'node_unpublish_action',
];
$this->submitForm($edit, 'Apply to selected items');
$node = $this->loadNode($node->id());
$this->assertFalse($node->isPublished(), 'Node has been unpublished');
$this->assertTrue($node->getTranslation('en-gb')
->isPublished(), 'Node translation has not been unpublished');
$this->assertTrue($node->getTranslation('it')
->isPublished(), 'Node translation has not been unpublished');
// Publish action.
$edit = [
'node_bulk_form[0]' => TRUE,
'action' => 'node_publish_action',
];
$this->submitForm($edit, 'Apply to selected items');
$node = $this->loadNode($node->id());
$this->assertTrue($node->isPublished(), 'Node has been published again');
// Make sticky action.
$this->assertFalse($node->isSticky(), 'Node is not sticky');
$this->assertFalse($node->getTranslation('en-gb')
->isSticky(), 'Node translation is not sticky');
$this->assertFalse($node->getTranslation('it')
->isSticky(), 'Node translation is not sticky');
$edit = [
'node_bulk_form[0]' => TRUE,
'action' => 'node_make_sticky_action',
];
$this->submitForm($edit, 'Apply to selected items');
$node = $this->loadNode($node->id());
$this->assertTrue($node->isSticky(), 'Node has been made sticky');
$this->assertFalse($node->getTranslation('en-gb')
->isSticky(), 'Node translation has not been made sticky');
$this->assertFalse($node->getTranslation('it')
->isSticky(), 'Node translation has not been made sticky');
// Make unsticky action.
$edit = [
'node_bulk_form[0]' => TRUE,
'action' => 'node_make_unsticky_action',
];
$this->submitForm($edit, 'Apply to selected items');
$node = $this->loadNode($node->id());
$this->assertFalse($node->isSticky(), 'Node is not sticky anymore');
// Promote to front page.
$this->assertFalse($node->isPromoted(), 'Node is not promoted to the front page');
$this->assertFalse($node->getTranslation('en-gb')
->isPromoted(), 'Node translation is not promoted to the front page');
$this->assertFalse($node->getTranslation('it')
->isPromoted(), 'Node translation is not promoted to the front page');
$edit = [
'node_bulk_form[0]' => TRUE,
'action' => 'node_promote_action',
];
$this->submitForm($edit, 'Apply to selected items');
$node = $this->loadNode($node->id());
$this->assertTrue($node->isPromoted(), 'Node has been promoted to the front page');
$this->assertFalse($node->getTranslation('en-gb')
->isPromoted(), 'Node translation has not been promoted to the front page');
$this->assertFalse($node->getTranslation('it')
->isPromoted(), 'Node translation has not been promoted to the front page');
// Demote from front page.
$edit = [
'node_bulk_form[0]' => TRUE,
'action' => 'node_unpromote_action',
];
$this->submitForm($edit, 'Apply to selected items');
$node = $this->loadNode($node->id());
$this->assertFalse($node->isPromoted(), 'Node has been demoted');
// Select a bunch of translated and untranslated nodes and check that
// operations are always applied to individual translations.
$edit = [
// Original and all translations.
// Node 1, English, original.
'node_bulk_form[0]' => TRUE,
// Node 1, British English.
'node_bulk_form[1]' => TRUE,
// Node 1, Italian.
'node_bulk_form[2]' => TRUE,
// Original and only one translation.
// Node 2, English.
'node_bulk_form[3]' => TRUE,
// Node 2, British English, original.
'node_bulk_form[4]' => TRUE,
// Node 2, Italian.
'node_bulk_form[5]' => FALSE,
// Only a single translation.
// Node 3, English.
'node_bulk_form[6]' => TRUE,
// Node 3, Italian, original.
'node_bulk_form[7]' => FALSE,
// Only a single untranslated node.
// Node 4, English, untranslated.
'node_bulk_form[8]' => TRUE,
// Node 5, British English, untranslated.
'node_bulk_form[9]' => FALSE,
'action' => 'node_unpublish_action',
];
$this->submitForm($edit, 'Apply to selected items');
$node = $this->loadNode(1);
$this->assertFalse($node->getTranslation('en')
->isPublished(), '1: English translation has been unpublished');
$this->assertFalse($node->getTranslation('en-gb')
->isPublished(), '1: British English translation has been unpublished');
$this->assertFalse($node->getTranslation('it')
->isPublished(), '1: Italian translation has been unpublished');
$node = $this->loadNode(2);
$this->assertFalse($node->getTranslation('en')
->isPublished(), '2: English translation has been unpublished');
$this->assertFalse($node->getTranslation('en-gb')
->isPublished(), '2: British English translation has been unpublished');
$this->assertTrue($node->getTranslation('it')
->isPublished(), '2: Italian translation has not been unpublished');
$node = $this->loadNode(3);
$this->assertFalse($node->getTranslation('en')
->isPublished(), '3: English translation has been unpublished');
$this->assertTrue($node->getTranslation('it')
->isPublished(), '3: Italian translation has not been unpublished');
$node = $this->loadNode(4);
$this->assertFalse($node->isPublished(), '4: Node has been unpublished');
$node = $this->loadNode(5);
$this->assertTrue($node->isPublished(), '5: Node has not been unpublished');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.