public function ProductTest::testProductClassForm in Ubercart 8.4
Tests making node types into products.
File
- uc_product/
tests/ src/ Functional/ ProductTest.php, line 212
Class
- ProductTest
- Tests the product content type.
Namespace
Drupal\Tests\uc_product\FunctionalCode
public function testProductClassForm() {
/** @var \Drupal\Tests\WebAssert $assert */
$assert = $this
->assertSession();
// Try making a new product class.
$class = strtolower($this
->randomMachineName(12));
$edit = [
'type' => $class,
'name' => $class,
'description' => $this
->randomMachineName(32),
'uc_product[product]' => 1,
];
$this
->drupalGet('admin/structure/types/add');
$this
->submitForm($edit, 'Save content type');
$this
->assertTrue(uc_product_is_product($class), 'The new content type is a product class.');
// Make an existing node type a product class.
$type = $this
->drupalCreateContentType([
'description' => $this
->randomMachineName(),
]);
$edit = [
'uc_product[product]' => 1,
];
$this
->drupalGet('admin/structure/types/manage/' . $type
->getOriginalId());
$this
->submitForm($edit, 'Save content type');
$this
->assertTrue(uc_product_is_product($type
->getOriginalId()), 'The updated content type is a product class.');
// Check the product classes page.
$this
->drupalGet('admin/store/products/classes');
// Check the product class is listed.
$assert
->pageTextContains($type
->getOriginalId());
// Check the product class description is found in the list.
$assert
->pageTextContains($type
->getDescription());
// Check the product class edit link is shown.
$assert
->linkByHrefExists('admin/structure/types/manage/' . $type
->getOriginalId(), 0);
// Check the product class delete link is shown.
$assert
->linkByHrefExists('admin/structure/types/manage/' . $type
->getOriginalId() . '/delete', 0);
// Remove the product class again.
$edit = [
'uc_product[product]' => FALSE,
];
$this
->drupalGet('admin/structure/types/manage/' . $class);
$this
->submitForm($edit, 'Save content type');
$this
->assertFalse(uc_product_is_product($class), 'The updated content type is no longer a product class.');
}