Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
qadan committed Aug 18, 2020
1 parent bcbb452 commit ac93d2e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
2 changes: 1 addition & 1 deletion islandora.routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'

48 changes: 44 additions & 4 deletions tests/src/Functional/DeleteMediaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,27 @@

namespace Drupal\Tests\islandora\Functional;

use Drupal\views\Views;

/**
* Tests the DeleteMedia and DeleteMediaAndFile actions.
*
* @group islandora
*/
class DeleteMediaTest extends IslandoraFunctionalTestBase {

/**
* Modules to be enabled.
*
* @var array
*/
public static $modules = [
'media_test_views',
'context_ui',
'field_ui',
'islandora',
];

/**
* Media.
*
Expand All @@ -23,16 +37,23 @@ class DeleteMediaTest extends IslandoraFunctionalTestBase {
*/
protected $file;

/**
* User account.
*
* @var \Drupal\Core\Session\AccountInterface;
*/
protected $account;

/**
* {@inheritdoc}
*/
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);
}

/**
Expand All @@ -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.
Expand Down

0 comments on commit ac93d2e

Please sign in to comment.