You are here

public function CatalogTest::testCatalog in Ubercart 8.4

Tests the catalog display and "buy it now" button.

File

uc_catalog/tests/src/Functional/CatalogTest.php, line 35

Class

CatalogTest
Tests for the Ubercart catalog.

Namespace

Drupal\Tests\uc_catalog\Functional

Code

public function testCatalog() {

  /** @var \Drupal\Tests\WebAssert $assert */
  $assert = $this
    ->assertSession();
  $this
    ->drupalLogin($this->adminUser);
  $term = $this
    ->createCatalogTerm();
  $product = $this
    ->createProduct([
    'taxonomy_catalog' => [
      $term
        ->id(),
    ],
  ]);
  $this
    ->drupalGet('catalog');
  $assert
    ->titleEquals('Catalog | Drupal');
  $assert
    ->linkExists($term
    ->label(), 0, 'The term is listed in the catalog.');
  $this
    ->clickLink($term
    ->label());
  $assert
    ->titleEquals($term
    ->label() . ' | Drupal');
  $assert
    ->linkExists($product
    ->label(), 0, 'The product is listed in the catalog.');

  // Check that the product SKU is shown in the catalog.
  $assert
    ->pageTextContains($product->model->value);

  // Check that the product price is shown in the catalog.
  $assert
    ->pageTextContains(uc_currency_format($product->price->value));
  $this
    ->submitForm([], 'Add to cart');
  $assert
    ->pageTextContains($product
    ->label() . ' added to your shopping cart.');
}