You are here

public function AttributeTest::testAttributeUiProductAdjustments in Ubercart 8.4

Tests the "product adjustments" page.

File

uc_attribute/tests/src/Functional/AttributeTest.php, line 773

Class

AttributeTest
Tests the product attribute API.

Namespace

Drupal\Tests\uc_attribute\Functional

Code

public function testAttributeUiProductAdjustments() {

  /** @var \Drupal\Tests\WebAssert $assert */
  $assert = $this
    ->assertSession();
  $product = $this
    ->createProduct();
  $attribute = $this
    ->createAttribute([
    'display' => 1,
  ]);
  for ($i = 0; $i < 3; $i++) {
    $option = $this
      ->createAttributeOption([
      'aid' => $attribute->aid,
    ]);
    $adjustment = $this
      ->createProductAdjustment([
      'combination' => serialize([
        $attribute->aid => $option->oid,
      ]),
      'nid' => $product
        ->id(),
    ]);
    $option->model = $adjustment->model;
    $attribute->options[$option->oid] = $option;
  }
  uc_attribute_subject_save($attribute, 'product', $product
    ->id(), TRUE);
  $this
    ->drupalGet('node/' . $product
    ->id() . '/edit/adjustments');

  // Check for default product SKU.
  $assert
    ->pageTextContains('Default product SKU: ' . $product->model->value);

  // Verify attribute name, option name(s), and option SKU(s) are found.
  $assert
    ->responseContains('<th>' . $attribute->name . '</th>');
  foreach ($attribute->options as $option) {
    $assert
      ->responseContains('<td>' . $option->name . '</td>');
    $assert
      ->responseContains($option->model);
  }
}