public function AttributeTest::testAttributeUiAddAttribute in Ubercart 8.4
Tests the "add attribute" user interface.
File
- uc_attribute/
tests/ src/ Functional/ AttributeTest.php, line 336
Class
- AttributeTest
- Tests the product attribute API.
Namespace
Drupal\Tests\uc_attribute\FunctionalCode
public function testAttributeUiAddAttribute() {
/** @var \Drupal\Tests\WebAssert $assert */
$assert = $this
->assertSession();
$this
->drupalGet('admin/store/products/attributes/add');
$assert
->pageTextContains('The name of the attribute used in administrative forms');
$edit = (array) $this
->createAttribute([], FALSE);
$this
->submitForm($edit, 'Submit');
if ($edit['display'] != 0) {
// We redirect to add options page ONLY for non-textfield attributes.
$assert
->pageTextContains('Options for ' . $edit['name']);
$assert
->pageTextContains('No options for this attribute have been added yet.');
}
else {
// For textfield attributes we redirect to attribute list.
// Check that the created attribute name and label appear.
$assert
->pageTextContains($edit['name']);
$assert
->pageTextContains($edit['label']);
}
$this
->drupalGet('admin/store/products/attributes');
// Verify name, label, 'required', ordering, and display fields.
$assert
->responseContains('<td>' . $edit['name'] . '</td>');
$assert
->responseContains('<td>' . $edit['label'] . '</td>');
$assert
->responseContains('<td>' . ($edit['required'] ? 'Yes' : 'No') . '</td>');
$assert
->responseContains('<td>' . $edit['ordering'] . '</td>');
$types = _uc_attribute_display_types();
$assert
->responseContains('<td>' . $types[$edit['display']] . '</td>');
$aid = \Drupal::database()
->query('SELECT aid FROM {uc_attributes} WHERE name = :name', [
':name' => $edit['name'],
])
->fetchField();
$this
->assertTrue($aid, 'Attribute was created.');
$attribute = uc_attribute_load($aid);
$fields_ok = TRUE;
foreach ($edit as $field => $value) {
if ($attribute->{$field} != $value) {
$this
->showVar($attribute);
$this
->showVar($edit);
$fields_ok = FALSE;
break;
}
}
$this
->assertTrue($fields_ok, 'Attribute created properly.');
}