You are here

public function CatalogBlockTest::testCatalogBlock in Ubercart 8.4

Tests catalog block basic functionality.

File

uc_catalog/tests/src/Functional/CatalogBlockTest.php, line 48

Class

CatalogBlockTest
Tests the catalog block functionality.

Namespace

Drupal\Tests\uc_catalog\Functional

Code

public function testCatalogBlock() {

  /** @var \Drupal\Tests\WebAssert $assert */
  $assert = $this
    ->assertSession();

  // Confirm configuration defaults on the block settings page.
  $configuration = $this->block
    ->getPlugin()
    ->getConfiguration();
  $this
    ->assertFalse($configuration['link_title']);
  $this
    ->assertFalse($configuration['expanded']);
  $this
    ->assertTrue($configuration['product_count']);
  $this
    ->assertEquals(BlockPluginInterface::BLOCK_LABEL_VISIBLE, $configuration['label_display']);

  // Create a taxonomy term to use as a catalog category.
  $term = $this
    ->createCatalogTerm();

  // Create product and put it in this category.
  $product = $this
    ->createProduct([
    'taxonomy_catalog' => [
      $term
        ->id(),
    ],
  ]);

  // Test the catalog block with one product.
  $this
    ->drupalGet('');

  // If the block is present, we should see both
  // the block title and the term title.
  $assert
    ->pageTextContains($this->block
    ->label());
  $assert
    ->pageTextContains($term
    ->label());
  $assert
    ->linkExists($term
    ->label() . ' (1)', 0, 'The category is listed in the catalog block.');

  // Click through to catalog category page, verify product is there.
  $this
    ->clickLink($term
    ->label() . ' (1)');
  $assert
    ->titleEquals($term
    ->label() . ' | Drupal');
  $assert
    ->linkExists($product
    ->label(), 0, 'The product is listed in the catalog.');
}