Commit f9b3442b authored by zaporylie's avatar zaporylie Committed by mglaman

Issue #2998745 by zaporylie, mglaman: Take advantage of WebDriverTestBase to...

Issue #2998745 by zaporylie, mglaman: Take advantage of WebDriverTestBase to deprecated PhantomJS for Chrome
parent beb79ee7
......@@ -6,5 +6,5 @@ set -e $DRUPAL_TI_DEBUG
# Note: This function is re-entrant.
drupal_ti_ensure_drupal
# Turn on PhantomJS for functional Javascript tests
phantomjs --ssl-protocol=any --ignore-ssl-errors=true $DRUPAL_TI_DRUPAL_DIR/vendor/jcalderonzumba/gastonjs/src/Client/main.js 8510 1024 768 2>&1 >> /dev/null &
# Turn on chromdriver for functional Javascript tests
chromedriver > /dev/null 2>&1 &
......@@ -10,7 +10,10 @@ language: php
sudo: false
dist: precise
dist: trusty
addons:
chrome: stable
php:
- 7.2
......@@ -52,8 +55,8 @@ env:
- DRUPAL_TI_WEBSERVER_PORT="8080"
# Simpletest specific commandline arguments, the DRUPAL_TI_SIMPLETEST_GROUP is appended at the end.
- DRUPAL_TI_SIMPLETEST_ARGS="--verbose --color --concurrency 20 --url $DRUPAL_TI_WEBSERVER_URL:$DRUPAL_TI_WEBSERVER_PORT --types Simpletest,PHPUnit-Unit,PHPUnit-Kernel,PHPUnit-Functional --suppress-deprecations"
- DRUPAL_TI_SIMPLETEST_JS_ARGS="--verbose --color --concurrency 1 --url $DRUPAL_TI_WEBSERVER_URL:$DRUPAL_TI_WEBSERVER_PORT --types PHPUnit-FunctionalJavascript --suppress-deprecations"
- DRUPAL_TI_SIMPLETEST_ARGS="--verbose --color --concurrency 25 --url $DRUPAL_TI_WEBSERVER_URL:$DRUPAL_TI_WEBSERVER_PORT --types Simpletest,PHPUnit-Unit,PHPUnit-Kernel,PHPUnit-Functional --suppress-deprecations"
- DRUPAL_TI_SIMPLETEST_JS_ARGS="--verbose --color --concurrency 5 --url $DRUPAL_TI_WEBSERVER_URL:$DRUPAL_TI_WEBSERVER_PORT --types PHPUnit-FunctionalJavascript --suppress-deprecations"
# === Behat specific variables.
# This is relative to $TRAVIS_BUILD_DIR
......@@ -112,11 +115,16 @@ before_install:
install:
- drupal-ti install
- mkdir travis-phantomjs
- wget https://s3.amazonaws.com/travis-phantomjs/phantomjs-2.0.0-ubuntu-12.04.tar.bz2 -O $PWD/travis-phantomjs/phantomjs-2.0.0-ubuntu-12.04.tar.bz2
- tar -xvf $PWD/travis-phantomjs/phantomjs-2.0.0-ubuntu-12.04.tar.bz2 -C $PWD/travis-phantomjs
- export PATH=$PWD/travis-phantomjs:$PATH
- phantomjs --version
# Install Chromedriver.
- mkdir travis-chromedriver
- CHROMEDRIVER_VERSION=$(wget http://chromedriver.storage.googleapis.com/LATEST_RELEASE -qO-)
- wget http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip
- unzip chromedriver_linux64.zip -d travis-chromedriver && rm -f chromedriver_linux64.zip
- chmod a+x travis-chromedriver/chromedriver
- export PATH=$PWD/travis-chromedriver:$PATH
- chromedriver --version
# Installed after Drush to prevent Composer conflicts around symfony/yaml.
- composer global require "drupal/coder:8.3.*"
- phpcs --config-set installed_paths $HOME/.composer/vendor/drupal/coder/coder_sniffer
......
......@@ -2,14 +2,6 @@
namespace Drupal\Tests\commerce_cart\Functional;
use Drupal\commerce_order\Entity\OrderItemInterface;
use Drupal\commerce_product\Entity\ProductAttribute;
use Drupal\commerce_product\Entity\ProductInterface;
use Drupal\commerce_product\Entity\ProductVariationInterface;
use Drupal\commerce_product\Entity\ProductVariationTypeInterface;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Tests\commerce_order\Functional\OrderBrowserTestBase;
/**
......@@ -17,6 +9,8 @@ use Drupal\Tests\commerce_order\Functional\OrderBrowserTestBase;
*/
abstract class CartBrowserTestBase extends OrderBrowserTestBase {
use CartBrowserTestTrait;
/**
* The cart order to test against.
*
......@@ -71,159 +65,4 @@ abstract class CartBrowserTestBase extends OrderBrowserTestBase {
$this->attributeFieldManager = \Drupal::service('commerce_product.attribute_field_manager');
}
/**
* Posts the add to cart form for a product.
*
* @param \Drupal\commerce_product\Entity\ProductInterface $product
* The product.
* @param array $edit
* The form array.
*
* @throws \Exception
*/
protected function postAddToCart(ProductInterface $product, array $edit = []) {
$this->drupalGet('product/' . $product->id());
$this->assertSession()->buttonExists('Add to cart');
$this->submitForm($edit, 'Add to cart');
}
/**
* Asserts that an attribute option is selected.
*
* @param string $selector
* The element selector.
* @param string $option
* The option.
*/
protected function assertAttributeSelected($selector, $option) {
$selected_option = $this->getSession()->getPage()->find('css', 'select[name="' . $selector . '"] option[selected="selected"]')->getText();
$this->assertEquals($option, $selected_option);
}
/**
* Asserts that an attribute option does exist.
*
* @param string $selector
* The element selector.
* @param string $option
* The option.
*/
protected function assertAttributeExists($selector, $option) {
$this->assertSession()->elementExists('xpath', '//select[@name="' . $selector . '"]//option[@value="' . $option . '"]');
}
/**
* Asserts that an attribute option does not exist.
*
* @param string $selector
* The element selector.
* @param string $option
* The option.
*/
protected function assertAttributeDoesNotExist($selector, $option) {
$this->assertSession()->elementNotExists('xpath', '//select[@name="' . $selector . '"]//option[@value="' . $option . '"]');
}
/**
* Creates an attribute field and set of attribute values.
*
* @param \Drupal\commerce_product\Entity\ProductVariationTypeInterface $variation_type
* The variation type.
* @param string $name
* The attribute field name.
* @param array $options
* Associative array of key name values. [red => Red].
* @param bool $test_field
* Flag to create a test field on the attribute.
*
* @return \Drupal\commerce_product\Entity\ProductAttributeValueInterface[]
* Array of attribute entities.
*/
protected function createAttributeSet(ProductVariationTypeInterface $variation_type, $name, array $options, $test_field = FALSE) {
$attribute = ProductAttribute::create([
'id' => $name,
'label' => ucfirst($name),
]);
$attribute->save();
$this->attributeFieldManager->createField($attribute, $variation_type->id());
if ($test_field) {
$field_storage = FieldStorageConfig::loadByName('commerce_product_attribute_value', 'rendered_test');
if (!$field_storage) {
$field_storage = FieldStorageConfig::create([
'field_name' => 'rendered_test',
'entity_type' => 'commerce_product_attribute_value',
'type' => 'text',
]);
$field_storage->save();
}
FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => $attribute->id(),
])->save();
/** @var \Drupal\Core\Entity\Entity\EntityFormDisplay $attribute_view_display */
$attribute_view_display = EntityViewDisplay::create([
'targetEntityType' => 'commerce_product_attribute_value',
'bundle' => $name,
'mode' => 'add_to_cart',
'status' => TRUE,
]);
$attribute_view_display->removeComponent('name');
$attribute_view_display->setComponent('rendered_test', [
'label' => 'hidden',
'type' => 'string',
]);
$attribute_view_display->save();
}
$attribute_set = [];
foreach ($options as $key => $value) {
$attribute_set[$key] = $this->createAttributeValue($name, $value);
}
return $attribute_set;
}
/**
* Creates an attribute value.
*
* @param string $attribute
* The attribute ID.
* @param string $name
* The attribute value name.
*
* @return \Drupal\commerce_product\Entity\ProductAttributeValueInterface
* The attribute value entity.
*/
protected function createAttributeValue($attribute, $name) {
$attribute_value = $this->createEntity('commerce_product_attribute_value', [
'attribute' => $attribute,
'name' => $name,
]);
$attribute_value->save();
return $attribute_value;
}
/**
* Assert the order item in the order is correct.
*
* @param \Drupal\commerce_product\Entity\ProductVariationInterface $variation
* The purchased product variation.
* @param \Drupal\commerce_order\Entity\OrderItemInterface $order_item
* The order item.
* @param int $quantity
* The quantity.
*/
protected function assertOrderItemInOrder(ProductVariationInterface $variation, OrderItemInterface $order_item, $quantity = 1) {
$this->assertEquals($order_item->getTitle(), $variation->getOrderItemTitle());
$this->assertNotEmpty(($order_item->getQuantity() == $quantity), t('The product @product has been added to cart with quantity of @quantity.', [
'@product' => $order_item->getTitle(),
'@quantity' => $order_item->getQuantity(),
]));
}
}
<?php
namespace Drupal\Tests\commerce_cart\Functional;
use Drupal\commerce_order\Entity\OrderItemInterface;
use Drupal\commerce_product\Entity\ProductAttribute;
use Drupal\commerce_product\Entity\ProductInterface;
use Drupal\commerce_product\Entity\ProductVariationInterface;
use Drupal\commerce_product\Entity\ProductVariationTypeInterface;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Defines a trait for commerce_cart functional tests.
*/
trait CartBrowserTestTrait {
/**
* Posts the add to cart form for a product.
*
* @param \Drupal\commerce_product\Entity\ProductInterface $product
* The product.
* @param array $edit
* The form array.
*
* @throws \Exception
*/
protected function postAddToCart(ProductInterface $product, array $edit = []) {
$this->drupalGet('product/' . $product->id());
$this->assertSession()->buttonExists('Add to cart');
$this->submitForm($edit, 'Add to cart');
}
/**
* Asserts that an attribute option is selected.
*
* @param string $selector
* The element selector.
* @param string $option
* The option.
*/
protected function assertAttributeSelected($selector, $option) {
$selected_option = $this->getSession()->getPage()->find('css', 'select[name="' . $selector . '"] option[selected="selected"]')->getText();
$this->assertEquals($option, $selected_option);
}
/**
* Asserts that an attribute option does exist.
*
* @param string $selector
* The element selector.
* @param string $option
* The option.
*/
protected function assertAttributeExists($selector, $option) {
$this->assertSession()->elementExists('xpath', '//select[@name="' . $selector . '"]//option[@value="' . $option . '"]');
}
/**
* Asserts that an attribute option does not exist.
*
* @param string $selector
* The element selector.
* @param string $option
* The option.
*/
protected function assertAttributeDoesNotExist($selector, $option) {
$this->assertSession()->elementNotExists('xpath', '//select[@name="' . $selector . '"]//option[@value="' . $option . '"]');
}
/**
* Creates an attribute field and set of attribute values.
*
* @param \Drupal\commerce_product\Entity\ProductVariationTypeInterface $variation_type
* The variation type.
* @param string $name
* The attribute field name.
* @param array $options
* Associative array of key name values. [red => Red].
* @param bool $test_field
* Flag to create a test field on the attribute.
*
* @return \Drupal\commerce_product\Entity\ProductAttributeValueInterface[]
* Array of attribute entities.
*/
protected function createAttributeSet(ProductVariationTypeInterface $variation_type, $name, array $options, $test_field = FALSE) {
$attribute = ProductAttribute::create([
'id' => $name,
'label' => ucfirst($name),
]);
$attribute->save();
$this->attributeFieldManager->createField($attribute, $variation_type->id());
if ($test_field) {
$field_storage = FieldStorageConfig::loadByName('commerce_product_attribute_value', 'rendered_test');
if (!$field_storage) {
$field_storage = FieldStorageConfig::create([
'field_name' => 'rendered_test',
'entity_type' => 'commerce_product_attribute_value',
'type' => 'text',
]);
$field_storage->save();
}
FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => $attribute->id(),
])->save();
/** @var \Drupal\Core\Entity\Entity\EntityFormDisplay $attribute_view_display */
$attribute_view_display = EntityViewDisplay::create([
'targetEntityType' => 'commerce_product_attribute_value',
'bundle' => $name,
'mode' => 'add_to_cart',
'status' => TRUE,
]);
$attribute_view_display->removeComponent('name');
$attribute_view_display->setComponent('rendered_test', [
'label' => 'hidden',
'type' => 'string',
]);
$attribute_view_display->save();
}
$attribute_set = [];
foreach ($options as $key => $value) {
$attribute_set[$key] = $this->createAttributeValue($name, $value);
}
return $attribute_set;
}
/**
* Creates an attribute value.
*
* @param string $attribute
* The attribute ID.
* @param string $name
* The attribute value name.
*
* @return \Drupal\commerce_product\Entity\ProductAttributeValueInterface
* The attribute value entity.
*/
protected function createAttributeValue($attribute, $name) {
$attribute_value = $this->createEntity('commerce_product_attribute_value', [
'attribute' => $attribute,
'name' => $name,
]);
$attribute_value->save();
return $attribute_value;
}
/**
* Assert the order item in the order is correct.
*
* @param \Drupal\commerce_product\Entity\ProductVariationInterface $variation
* The purchased product variation.
* @param \Drupal\commerce_order\Entity\OrderItemInterface $order_item
* The order item.
* @param int $quantity
* The quantity.
*/
protected function assertOrderItemInOrder(ProductVariationInterface $variation, OrderItemInterface $order_item, $quantity = 1) {
$this->assertEquals($order_item->getTitle(), $variation->getOrderItemTitle());
$this->assertNotEmpty(($order_item->getQuantity() == $quantity), t('The product @product has been added to cart with quantity of @quantity.', [
'@product' => $order_item->getTitle(),
'@quantity' => $order_item->getQuantity(),
]));
}
}
......@@ -2,20 +2,16 @@
namespace Drupal\Tests\commerce_cart\FunctionalJavascript;
use Drupal\Tests\commerce\FunctionalJavascript\JavascriptTestTrait;
use Drupal\commerce_order\Entity\Order;
use Drupal\commerce_product\Entity\ProductVariation;
use Drupal\commerce_product\Entity\ProductVariationType;
use Drupal\Tests\commerce_cart\Functional\CartBrowserTestBase;
/**
* Tests the add to cart form.
*
* @group commerce
*/
class AddToCartMultiAttributeTest extends CartBrowserTestBase {
use JavascriptTestTrait;
class AddToCartMultiAttributeTest extends CartWebDriverTestBase {
/**
* {@inheritdoc}
......
......@@ -8,17 +8,13 @@ use Drupal\commerce_product\Entity\ProductVariation;
use Drupal\commerce_product\Entity\ProductVariationType;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\commerce\FunctionalJavascript\JavascriptTestTrait;
use Drupal\Tests\commerce_cart\Functional\CartBrowserTestBase;
/**
* Tests the add to cart form for multilingual.
*
* @group commerce
*/
class AddToCartMultilingualTest extends CartBrowserTestBase {
use JavascriptTestTrait;
class AddToCartMultilingualTest extends CartWebDriverTestBase {
/**
* The variations to test with.
......
......@@ -6,17 +6,13 @@ use Drupal\commerce_price\Entity\Currency;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Entity\Entity\EntityViewMode;
use Drupal\Tests\commerce\FunctionalJavascript\JavascriptTestTrait;
use Drupal\Tests\commerce_cart\Functional\CartBrowserTestBase;
/**
* Confirms that changing the product variation keeps the same view mode.
*
* @group commerce
*/
class AddToCartViewModeTest extends CartBrowserTestBase {
use JavascriptTestTrait;
class AddToCartViewModeTest extends CartWebDriverTestBase {
/**
* The first product variation.
......
<?php
namespace Drupal\Tests\commerce_cart\FunctionalJavascript;
use Drupal\Tests\commerce_cart\Functional\CartBrowserTestTrait;
use Drupal\Tests\commerce_order\FunctionalJavascript\OrderWebDriverTestBase;
/**
* Defines base class for commerce_cart test cases.
*/
abstract class CartWebDriverTestBase extends OrderWebDriverTestBase {
use CartBrowserTestTrait;
/**
* The cart order to test against.
*
* @var \Drupal\commerce_order\Entity\OrderInterface
*/
protected $cart;
/**
* The cart manager.
*
* @var \Drupal\commerce_cart\CartManagerInterface
*/
protected $cartManager;
/**
* The attribute field manager.
*
* @var \Drupal\commerce_product\ProductAttributeFieldManagerInterface
*/
protected $attributeFieldManager;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = [
'commerce_cart',
'commerce_cart_test',
'node',
'taxonomy',
];
/**
* {@inheritdoc}
*/
protected function getAdministratorPermissions() {
return array_merge([
'administer commerce_product',
'access content',
], parent::getAdministratorPermissions());
}
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->cart = \Drupal::service('commerce_cart.cart_provider')->createCart('default');
$this->cartManager = \Drupal::service('commerce_cart.cart_manager');
$this->attributeFieldManager = \Drupal::service('commerce_product.attribute_field_manager');
}
}
......@@ -5,17 +5,13 @@ namespace Drupal\Tests\commerce_cart\FunctionalJavascript;
use Drupal\commerce_order\Entity\Order;
use Drupal\commerce_product\Entity\ProductVariationType;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Tests\commerce\FunctionalJavascript\JavascriptTestTrait;
use Drupal\Tests\commerce_cart\Functional\CartBrowserTestBase;
/**
* Tests pages with multiple products rendered with add to cart forms.
*
* @group commerce
*/
class MultipleCartFormsTest extends CartBrowserTestBase {
use JavascriptTestTrait;
class MultipleCartFormsTest extends CartWebDriverTestBase {
/**
* Modules to enable.
......@@ -123,8 +119,6 @@ class MultipleCartFormsTest extends CartBrowserTestBase {
$this->assertFalse(in_array($form_id, $seen_ids));
$seen_ids[] = $form_id;
}
$this->assertSession()->responseHeaderNotEquals('BigPipe-Test-Placeholders', '<none>');
$this->assertSession()->responseHeaderEquals('BigPipe-Test-No-Js-Placeholders', '<none>');
$forms[1]->selectFieldOption('Size', 'Large');
$this->assertSession()->assertWaitOnAjaxRequest();
......
......@@ -6,8 +6,6 @@ use Drupal\commerce_order\Entity\Order;
use Drupal\commerce_product\Entity\ProductAttribute;
use Drupal\commerce_product\Entity\ProductType;
use Drupal\commerce_product\Entity\ProductVariationType;
use Drupal\Tests\commerce\FunctionalJavascript\JavascriptTestTrait;
use Drupal\Tests\commerce_cart\Functional\CartBrowserTestBase;
use Drupal\views\Entity\View;
/**
......@@ -17,9 +15,7 @@ use Drupal\views\Entity\View;
*
* @group commerce
*/
class MultipleCartMultipleVariationTypesTest extends CartBrowserTestBase {
use JavascriptTestTrait;
class MultipleCartMultipleVariationTypesTest extends CartWebDriverTestBase {
/**
* Modules to enable.
......
......@@ -3,17 +3,13 @@
namespace Drupal\Tests\commerce_order\FunctionalJavascript;
use Drupal\commerce_order\Entity\Order;
use Drupal\Tests\commerce\Functional\CommerceBrowserTestBase;
use Drupal\Tests\commerce\FunctionalJavascript\JavascriptTestTrait;
/**
* Tests the commerce_order reassign form.
*
* @group commerce
*/
class OrderReassignTest extends CommerceBrowserTestBase {
use JavascriptTestTrait;
class OrderReassignTest extends OrderWebDriverTestBase {
/**
* Modules to enable.
......
<?php
namespace Drupal\Tests\commerce_order\FunctionalJavascript;
use Drupal\Tests\commerce\FunctionalJavascript\CommerceWebDriverTestBase;
/**
* Defines base class for commerce_order test cases.
*/
abstract class OrderWebDriverTestBase extends CommerceWebDriverTestBase {
/**
* The variation to test against.
*
* @var \Drupal\commerce_product\Entity\ProductVariation
*/
protected $variation;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = [
'commerce_product',
'commerce_order',
'commerce_order_test',
'inline_entity_form',
];
/**
* {@inheritdoc}
*/
protected function getAdministratorPermissions() {
return array_merge([
'administer commerce_order',
'administer commerce_order_type',
'access commerce_order overview',
], parent::getAdministratorPermissions());
}
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Create a product variation.
$this->variation = $this->createEntity('commerce_product_variation', [
'type' => 'default',
'sku' => $this->randomMachineName(),
'price' => [
'number' => 999,
'currency_code' => 'USD',
],
]);
// We need a product too otherwise tests complain about the missing
// backreference.
$this->createEntity('commerce_product', [
'type' => 'default',
'title' => $this->randomMachineName(),
'stores' => [$this->store],
'variations' => [$this->variation],
]);
}
}
......@@ -8,17 +8,14 @@ use Drupal\commerce_order\Entity\Order;
use Drupal\commerce_payment\Entity\Payment;
use Drupal\commerce_payment\Entity\PaymentGateway;
use Drupal\commerce_price\Price;
use Drupal\Tests\commerce\Functional\CommerceBrowserTestBase;
use Drupal\Tests\commerce\FunctionalJavascript\JavascriptTestTrait;
use Drupal\Tests\commerce\FunctionalJavascript\CommerceWebDriverTestBase;
/**
* Tests the integration between payments and checkout.
*
* @group commerce
*/
class PaymentCheckoutTest extends CommerceBrowserTestBase {
use JavascriptTestTrait;
class PaymentCheckoutTest extends CommerceWebDriverTestBase {
/**
* The current user.
......
......@@ -2,16 +2,14 @@
namespace Drupal\Tests\commerce_price\FunctionalJavascript;
use Drupal\Tests\commerce\Functional\CommerceBrowserTestBase;
use Drupal\Tests\commerce\FunctionalJavascript\JavascriptTestTrait;
use Drupal\Tests\commerce\FunctionalJavascript\CommerceWebDriverTestBase;
/**