Browse Source

update tests

pull/792/head
qadan 4 years ago
parent
commit
65bea6b0e7
  1. 2
      islandora.routing.yml
  2. 48
      tests/src/Functional/DeleteMediaTest.php

2
islandora.routing.yml

@ -63,5 +63,5 @@ islandora.confirm_delete_media_and_file:
defaults: defaults:
_form: 'Drupal\islandora\Form\ConfirmDeleteMediaAndFile' _form: 'Drupal\islandora\Form\ConfirmDeleteMediaAndFile'
requirements: requirements:
_permission: 'delete media' _permission: 'administer media+delete any media'

48
tests/src/Functional/DeleteMediaTest.php

@ -2,6 +2,8 @@
namespace Drupal\Tests\islandora\Functional; namespace Drupal\Tests\islandora\Functional;
use Drupal\views\Views;
/** /**
* Tests the DeleteMedia and DeleteMediaAndFile actions. * Tests the DeleteMedia and DeleteMediaAndFile actions.
* *
@ -9,6 +11,18 @@ namespace Drupal\Tests\islandora\Functional;
*/ */
class DeleteMediaTest extends IslandoraFunctionalTestBase { class DeleteMediaTest extends IslandoraFunctionalTestBase {
/**
* Modules to be enabled.
*
* @var array
*/
public static $modules = [
'media_test_views',
'context_ui',
'field_ui',
'islandora',
];
/** /**
* Media. * Media.
* *
@ -23,6 +37,13 @@ class DeleteMediaTest extends IslandoraFunctionalTestBase {
*/ */
protected $file; protected $file;
/**
* User account.
*
* @var \Drupal\Core\Session\AccountInterface;
*/
protected $account;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -30,9 +51,9 @@ class DeleteMediaTest extends IslandoraFunctionalTestBase {
parent::setUp(); parent::setUp();
// Create a test user. // 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 @@ class DeleteMediaTest extends IslandoraFunctionalTestBase {
* @covers \Drupal\islandora\Plugin\Action\DeleteMediaAndFile::execute * @covers \Drupal\islandora\Plugin\Action\DeleteMediaAndFile::execute
*/ */
public function testDeleteMediaAndFile() { 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(); $mid = $this->media->id();
$fid = $this->file->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. // Attempt to reload the entities.
// Both media and file should be gone. // Both media and file should be gone.

Loading…
Cancel
Save