You are here

public function PriceListTest::testAdd in Commerce Pricelist 8.2

Tests adding a price list.

File

tests/src/Functional/PriceListTest.php, line 36

Class

PriceListTest
Tests the price list UI.

Namespace

Drupal\Tests\commerce_pricelist\Functional

Code

public function testAdd() {
  $this
    ->drupalGet(Url::fromRoute('entity.commerce_pricelist.collection')
    ->toString());
  $this
    ->clickLink('Add price list');
  $roles = $this->adminUser
    ->getRoles();
  $role = reset($roles);
  $this
    ->submitForm([
    'name[0][value]' => 'Black Friday 2018',
    'start_date[0][value][date]' => '2018-07-07',
    'start_date[0][value][time]' => '13:37:00',
    'customer_eligibility' => 'customer_roles',
    "customer_roles[{$role}]" => $role,
    // The customer should not be persisted due to the role being used.
    'customers[0][target_id]' => $this->adminUser
      ->label() . ' (' . $this->adminUser
      ->id() . ')',
  ], 'Save');
  $this
    ->assertSession()
    ->pageTextContains('Saved the Black Friday 2018 price list.');

  /** @var \Drupal\commerce_pricelist\Entity\PriceListInterface $price_list */
  $price_list = PriceList::load(1);
  $this
    ->assertEquals('Black Friday 2018', $price_list
    ->getName());
  $this
    ->assertEquals('2018-07-07 13:37:00', $price_list
    ->getStartDate()
    ->format('Y-m-d H:i:s'));
  $this
    ->assertEquals([
    $role,
  ], $price_list
    ->getCustomerRoles());
  $this
    ->assertEmpty($price_list
    ->getCustomers());
}