public function MediaBulkFormTest::testBulkForm in Drupal 10
Same name and namespace in other branches
- 8 core/modules/media/tests/src/Functional/MediaBulkFormTest.php \Drupal\Tests\media\Functional\MediaBulkFormTest::testBulkForm()
- 9 core/modules/media/tests/src/Functional/MediaBulkFormTest.php \Drupal\Tests\media\Functional\MediaBulkFormTest::testBulkForm()
Tests the media bulk form.
File
- core/
modules/ media/ tests/ src/ Functional/ MediaBulkFormTest.php, line 63
Class
- MediaBulkFormTest
- Tests a media bulk form.
Namespace
Drupal\Tests\media\FunctionalCode
public function testBulkForm() {
$session = $this
->getSession();
$page = $session
->getPage();
$assert_session = $this
->assertSession();
// Check that all created items are present in the test view.
$view = Views::getView('test_media_bulk_form');
$view
->execute();
$this
->assertSame($view->total_rows, 5);
// Check the operations are accessible to the logged in user.
$this
->drupalGet('test-media-bulk-form');
// Current available actions: Delete, Save, Publish, Unpublish.
$available_actions = [
'media_delete_action',
'media_publish_action',
'media_save_action',
'media_unpublish_action',
];
foreach ($available_actions as $action_name) {
$assert_session
->optionExists('action', $action_name);
}
// Test unpublishing in bulk.
$page
->checkField('media_bulk_form[0]');
$page
->checkField('media_bulk_form[1]');
$page
->checkField('media_bulk_form[2]');
$page
->selectFieldOption('action', 'media_unpublish_action');
$page
->pressButton('Apply to selected items');
$assert_session
->pageTextContains('Unpublish media was applied to 3 items');
$this
->assertFalse($this->storage
->loadUnchanged(1)
->isPublished(), 'The unpublish action failed in some of the media items.');
$this
->assertFalse($this->storage
->loadUnchanged(2)
->isPublished(), 'The unpublish action failed in some of the media items.');
$this
->assertFalse($this->storage
->loadUnchanged(3)
->isPublished(), 'The unpublish action failed in some of the media items.');
// Test publishing in bulk.
$page
->checkField('media_bulk_form[0]');
$page
->checkField('media_bulk_form[1]');
$page
->selectFieldOption('action', 'media_publish_action');
$page
->pressButton('Apply to selected items');
$assert_session
->pageTextContains('Publish media was applied to 2 items');
$this
->assertTrue($this->storage
->loadUnchanged(1)
->isPublished(), 'The publish action failed in some of the media items.');
$this
->assertTrue($this->storage
->loadUnchanged(2)
->isPublished(), 'The publish action failed in some of the media items.');
// Test deletion in bulk.
$page
->checkField('media_bulk_form[0]');
$page
->checkField('media_bulk_form[1]');
$page
->selectFieldOption('action', 'media_delete_action');
$page
->pressButton('Apply to selected items');
$assert_session
->pageTextContains('Are you sure you want to delete these media items?');
$page
->pressButton('Delete');
$assert_session
->pageTextContains('Deleted 2 items.');
$this
->assertNull($this->storage
->loadUnchanged(1), 'Could not delete some of the media items.');
$this
->assertNull($this->storage
->loadUnchanged(2), 'Could not delete some of the media items.');
}