StoreTest.php in Commerce Core 8.2
File
modules/store/tests/src/FunctionalJavascript/StoreTest.php
View source
<?php
namespace Drupal\Tests\commerce_store\FunctionalJavascript;
use Drupal\commerce_store\Entity\Store;
use Drupal\Tests\commerce\FunctionalJavascript\CommerceWebDriverTestBase;
class StoreTest extends CommerceWebDriverTestBase {
protected $type;
protected function getAdministratorPermissions() {
return array_merge([
'access commerce_store overview',
], parent::getAdministratorPermissions());
}
public function testCreateStore() {
$this
->drupalGet('admin/commerce/config/stores');
$this
->getSession()
->getPage()
->clickLink('Add store');
$this
->assertSession()
->fieldExists('name[0][value]');
$this
->assertSession()
->fieldExists('mail[0][value]');
$this
->assertSession()
->fieldExists('address[0][address][country_code]');
$this
->assertSession()
->fieldExists('billing_countries[]');
$this
->assertSession()
->fieldExists('is_default[value]');
$this
->getSession()
->getPage()
->fillField('address[0][address][country_code]', 'US');
$this
->getSession()
->wait(4000, 'jQuery(\'select[name="address[0][address][administrative_area]"]\').length > 0 && jQuery.active == 0;');
$name = $this
->randomMachineName(8);
$edit = [
'name[0][value]' => $name,
'mail[0][value]' => \Drupal::currentUser()
->getEmail(),
'default_currency' => 'USD',
'timezone' => 'UTC',
];
$address = [
'address_line1' => '1098 Alta Ave',
'locality' => 'Mountain View',
'administrative_area' => 'CA',
'postal_code' => '94043',
];
foreach ($address as $property => $value) {
$path = 'address[0][address][' . $property . ']';
$edit[$path] = $value;
}
$this
->submitForm($edit, t('Save'));
$this
->assertSession()
->pageTextContains("Saved the {$name} store.");
}
public function testEditStore() {
$store = $this
->createStore('Test');
$this
->drupalGet($store
->toUrl('edit-form'));
$edit = [
'name[0][value]' => 'Test!',
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains("Saved the Test! store.");
$store = $this
->reloadEntity($store);
$this
->assertEquals('Test!', $store
->label());
}
public function testDuplicateStore() {
$store = $this
->createStore('Test');
$this
->drupalGet($store
->toUrl('duplicate-form'));
$edit = [
'name[0][value]' => 'Test2',
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('Saved the Test2 store.');
$store = $this
->reloadEntity($store);
$this
->assertEquals('Test', $store
->label());
$store = Store::load($store
->id() + 1);
$this
->assertNotEmpty($store);
$this
->assertEquals('Test2', $store
->label());
}
public function testDeleteStore() {
$store = $this
->createStore();
$this
->drupalGet($store
->toUrl('delete-form'));
$this
->assertSession()
->pageTextContains('This action cannot be undone.');
$this
->submitForm([], t('Delete'));
$this->container
->get('entity_type.manager')
->getStorage('commerce_store')
->resetCache([
$store
->id(),
]);
$store_exists = (bool) Store::load($store
->id());
$this
->assertEmpty($store_exists);
}
}