You are here

public function IntegrationTest::testFramework in Acquia Content Hub 8

Tests various operations via the Acquia Content Hub admin UI.

File

tests/src/Functional/IntegrationTest.php, line 134

Class

IntegrationTest
Tests the overall functionality of the Acquia Content Hub module.

Namespace

Drupal\Tests\acquia_contenthub\Functional

Code

public function testFramework() {

  // Enable dumpHeaders when you are having caching issues.
  $this->dumpHeaders = TRUE;
  $this
    ->drupalLogin($this->adminUser);

  // Create sample content.
  $this
    ->createSampleContent();

  // Configure Acquia Content Hub for article nodes with view modes.
  $this
    ->configureContentHubContentTypes('node', [
    'article',
  ]);
  $this
    ->checkCdfOutput($this->article);

  // Check CDF access on published node.
  $this
    ->setRoleFor(AccountInterface::ANONYMOUS_ROLE);
  $this
    ->checkCdfAccess($this->article);
  $this
    ->checkCdfFormat($this->article);
  $this
    ->setRoleFor($this->limitedRole);
  $this
    ->checkCdfAccess($this->article);
  $this
    ->setRoleFor($this->adminRole);
  $this
    ->checkCdfAccess($this->article);

  // Check CDF access on unpublished node.
  $this
    ->setRoleFor(AccountInterface::ANONYMOUS_ROLE);
  $this
    ->checkCdfAccess($this->unpublishedArticle, FALSE);
  $this
    ->setRoleFor($this->limitedRole);
  $visible_roles = $this
    ->getUserWarningRole();
  $this
    ->assertFalse(array_key_exists($this->limitedRole, $visible_roles), 'The role warning message absent');
  $this
    ->checkCdfAccess($this->unpublishedArticle, FALSE);
  $this
    ->setRoleFor($this->adminRole);
  $visible_roles = $this
    ->getUserWarningRole();
  $this
    ->assertTrue(array_key_exists($this->adminRole, $visible_roles), 'The role warning message present');
  $this
    ->checkCdfAccess($this->unpublishedArticle);

  // Check if the test field presents in CDF attributes.
  $this
    ->setRoleFor(AccountInterface::ANONYMOUS_ROLE);
  $this
    ->checkCdfFieldAccess($this->article);
  $this
    ->setRoleFor(AccountInterface::ANONYMOUS_ROLE);
  $this
    ->checkCdfFieldAccess($this->article, FALSE, FALSE);
  $this
    ->setRoleFor($this->adminRole);
  $this
    ->checkCdfFieldAccess($this->article);
  $this
    ->setRoleFor($this->adminRole);
  $this
    ->checkCdfFieldAccess($this->article, FALSE, FALSE);

  // Access test cleanup.
  $this
    ->setRoleFor(AccountInterface::ANONYMOUS_ROLE);

  // Enable view-modes for article nodes.
  $this
    ->enableViewModeFor('node', 'article', 'teaser');
  $this
    ->checkCdfOutput($this->article, 'teaser');
  $this
    ->ConfigureAndUsePreviewImageStyle();

  // Access to view modes as admin should be allowed.
  $this
    ->checkAccessViewMode($this->article, 'teaser', TRUE);

  // Access to view modes on unpublished content as admin should be allowed.
  $this
    ->drupalGet("acquia-contenthub/display/node/{$this->unpublishedArticle->id()}/teaser");
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertNoText($this->unpublishedArticle
    ->label(), 'An unpublished content should not be rendered for admin user if anonymous role selected');

  // Check if the test field rendered properly.
  $this
    ->setRoleFor(AccountInterface::ANONYMOUS_ROLE);
  $this
    ->checkFieldAccessViewMode($this->article, 'teaser');
  $this
    ->checkCdfMarkup($this->article);
  $this
    ->setRoleFor(AccountInterface::ANONYMOUS_ROLE);
  $this
    ->checkFieldAccessViewMode($this->article, 'teaser', FALSE, FALSE);
  $this
    ->setRoleFor($this->adminRole);
  $this
    ->checkFieldAccessViewMode($this->article, 'teaser');
  $this
    ->setRoleFor($this->adminRole);
  $this
    ->checkFieldAccessViewMode($this->article, 'teaser', FALSE, FALSE);
  $this
    ->setRoleFor($this->adminRole);

  // Access to view modes as admin should be allowed.
  $this
    ->checkAccessViewMode($this->article, 'teaser', TRUE);

  // Access to view modes on unpublished content as admin should be allowed.
  $this
    ->checkAccessViewMode($this->unpublishedArticle, 'teaser', TRUE);
  $this
    ->drupalLogout();

  // Access to view modes as anonymous should be denied.
  $this
    ->checkAccessViewMode($this->article, 'teaser', FALSE);
  $this
    ->checkAccessViewMode($this->unpublishedArticle, 'teaser', FALSE);
}