You are here

public function AutoEntityLabelBatchTest::testBatchProcess in Automatic Entity Label 8.3

Tests that re-save batch works correctly.

File

tests/src/FunctionalJavascript/AutoEntityLabelBatchTest.php, line 81

Class

AutoEntityLabelBatchTest
Tests batch operations on re-save.

Namespace

Drupal\Tests\auto_entitylabel\FunctionalJavascript

Code

public function testBatchProcess() {
  $webAssert = $this
    ->assertSession();
  $this
    ->createTestNodes(10, 'page');
  $pagesIDs = $this->nodeStorage
    ->getQuery()
    ->condition('type', 'page')
    ->execute();
  foreach ($this->nodeStorage
    ->loadMultiple($pagesIDs) as $index => $page) {
    $this
      ->assertEquals('Testing node page ' . ($index - 1), $page
      ->get('title')->value);
    $page
      ->save();
  }
  $this->configFactory
    ->getEditable("auto_entitylabel.settings.node.{$this->nodeType->id()}")
    ->set('status', 1)
    ->set('pattern', 'Test node [current-user:account-name]')
    ->save();
  $this
    ->drupalGet('/admin/structure/types/manage/page/auto-label');
  $webAssert
    ->pageTextContains('AUTOMATIC LABEL GENERATION FOR');
  $webAssert
    ->fieldExists('status');
  $webAssert
    ->fieldExists('pattern');
  $webAssert
    ->fieldExists('save');
  $webAssert
    ->fieldExists('chunk');
  $edit = [
    'save' => TRUE,
    'chunk' => 5,
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Save configuration');
  $webAssert
    ->assertWaitOnAjaxRequest();
  $webAssert
    ->pageTextContains('The configuration options have been saved.');
  $webAssert
    ->pageTextContains('Resaved 10 labels.');
  foreach ($this->nodeStorage
    ->loadMultiple($pagesIDs) as $page) {
    $this
      ->assertEquals('Test node ' . $this->user
      ->getAccountName(), $page
      ->get('title')->value);
  }
}