Commit 1b54e445 authored by mglaman's avatar mglaman

Issue #2733759: Convert StoreTest to BrowserTest

parent 299c154f
......@@ -33,3 +33,6 @@ composer update -n --lock --verbose
# Enable main module and submodules.
drush en -y commerce commerce_product commerce_order commerce_checkout
# 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 &
......@@ -28,6 +28,7 @@ matrix:
env:
global:
- PHANTOMJS2_VERSION="2.0.0"
# add composer's global bin directory to the path
# see: https://github.com/drush-ops/drush#install---composer
- PATH="$PATH:$HOME/.composer/vendor/bin"
......@@ -113,6 +114,11 @@ 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
before_script:
- drupal-ti --include ".travis-before-script.sh"
......
<?php
namespace Drupal\commerce_store\Tests;
namespace Drupal\Tests\commerce_store\FunctionalJavascript;
use Drupal\commerce\Tests\CommerceTestBase;
use Drupal\commerce_store\Entity\Store;
use Drupal\commerce_store\StoreCreationTrait;
use Drupal\simpletest\BlockCreationTrait;
use Drupal\Tests\commerce\Functional\CommerceJavascriptTestBase;
/**
* Create, view, edit, delete, and change store entities.
*
* @group commerce
*/
class StoreTest extends CommerceTestBase {
class StoreTest extends CommerceJavascriptTestBase {
use BlockCreationTrait;
use StoreCreationTrait;
/**
......@@ -20,7 +22,7 @@ class StoreTest extends CommerceTestBase {
*
* @var array
*/
public static $modules = ['commerce_store'];
public static $modules = ['block', 'commerce_store'];
/**
* A store type entity to use in the tests.
......@@ -29,6 +31,16 @@ class StoreTest extends CommerceTestBase {
*/
protected $type;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->placeBlock('local_tasks_block');
$this->placeBlock('local_actions_block');
}
/**
* {@inheritdoc}
*/
......@@ -44,28 +56,26 @@ class StoreTest extends CommerceTestBase {
*/
public function testCreateStore() {
$this->drupalGet('admin/commerce/stores');
$this->clickLink('Add a new store');
$this->getSession()->getPage()->clickLink('Add a new store');
// Check the integrity of the form.
$this->assertFieldByName('name[0][value]', NULL, 'Name field is present.');
$this->assertFieldByName('mail[0][value]', NULL, 'Email field is present.');
$this->assertFieldByName('address[0][country_code]', NULL, 'Address field is present.');
$this->assertFieldByName('billing_countries[]', NULL, 'Supported billing countries field is present');
$this->assertFieldByName('uid[0][target_id]', NULL, 'Owner field is present');
$this->assertFieldByName('default', NULL, 'Default field is present');
$this->assertFieldsByValue(t('Save'), NULL, 'Save button is present');
$this->assertSession()->fieldExists('name[0][value]');
$this->assertSession()->fieldExists('mail[0][value]');
$this->assertSession()->fieldExists('address[0][country_code]');
$this->assertSession()->fieldExists('billing_countries[]');
$this->assertSession()->fieldExists('uid[0][target_id]');
$this->assertSession()->fieldExists('default');
$this->getSession()->getPage()->fillField('address[0][country_code]', 'US');
$this->getSession()->wait(4000, 'jQuery(\'select[name="address[0][administrative_area]"]\').length > 0 && jQuery.active == 0;');
$name = $this->randomMachineName(8);
$edit = [
'name[0][value]' => $this->randomMachineName(8),
'name[0][value]' => $name,
'mail[0][value]' => \Drupal::currentUser()->getEmail(),
'default_currency' => 'USD',
];
$address_country = [
'address[0][country_code]' => 'US',
];
$this->drupalPostAjaxForm(NULL, $address_country, 'address[0][country_code]');
$address = [
'country_code' => 'US',
'address_line1' => '1098 Alta Ave',
'locality' => 'Mountain View',
'administrative_area' => 'US-CA',
......@@ -75,10 +85,10 @@ class StoreTest extends CommerceTestBase {
$path = 'address[0][' . $property . ']';
$edit[$path] = $value;
}
$this->drupalPostForm(NULL, $edit, t('Save'));
$store_count = $this->cssSelect('.view-commerce-stores tr td.views-field-name');
$this->assertEqual(count($store_count), 1, 'Stores exists in the table.');
$this->submitForm($edit, t('Save'));
$this->assertSession()->pageTextContains("Saved the $name store.");
$store_count = $this->getSession()->getPage()->find('css', '.view-commerce-stores tr td.views-field-name');
$this->assertEquals(count($store_count), 1, 'Stores exists in the table.');
}
/**
......@@ -92,11 +102,11 @@ class StoreTest extends CommerceTestBase {
$edit = [
'name[0][value]' => $new_store_name,
];
$this->drupalPostForm(NULL, $edit, 'Save');
$this->submitForm($edit, 'Save');
\Drupal::service('entity_type.manager')->getStorage('commerce_store')->resetCache([$store->id()]);
$store_changed = Store::load($store->id());
$this->assertEqual($new_store_name, $store_changed->getName(), 'The store name successfully updated.');
$this->assertEquals($new_store_name, $store_changed->getName(), 'The store name successfully updated.');
}
/**
......@@ -105,9 +115,9 @@ class StoreTest extends CommerceTestBase {
public function testDeleteStore() {
$store = $this->createStore();
$this->drupalGet($store->toUrl('delete-form'));
$this->assertResponse(200, 'The store delete form can be accessed.');
$this->assertText(t('This action cannot be undone.'), 'The store delete confirmation form is available.');
$this->drupalPostForm(NULL, NULL, t('Delete'));
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains('This action cannot be undone.');
$this->submitForm([], t('Delete'));
\Drupal::service('entity_type.manager')->getStorage('commerce_store')->resetCache([$store->id()]);
$store_exists = (bool) Store::load($store->id());
......
<?php
namespace Drupal\Tests\commerce\Functional;
use Zumba\Mink\Driver\PhantomJSDriver;
/**
* Provides a base class for Commerce functional tests with JavaScript.
*
* This class does not extend JavascriptTestBase. It uses the same initMink
* override code to tell Mink to use PhantomJS.
*
* This allows us to re-use our helper methods in CommerceBrowserTestBase.
*/
abstract class CommerceJavascriptTestBase extends CommerceBrowserTestBase {
/**
* {@inheritdoc}
*/
protected $minkDefaultDriverClass = PhantomJSDriver::class;
/**
* {@inheritdoc}
*
* @see \Drupal\FunctionalJavascriptTests\JavascriptTestBase::initMink
*/
protected function initMink() {
// Set up the template cache used by the PhantomJS mink driver.
$path = $this->tempFilesDirectory . DIRECTORY_SEPARATOR . 'browsertestbase-templatecache';
$this->minkDefaultDriverArgs = [
'http://127.0.0.1:8510',
$path,
];
if (!file_exists($path)) {
mkdir($path);
}
return parent::initMink();
}
/**
* Waits for the given time or until the given JS condition becomes TRUE.
*
* @param string $condition
* JS condition to wait until it becomes TRUE.
* @param int $timeout
* (Optional) Timeout in milliseconds, defaults to 1000.
* @param string $message
* (optional) A message to display with the assertion. If left blank, a
* default message will be displayed.
*
* @see \Behat\Mink\Driver\DriverInterface::evaluateScript()
*/
protected function assertJsCondition($condition, $timeout = 1000, $message = '') {
$message = $message ?: "Javascript condition met:\n" . $condition;
$result = $this->getSession()->getDriver()->wait($timeout, $condition);
$this->assertTrue($result, $message);
}
/**
* Waits for jQuery to become active and animations to complete.
*/
protected function waitForAjaxToFinish() {
$condition = "(0 === jQuery.active && 0 === jQuery(':animated').length)";
$this->assertJsCondition($condition, 10000);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment