You are here

function DefaultViewsTest::testDefaultViews in Zircon Profile 8

Same name in this branch
  1. 8 core/modules/views/src/Tests/DefaultViewsTest.php \Drupal\views\Tests\DefaultViewsTest::testDefaultViews()
  2. 8 core/modules/views_ui/src/Tests/DefaultViewsTest.php \Drupal\views_ui\Tests\DefaultViewsTest::testDefaultViews()
Same name and namespace in other branches
  1. 8.0 core/modules/views_ui/src/Tests/DefaultViewsTest.php \Drupal\views_ui\Tests\DefaultViewsTest::testDefaultViews()

Tests default views.

File

core/modules/views_ui/src/Tests/DefaultViewsTest.php, line 38
Contains \Drupal\views_ui\Tests\DefaultViewsTest.

Class

DefaultViewsTest
Tests enabling, disabling, and reverting default views via the listing page.

Namespace

Drupal\views_ui\Tests

Code

function testDefaultViews() {

  // Make sure the view starts off as disabled (does not appear on the listing
  // page).
  $edit_href = 'admin/structure/views/view/glossary';
  $this
    ->drupalGet('admin/structure/views');

  // @todo Disabled default views do now appear on the front page. Test this
  // behavior with templates instead.
  // $this->assertNoLinkByHref($edit_href);
  // Enable the view, and make sure it is now visible on the main listing
  // page.
  $this
    ->drupalGet('admin/structure/views');
  $this
    ->clickViewsOperationLink(t('Enable'), '/glossary/');
  $this
    ->assertUrl('admin/structure/views');
  $this
    ->assertLinkByHref($edit_href);

  // It should not be possible to revert the view yet.
  // @todo Figure out how to handle this with the new configuration system.
  // $this->assertNoLink(t('Revert'));
  // $revert_href = 'admin/structure/views/view/glossary/revert';
  // $this->assertNoLinkByHref($revert_href);
  // Edit the view and change the title. Make sure that the new title is
  // displayed.
  $new_title = $this
    ->randomMachineName(16);
  $edit = array(
    'title' => $new_title,
  );
  $this
    ->drupalPostForm('admin/structure/views/nojs/display/glossary/page_1/title', $edit, t('Apply'));
  $this
    ->drupalPostForm('admin/structure/views/view/glossary/edit/page_1', array(), t('Save'));
  $this
    ->drupalGet('glossary');
  $this
    ->assertResponse(200);
  $this
    ->assertText($new_title);

  // Save another view in the UI.
  $this
    ->drupalPostForm('admin/structure/views/nojs/display/archive/page_1/title', array(), t('Apply'));
  $this
    ->drupalPostForm('admin/structure/views/view/archive/edit/page_1', array(), t('Save'));

  // Check there is an enable link. i.e. The view has not been enabled after
  // editing.
  $this
    ->drupalGet('admin/structure/views');
  $this
    ->assertLinkByHref('admin/structure/views/view/archive/enable');

  // Enable it again so it can be tested for access permissions.
  $this
    ->clickViewsOperationLink(t('Enable'), '/archive/');

  // It should now be possible to revert the view. Do that, and make sure the
  // view title we added above no longer is displayed.
  // $this->drupalGet('admin/structure/views');
  // $this->assertLink(t('Revert'));
  // $this->assertLinkByHref($revert_href);
  // $this->drupalPostForm($revert_href, array(), t('Revert'));
  // $this->drupalGet('glossary');
  // $this->assertNoText($new_title);
  // Duplicate the view and check that the normal schema of duplicated views is used.
  $this
    ->drupalGet('admin/structure/views');
  $this
    ->clickViewsOperationLink(t('Duplicate'), '/glossary');
  $edit = array(
    'id' => 'duplicate_of_glossary',
  );
  $this
    ->assertTitle(t('Duplicate of @label | @site-name', array(
    '@label' => 'Glossary',
    '@site-name' => $this
      ->config('system.site')
      ->get('name'),
  )));
  $this
    ->drupalPostForm(NULL, $edit, t('Duplicate'));
  $this
    ->assertUrl('admin/structure/views/view/duplicate_of_glossary', array(), 'The normal duplicating name schema is applied.');

  // Duplicate a view and set a custom name.
  $this
    ->drupalGet('admin/structure/views');
  $this
    ->clickViewsOperationLink(t('Duplicate'), '/glossary');
  $random_name = strtolower($this
    ->randomMachineName());
  $this
    ->drupalPostForm(NULL, array(
    'id' => $random_name,
  ), t('Duplicate'));
  $this
    ->assertUrl("admin/structure/views/view/{$random_name}", array(), 'The custom view name got saved.');

  // Now disable the view, and make sure it stops appearing on the main view
  // listing page but instead goes back to displaying on the disabled views
  // listing page.
  // @todo Test this behavior with templates instead.
  $this
    ->drupalGet('admin/structure/views');
  $this
    ->clickViewsOperationLink(t('Disable'), '/glossary/');

  // $this->assertUrl('admin/structure/views');
  // $this->assertNoLinkByHref($edit_href);
  // The easiest way to verify it appears on the disabled views listing page
  // is to try to click the "enable" link from there again.
  $this
    ->drupalGet('admin/structure/views');
  $this
    ->clickViewsOperationLink(t('Enable'), '/glossary/');
  $this
    ->assertUrl('admin/structure/views');
  $this
    ->assertLinkByHref($edit_href);

  // Clear permissions for anonymous users to check access for default views.
  Role::load(RoleInterface::ANONYMOUS_ID)
    ->revokePermission('access content')
    ->save();

  // Test the default views disclose no data by default.
  $this
    ->drupalLogout();
  $this
    ->drupalGet('glossary');
  $this
    ->assertResponse(403);
  $this
    ->drupalGet('archive');
  $this
    ->assertResponse(403);

  // Test deleting a view.
  $this
    ->drupalLogin($this->fullAdminUser);
  $this
    ->drupalGet('admin/structure/views');
  $this
    ->clickViewsOperationLink(t('Delete'), '/glossary/');

  // Submit the confirmation form.
  $this
    ->drupalPostForm(NULL, array(), t('Delete'));

  // Ensure the view is no longer listed.
  $this
    ->assertUrl('admin/structure/views');
  $this
    ->assertNoLinkByHref($edit_href);

  // Ensure the view is no longer available.
  $this
    ->drupalGet($edit_href);
  $this
    ->assertResponse(404);
  $this
    ->assertText('Page not found');
}