You are here

public function PreviewSettingsUpdateTest::testUpdatePath in Gatsby Live Preview & Incremental Builds 2.0.x

Same name and namespace in other branches
  1. 8 tests/src/Functional/PreviewSettingsUpdateTest.php \Drupal\Tests\gatsby\Functional\PreviewSettingsUpdateTest::testUpdatePath()

Tests update path.

File

tests/src/Functional/PreviewSettingsUpdateTest.php, line 37

Class

PreviewSettingsUpdateTest
Defines a class for testing the update path.

Namespace

Drupal\Tests\gatsby\Functional

Code

public function testUpdatePath() {
  $gatsby_settings = \Drupal::config('gatsby.settings');
  $preview_settings = $gatsby_settings
    ->get('preview');
  $target_settings = $gatsby_settings
    ->get('target');
  $iframe_settings = $gatsby_settings
    ->get('iframe');
  $this
    ->assertEquals([
    'article' => 1,
    'page' => 1,
  ], $preview_settings);
  $this
    ->assertEquals([
    'article' => 1,
    'page' => 0,
  ], $iframe_settings);
  $this
    ->assertEquals([
    'article' => 'window',
    'page' => 'sidebar',
  ], $target_settings);
  $this
    ->assertEquals('https://example.com', $gatsby_settings
    ->get('server_url'));
  $this
    ->assertEmpty($gatsby_settings
    ->get('preview_callback_url'));
  $this
    ->runUpdates();
  $gatsby_settings = \Drupal::config('gatsby.settings');
  $this
    ->assertEmpty($gatsby_settings
    ->get('preview'));
  $this
    ->assertEmpty($gatsby_settings
    ->get('target'));
  $this
    ->assertEmpty($gatsby_settings
    ->get('iframe'));

  /** @var \Drupal\node\NodeTypeInterface $page */
  $page = NodeType::load('page');
  $this
    ->assertTrue($page
    ->getThirdPartySetting('gatsby', 'preview'));
  $this
    ->assertEquals('sidebar', $page
    ->getThirdPartySetting('gatsby', 'target'));
  $this
    ->assertFalse($page
    ->getThirdPartySetting('gatsby', 'iframe'));

  /** @var \Drupal\node\NodeTypeInterface $article */
  $article = NodeType::load('article');
  $this
    ->assertTrue($article
    ->getThirdPartySetting('gatsby', 'preview'));
  $this
    ->assertEquals('window', $article
    ->getThirdPartySetting('gatsby', 'target'));
  $this
    ->assertTrue($article
    ->getThirdPartySetting('gatsby', 'iframe'));
  $this
    ->assertEquals('https://example.com/__refresh', $gatsby_settings
    ->get('preview_callback_url'));
}