You are here

public function ViewModeToggleTest::testFbiaViewModeToggle in Facebook Instant Articles 3.x

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/ViewModeToggleTest.php \Drupal\Tests\fb_instant_articles\Functional\ViewModeToggleTest::testFbiaViewModeToggle()

Test the FBIA view mode toggle.

File

tests/src/Functional/ViewModeToggleTest.php, line 95

Class

ViewModeToggleTest
Tests the view mode toggle functionality.

Namespace

Drupal\Tests\fb_instant_articles\Functional

Code

public function testFbiaViewModeToggle() {

  // Login as an admin user.
  $this->adminUser = $this
    ->drupalCreateUser($this->permissions);
  $this
    ->drupalLogin($this->adminUser);

  // Check that the FBIA view mode is available.
  $view_modes_url = Url::fromRoute('entity.entity_view_mode.collection')
    ->toString();
  $this
    ->drupalGet($view_modes_url);
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextContains('Facebook Instant Articles');

  // Enable FBIA display on article content.
  $article_url = Url::fromRoute('entity.node_type.edit_form', [
    'node_type' => 'article',
  ])
    ->toString();
  $this
    ->drupalGet($article_url);
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $edit = [
    'fb_instant_articles_enabled' => '1',
  ];
  $this
    ->submitForm($edit, t('Save content type'));

  // Check that the FBIA view mode has been turned on.
  $article_display_url = Url::fromRoute('entity.entity_view_display.node.default', [
    'node_type' => 'article',
  ])
    ->toString();
  $this
    ->drupalGet($article_display_url);
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->checkboxChecked('edit-display-modes-custom-fb-instant-articles');

  // Check that the additional regions show up on the Manage Display UI.
  $article_display_url = Url::fromRoute('entity.entity_view_display.node.view_mode', [
    'node_type' => 'article',
    'view_mode_name' => 'fb_instant_articles',
  ])
    ->toString();
  $this
    ->drupalGet($article_display_url);
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextContains('Header');
  $this
    ->assertSession()
    ->pageTextContains('Body');
  $this
    ->assertSession()
    ->pageTextContains('Footer');
  $this
    ->assertSession()
    ->pageTextContains('No fields are displayed in this region.');
  $edit = [
    'fields[' . $this->testField . '][region]' => 'content',
  ];
  $this
    ->submitForm($edit, t('Save'));
  $this
    ->assertSession()
    ->fieldValueEquals('fields[' . $this->testField . '][region]', 'content');

  // Disable the FBIA view mode.
  $article_url = Url::fromRoute('entity.node_type.edit_form', [
    'node_type' => 'article',
  ])
    ->toString();
  $this
    ->drupalGet($article_url);
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $edit = [
    'fb_instant_articles_enabled' => '0',
  ];
  $this
    ->submitForm($edit, t('Save content type'));

  // Check that the FBIA view mode has been turned off.
  $article_display_url = Url::fromRoute('entity.entity_view_display.node.default', [
    'node_type' => 'article',
  ])
    ->toString();
  $this
    ->drupalGet($article_display_url);
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->checkboxNotChecked('edit-display-modes-custom-fb-instant-articles');
}