From ac93d2e733c5c92b7e67497001a73a8611262ae1 Mon Sep 17 00:00:00 2001 From: qadan Date: Mon, 17 Aug 2020 16:01:23 -0300 Subject: [PATCH] update tests --- islandora.routing.yml | 2 +- tests/src/Functional/DeleteMediaTest.php | 48 ++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/islandora.routing.yml b/islandora.routing.yml index 5738a0a8a..5ca9e3485 100644 --- a/islandora.routing.yml +++ b/islandora.routing.yml @@ -63,5 +63,5 @@ islandora.confirm_delete_media_and_file: defaults: _form: 'Drupal\islandora\Form\ConfirmDeleteMediaAndFile' requirements: - _permission: 'delete media' + _permission: 'administer media+delete any media' diff --git a/tests/src/Functional/DeleteMediaTest.php b/tests/src/Functional/DeleteMediaTest.php index 031921946..6236dbb65 100644 --- a/tests/src/Functional/DeleteMediaTest.php +++ b/tests/src/Functional/DeleteMediaTest.php @@ -2,6 +2,8 @@ namespace Drupal\Tests\islandora\Functional; +use Drupal\views\Views; + /** * Tests the DeleteMedia and DeleteMediaAndFile actions. * @@ -9,6 +11,18 @@ */ class DeleteMediaTest extends IslandoraFunctionalTestBase { + /** + * Modules to be enabled. + * + * @var array + */ + public static $modules = [ + 'media_test_views', + 'context_ui', + 'field_ui', + 'islandora', + ]; + /** * Media. * @@ -23,6 +37,13 @@ class DeleteMediaTest extends IslandoraFunctionalTestBase { */ protected $file; + /** + * User account. + * + * @var \Drupal\Core\Session\AccountInterface; + */ + protected $account; + /** * {@inheritdoc} */ @@ -30,9 +51,9 @@ public function setUp() { parent::setUp(); // Create a test user. - $account = $this->createUser(['create media']); + $this->account = $this->createUser(['create media', 'delete any media']); - list($this->file, $this->media) = $this->makeMediaAndFile($account); + list($this->file, $this->media) = $this->makeMediaAndFile($this->account); } /** @@ -41,12 +62,31 @@ public function setUp() { * @covers \Drupal\islandora\Plugin\Action\DeleteMediaAndFile::execute */ public function testDeleteMediaAndFile() { - $action = $this->container->get('entity_type.manager')->getStorage('action')->load('delete_media_and_file'); + $this->drupalLogin($this->account); + $session = $this->getSession(); + $page = $session->getPage(); $mid = $this->media->id(); $fid = $this->file->id(); - $action->execute([$this->media]); + // 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.