You are here

public function NumberPatternTest::testResetSequence in Commerce Core 8.2

Tests resetting a number pattern's sequence.

File

modules/number_pattern/tests/src/FunctionalJavascript/NumberPatternTest.php, line 119

Class

NumberPatternTest
Tests the number pattern admin UI.

Namespace

Drupal\Tests\commerce_number_pattern\FunctionalJavascript

Code

public function testResetSequence() {
  $number_pattern = NumberPattern::create([
    'id' => 'foo',
    'label' => 'Foo',
    'targetEntityType' => 'entity_test_with_store',
    'plugin' => 'infinite',
    'configuration' => [
      'initial_number' => 1,
      'padding' => 2,
    ],
  ]);
  $number_pattern
    ->save();
  $entity = EntityTestWithStore::create([
    'store_id' => $this->store,
  ]);
  $entity
    ->save();
  $number = $number_pattern
    ->getPlugin()
    ->generate($entity);
  $this
    ->assertEquals(1, $number);
  $entity = EntityTestWithStore::create([
    'store_id' => $this->store,
  ]);
  $entity
    ->save();
  $number = $number_pattern
    ->getPlugin()
    ->generate($entity);
  $this
    ->assertEquals(2, $number);
  $this
    ->drupalGet($number_pattern
    ->toUrl('reset-sequence-form'));
  $this
    ->assertSession()
    ->pageTextContains(t('Are you sure you want to reset the sequence for the @type number pattern?', [
    '@type' => $number_pattern
      ->label(),
  ]));
  $this
    ->assertSession()
    ->pageTextContains('This action cannot be undone.');
  $this
    ->submitForm([], 'Reset sequence');
  $entity = EntityTestWithStore::create([
    'store_id' => $this->store,
  ]);
  $entity
    ->save();
  $number = $number_pattern
    ->getPlugin()
    ->generate($entity);
  $this
    ->assertEquals(1, $number);
}