= 10.1) { $permissions = ['create media', 'delete any media', 'delete any files']; } else { $permissions = ['create media', 'delete any media']; } // Create a test user. $this->account = $this->createUser($permissions); list($this->file, $this->media) = $this->makeMediaAndFile($this->account); } /** * Tests the delete_media_and_file action. * * @covers \Drupal\islandora\Plugin\Action\DeleteMediaAndFile::execute */ public function testDeleteMediaAndFile() { $this->drupalLogin($this->account); $session = $this->getSession(); $page = $session->getPage(); $mid = $this->media->id(); $fid = $this->file->id(); // Ensure the media is in the test view. $view = Views::getView('test_media_bulk_form'); $view->execute(); $this->assertSame($view->total_rows, 1); $this->drupalGet('test-media-bulk-form'); // Check that the option exists. $this->assertSession()->optionExists('action', 'delete_media_and_file'); // Run the bulk action. $page->checkField('media_bulk_form[0]'); $page->selectFieldOption('action', 'delete_media_and_file'); $page->pressButton('Apply to selected items'); $this->assertSession()->pageTextContains('Are you sure you want to delete this media and associated files?'); $page->pressButton('Delete'); // Should assert that a media and file were deleted. $this->assertSession()->pageTextContains('Deleted 2 items.'); // Attempt to reload the entities. // Both media and file should be gone. $this->assertTrue( !$this->container->get('entity_type.manager')->getStorage('media')->load($mid), "Media must be deleted after running action" ); $this->assertTrue( !$this->container->get('entity_type.manager')->getStorage('file')->load($fid), "File must be deleted after running action" ); } }