You are here

NodeFormTest.php in Acquia Content Hub 8

File

tests/src/Functional/NodeFormTest.php
View source
<?php

namespace Drupal\Tests\acquia_contenthub\Functional;

use Drupal\Core\StringTranslation\StringTranslationTrait;

/**
 * Test Acquia Content Hub node form.
 *
 * @group acquia_contenthub
 */
class NodeFormTest extends ContentHubTestBase {
  use ContentHubEntityTrait;
  use StringTranslationTrait;

  /**
   * The sample article we generate.
   *
   * @var \Drupal\node\NodeInterface
   */
  private $article;

  /**
   * Configure content hub node form.
   */
  public function testNodeForm() {
    $this
      ->drupalLogin($this->adminUser);
    $this->article = $this
      ->drupalCreateNode([
      'type' => 'article',
    ]);

    // A normal node should not have Acquia Content Hub settings.
    $this
      ->drupalGet('node/' . $this->article
      ->id() . '/edit');
    $this
      ->assertSession()
      ->pageTextNotContains($this
      ->t('Acquia Content Hub settings'));

    // Convert the node into a Content Hub node.
    $this
      ->convertToContentHubEntity($this->article);

    // A Content Hub node should have Acquia Content Hub settings.
    // Form should have option, and default to "enabled".
    $node_edit_url = 'node/' . $this->article
      ->id() . '/edit';
    $this
      ->drupalGet($node_edit_url);
    $this
      ->assertSession()
      ->pageTextContains($this
      ->t('Acquia Content Hub settings'));
    $this
      ->assertSession()
      ->checkboxChecked('edit-acquia-contenthub-auto-update');

    // Disable automatic update.
    $edit = [];
    $edit['acquia_contenthub[auto_update]'] = FALSE;
    $this
      ->submitForm($edit, $this
      ->t('Save'));

    // Option should now set to "disabled".
    $this
      ->drupalGet($node_edit_url);
    $this
      ->assertSession()
      ->checkboxNotChecked('edit-acquia-contenthub-auto-update');
  }

  /**
   * Configure content hub node form, auto setting to "having local change".
   */
  public function testNodeFormIntroduceLocalChange() {
    $this
      ->drupalLogin($this->adminUser);
    $this->article = $this
      ->drupalCreateNode([
      'type' => 'article',
    ]);

    // Convert the node into a Content Hub node.
    $this
      ->convertToContentHubEntity($this->article);

    // A Content Hub node should have Acquia Content Hub settings.
    // Form should have option, and default to "enabled".
    $node_edit_url = 'node/' . $this->article
      ->id() . '/edit';
    $this
      ->drupalGet($node_edit_url);
    $this
      ->assertSession()
      ->pageTextNotContains($this
      ->t('This syndicated content has been modified locally, therefore it is no longer automatically synchronized to its original content.'));
    $this
      ->assertSession()
      ->checkboxChecked('edit-acquia-contenthub-auto-update');

    // Don't edit anything, save.
    $this
      ->submitForm([], $this
      ->t('Save'));

    // Option should still be set to "enabled".
    $this
      ->drupalGet($node_edit_url);
    $this
      ->assertSession()
      ->pageTextNotContains($this
      ->t('This syndicated content has been modified locally, therefore it is no longer automatically synchronized to its original content.'));
    $this
      ->assertSession()
      ->checkboxChecked('edit-acquia-contenthub-auto-update');

    // Edit title.
    $edit = [];
    $edit['title[0][value]'] = 'my new title';
    $this
      ->submitForm($edit, $this
      ->t('Save'));

    // Option should now set to "disabled, as having local changes".
    $this
      ->drupalGet($node_edit_url);
    $this
      ->assertSession()
      ->pageTextContains($this
      ->t('This syndicated content has been modified locally, therefore it is no longer automatically synchronized to its original content.'));
    $this
      ->assertSession()
      ->checkboxNotChecked('edit-acquia-contenthub-auto-update');
  }

}

Classes

Namesort descending Description
NodeFormTest Test Acquia Content Hub node form.