View source
<?php
namespace Drupal\Tests\uc_catalog\Functional;
class CatalogTest extends CatalogTestBase {
protected static $modules = [
'history',
'uc_catalog',
'uc_attribute',
'field_ui',
];
protected static $adminPermissions = [
'administer catalog',
'administer node fields',
'administer taxonomy_term fields',
'view catalog',
];
public function testCatalog() {
$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.');
$assert
->pageTextContains($product->model->value);
$assert
->pageTextContains(uc_currency_format($product->price->value));
$this
->submitForm([], 'Add to cart');
$assert
->pageTextContains($product
->label() . ' added to your shopping cart.');
}
public function testCatalogAttribute() {
$assert = $this
->assertSession();
$this
->drupalLogin($this->adminUser);
$term = $this
->createCatalogTerm();
$product = $this
->createProduct([
'taxonomy_catalog' => [
$term
->id(),
],
]);
$attribute = $this
->createAttribute([
'display' => 0,
]);
uc_attribute_subject_save($attribute, 'product', $product
->id());
$this
->drupalGet('catalog/' . $term
->id());
$this
->submitForm([], 'Add to cart');
$assert
->pageTextNotContains($product
->label() . ' added to your shopping cart.');
$assert
->pageTextContains('This product has options that need to be selected before purchase. Please select them in the form below.');
}
public function testCatalogNode() {
$assert = $this
->assertSession();
$this
->drupalLogin($this->adminUser);
$term = $this
->createCatalogTerm();
$product = $this
->createProduct([
'taxonomy_catalog' => [
$term
->id(),
],
]);
$this
->drupalGet('node/' . $product
->id());
$assert
->linkExists($term
->label(), 0, 'The product links back to the catalog term.');
$assert
->linkByHrefExists('/catalog/' . $term
->id(), 0, 'The product links back to the catalog view.');
}
public function testCatalogField() {
$assert = $this
->assertSession();
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('admin/structure/taxonomy/manage/catalog/overview/fields');
$assert
->pageTextContains('uc_catalog_image');
$this
->drupalGet('admin/structure/types/manage/product/fields');
$assert
->pageTextContains('taxonomy_catalog');
$this
->drupalGet('node/add/product');
$assert
->fieldExists('taxonomy_catalog');
\Drupal::service('module_installer')
->install([
'uc_product_kit',
], FALSE);
$this
->drupalGet('admin/structure/types/manage/product_kit/fields');
$assert
->pageTextContains('taxonomy_catalog');
}
public function testCatalogRepair() {
$assert = $this
->assertSession();
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('admin/structure/types/manage/product/fields/node.product.taxonomy_catalog/delete');
$this
->submitForm([], 'Delete');
$assert
->pageTextContains('The field Catalog has been deleted from the Product content type.');
$this
->drupalGet('admin/structure/types/manage/product/fields');
$assert
->pageTextNotContains('taxonomy_catalog');
$this
->drupalGet('admin/store');
$assert
->pageTextContains('The catalog taxonomy reference field is missing.');
$this
->drupalGet('admin/store/config/catalog/repair');
$assert
->pageTextContains('The catalog taxonomy reference field has been repaired.');
$this
->drupalGet('admin/structure/types/manage/product/fields');
$assert
->pageTextContains('taxonomy_catalog');
}
}