You are here

public function ImportPartialFormTest::testImportPartialForm in Tome 8

Tests that the import partial form works.

File

modules/tome_sync/tests/src/Functional/ImportPartialFormTest.php, line 65

Class

ImportPartialFormTest
Tests that the import partial form works.

Namespace

Drupal\Tests\tome_sync\Functional

Code

public function testImportPartialForm() {

  /** @var \Drupal\tome_sync\JsonFileStorage $storage */
  $storage = \Drupal::service('tome_sync.storage.content');
  $node1 = $this
    ->createNode([
    'type' => 'article',
  ]);
  $node1_name = TomeSyncHelper::getContentName($node1);
  $node2 = $this
    ->createNode([
    'type' => 'article',
  ]);
  $node2_name = TomeSyncHelper::getContentName($node2);

  // Test initial state.
  $this
    ->drupalGet('/admin/config/tome/sync/import-partial');
  $assert_session = $this
    ->assertSession();
  $assert_session
    ->pageTextContains('Synchronize content and files');
  $assert_session
    ->pageTextContains('No content has been changed or deleted');

  // Delete content.
  $storage
    ->delete($node1_name);

  // Modify content.
  $content = $storage
    ->read($node2_name);
  $content['title'] = [
    'Foobar',
  ];
  $storage
    ->write($node2_name, $content);

  // Add content.
  $node3 = Node::create([
    'type' => 'article',
    'title' => 'My article',
    'uuid' => \Drupal::service('uuid')
      ->generate(),
  ]);
  $data = \Drupal::service('serializer')
    ->normalize($node3, 'json');
  $node3_name = TomeSyncHelper::getContentName($node3);
  $storage
    ->write($node3_name, $data);
  $this
    ->indexContent($node3);

  // Check that the page displays the correct information.
  $this
    ->drupalGet('/admin/config/tome/sync/import-partial');
  $assert_session
    ->pageTextNotContains('No content has been changed or deleted');
  $this
    ->assertStringContainsString($node1_name, $assert_session
    ->elementExists('css', '[data-drupal-selector="edit-deleted"]')
    ->getText());
  $this
    ->assertStringContainsString($node2_name, $assert_session
    ->elementExists('css', '[data-drupal-selector="edit-modified"]')
    ->getText());
  $this
    ->assertStringContainsString($node3_name, $assert_session
    ->elementExists('css', '[data-drupal-selector="edit-added"]')
    ->getText());

  // Submit the form and verify that changes were actually made.
  $this
    ->submitForm([], 'Submit');
  $assert_session
    ->pageTextContains('Import complete');
  $assert_session
    ->pageTextContains('No content has been changed or deleted');
}