You are here

public function ContentTmgmtEntitySourceUiTest::testEntitySourceAnonymousAccess in Translation Management Tool 8

Test content entity source anonymous access.

File

sources/content/tests/src/Functional/ContentTmgmtEntitySourceUiTest.php, line 913

Class

ContentTmgmtEntitySourceUiTest
Content entity source UI tests.

Namespace

Drupal\Tests\tmgmt_content\Functional

Code

public function testEntitySourceAnonymousAccess() {

  // Create translatable node.
  $node = $this
    ->createTranslatableNode('page', 'en');
  $job = $this
    ->createJob('en', 'de');
  $job->translator = $this->default_translator
    ->id();
  $job
    ->save();
  $job_item = tmgmt_job_item_create('content', $node
    ->getEntityTypeId(), $node
    ->id(), array(
    'tjid' => $job
      ->id(),
  ));
  $job_item
    ->save();

  // Anonymous view of content entities.
  $node
    ->setUnpublished();
  $node
    ->save();
  $this
    ->drupalLogout();
  $url = $job_item
    ->getSourceUrl();
  $this
    ->drupalGet($url);
  $this
    ->assertResponse(200);
  \Drupal::configFactory()
    ->getEditable('tmgmt.settings')
    ->set('anonymous_access', FALSE)
    ->save();
  $this
    ->drupalGet($url);
  $this
    ->assertResponse(403);
  \Drupal::configFactory()
    ->getEditable('tmgmt.settings')
    ->set('anonymous_access', TRUE)
    ->save();
  $this
    ->drupalGet($url);
  $this
    ->assertResponse(200);
  $job
    ->aborted();
  $this
    ->drupalGet($url);
  $this
    ->assertResponse(403);
}