You are here

public function FeedListBuilderTest::testUiWithOnlyImportPermissions in Feeds 8.3

Tests the feed listing page for an user who may only import feeds.

File

tests/src/Functional/FeedListBuilderTest.php, line 170

Class

FeedListBuilderTest
Tests the feed listing page.

Namespace

Drupal\Tests\feeds\Functional

Code

public function testUiWithOnlyImportPermissions() {

  // Add two feed types.
  $feed_type_1 = $this
    ->createFeedType();
  $feed_type_2 = $this
    ->createFeedType();

  // Add two feeds.
  $this
    ->createFeed($feed_type_1
    ->id(), [
    'title' => 'My feed 1',
    'source' => $this
      ->resourcesUrl() . '/rss/googlenewstz.rss2',
  ]);
  $this
    ->createFeed($feed_type_2
    ->id(), [
    'title' => 'My feed 2',
    'source' => $this
      ->resourcesUrl() . '/rss/googlenewstz.rss2',
  ]);

  // Login as an user who may only import the first feed.
  $account = $this
    ->drupalCreateUser([
    'access feed overview',
    'import ' . $feed_type_1
      ->id() . ' feeds',
  ]);
  $this
    ->drupalLogin($account);

  // Go to the feed listing page.
  $this
    ->drupalGet('admin/content/feed');
  $session = $this
    ->assertSession();

  // Assert that there are no warnings nor errors displayed.
  $this
    ->assertNoWarnings();

  // Assert the first feed listed with the expected links.
  $session
    ->pageTextContains('My feed 1');
  $session
    ->linkExists('Import');
  $session
    ->linkByHrefExists('/feed/1/import');
  $session
    ->linkNotExists('My feed 1');

  // Assert that the second feed is *not* listed.
  $session
    ->pageTextNotContains('My feed 2');
  $session
    ->linkByHrefNotExists('/feed/2');
  $session
    ->linkByHrefNotExists('/feed/2/import');

  // Assert that the following links do *not* exist for both feeds.
  $session
    ->linkNotExists('Edit');
  $session
    ->linkByHrefNotExists('/feed/1/edit');
  $session
    ->linkByHrefNotExists('/feed/2/edit');
  $session
    ->linkNotExists('Import in background');
  $session
    ->linkByHrefNotExists('/feed/1/schedule-import');
  $session
    ->linkByHrefNotExists('/feed/2/schedule-import');
  $session
    ->linkNotExists('Delete items');
  $session
    ->linkByHrefNotExists('/feed/1/delete-items');
  $session
    ->linkByHrefNotExists('/feed/2/delete-items');
}