Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 15 additions & 48 deletions modules/order/src/Tests/OrderTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@

use Drupal\commerce_product\Entity\ProductVariation;
use Drupal\commerce_store\Entity\Store;
use Drupal\commerce_store\Tests\StoreTestBase;
use Drupal\commerce\Tests\CommerceTestBase;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\simpletest\WebTestBase;

/**
* Defines base class for commerce_order test cases.
*/
abstract class OrderTestBase extends WebTestBase {
abstract class OrderTestBase extends CommerceTestBase {

/**
* The variation to test against
Expand All @@ -43,31 +42,16 @@ abstract class OrderTestBase extends WebTestBase {
'commerce_order',
'commerce_price',
'inline_entity_form',
'block'
'block',
];

/**
* A user with permission to administer orders.
*
* @var \Drupal\user\Entity\User
* {@inheritdoc}
*/
protected $adminUser;

protected function setUp() {
parent::setUp();

$this->drupalPlaceBlock('local_tasks_block');
$this->drupalPlaceBlock('local_actions_block');
$this->drupalPlaceBlock('page_title_block');

$this->adminUser = $this->drupalCreateUser([
'administer orders',
'administer order types',
'administer line item types',
'access administration pages',
]);

// Create a store
// Create a store.
$values = [
'name' => t('Default store'),
'uid' => 1,
Expand Down Expand Up @@ -103,36 +87,19 @@ protected function setUp() {
'title' => $this->randomMachineName(),
'variations' => [$this->variation],
]);

$this->drupalLogin($this->adminUser);
}

/**
* Creates a new entity
*
* @param string $entity_type
* @param array $values
* An array of settings.
* Example: 'id' => 'foo'.
*
* @return \Drupal\Core\Entity\EntityInterface
* {@inheritdoc}
*/
protected function createEntity($entity_type, $values) {
$entity = \Drupal::service('entity_type.manager')
->getStorage($entity_type)
->create($values);
$status = $entity->save();

$this->assertEqual(
$status,
SAVED_NEW,
SafeMarkup::format('Created %label entity %type.', [
'%label' => $entity->getEntityType()->getLabel(),
'%type' => $entity->id()
]
)
);

return $entity;
protected function defaultAdminUserPermissions() {
return [
'view the administration theme',
'configure store',
'administer orders',
'administer order types',
'administer line item types',
];
}

}
89 changes: 14 additions & 75 deletions modules/product/src/Tests/ProductTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@

namespace Drupal\commerce_product\Tests;

use Drupal\Component\Utility\SafeMarkup;
use Drupal\simpletest\WebTestBase;
use Drupal\commerce\Tests\CommerceTestBase;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;

/**
* Defines base class for shortcut test cases.
*/
abstract class ProductTestBase extends WebTestBase {
abstract class ProductTestBase extends CommerceTestBase {

use EntityReferenceTestTrait;

Expand All @@ -32,14 +31,9 @@ abstract class ProductTestBase extends WebTestBase {
'field_ui',
'options',
'taxonomy',
'block'
'block',
];

/**
* User with permission to administer products.
*/
protected $adminUser;

/**
* The product to test against
*/
Expand All @@ -56,19 +50,6 @@ abstract class ProductTestBase extends WebTestBase {
protected function setUp() {
parent::setUp();

$this->drupalPlaceBlock('local_tasks_block');
$this->drupalPlaceBlock('local_actions_block');
$this->drupalPlaceBlock('page_title_block');

$this->adminUser = $this->drupalCreateUser([
'administer products',
'administer product types',
'administer commerce_product fields',
'access administration pages',
'administer commerce_product_variation fields'
]);
$this->drupalLogin($this->adminUser);

$store_type = $this->createEntity('commerce_store_type', [
'id' => strtolower($this->randomMachineName(8)),
'label' => $this->randomMachineName(8),
Expand All @@ -86,60 +67,18 @@ protected function setUp() {
}

/**
* Creates a new entity
*
* @param string $entity_type
* The entity type.
* @param array $values
* The values used to create the entity.
*
* @return \Drupal\Core\Entity\EntityInterface
*/
protected function createEntity($entity_type, $values) {
$storage = \Drupal::service('entity_type.manager')->getStorage($entity_type);
$entity = $storage->create($values);
$status = $entity->save();
$this->assertEqual($status, SAVED_NEW, SafeMarkup::format('Created %label entity %type.', [
'%label' => $entity->getEntityType()->getLabel(),
'%type' => $entity->id()
]));
// The newly saved entity isn't identical to a loaded one, and would fail
// comparisons.
$entity = $storage->load($entity->id());

return $entity;
}

/**
* Asserts that the passed field values are correct.
*
* Ignores differences in ordering.
*
* @param array $field_values
* The field values.
* @param array $expected_values
* The expected values.
* @param $message
* (optional) A message to display with the assertion. Do not translate
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
* variables in the message text, not t(). If left blank, a default message
* will be displayed.
* {@inheritdoc}
*/
protected function assertFieldValues(array $field_values, array $expected_values, $message = '') {
$valid = TRUE;
if (count($field_values) == count($expected_values)) {
foreach ($expected_values as $value) {
if (!in_array($value, $field_values)) {
$valid = FALSE;
break;
}
}
}
else {
$valid = FALSE;
}

$this->assertTrue($valid, $message);
protected function defaultAdminUserPermissions() {
return [
'view the administration theme',
'configure store',
'administer products',
'administer product types',
'administer commerce_product fields',
'access administration pages',
'administer commerce_product_variation fields',
];
}

}
25 changes: 2 additions & 23 deletions modules/store/src/Tests/StoreTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@

namespace Drupal\commerce_store\Tests;

use Drupal\Component\Utility\SafeMarkup;
use Drupal\simpletest\WebTestBase;
use Drupal\commerce\Tests\CommerceTestBase;

/**
* Defines base class for commerce test cases.
*/
abstract class StoreTestBase extends WebTestBase {
abstract class StoreTestBase extends CommerceTestBase {

/**
* Modules to enable.
Expand Down Expand Up @@ -47,24 +46,4 @@ protected function setUp() {
$this->drupalLogin($this->adminUser);
}

/**
* Creates a new entity.
*
* @param string $entityType
* The entity type to be created.
* @param array $values
* An array of settings.
* Example: 'id' => 'foo'.
*
* @return \Drupal\Core\Entity\EntityInterface
* A new entity.
*/
protected function createEntity($entityType, array $values) {
$entity = \Drupal::service('entity_type.manager')->getStorage($entityType)->create($values);
$status = $entity->save();
$this->assertEqual($status, SAVED_NEW, SafeMarkup::format('Created %label entity %type.', ['%label' => $entity->getEntityType()->getLabel(), '%type' => $entity->id()]));

return $entity;
}

}
20 changes: 7 additions & 13 deletions modules/tax/src/Tests/TaxTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

namespace Drupal\commerce_tax\Tests;

use Drupal\simpletest\WebTestBase;
use Drupal\commerce\Tests\CommerceTestBase;

/**
* Defines the base class for tax test cases.
*/
abstract class TaxTestBase extends WebTestBase {
abstract class TaxTestBase extends CommerceTestBase {

/**
* Modules to enable.
Expand All @@ -21,21 +21,15 @@ abstract class TaxTestBase extends WebTestBase {
*/
public static $modules = ['commerce', 'commerce_tax', 'commerce_product'];

/**
* User with permission to administer products.
*/
protected $adminUser;

/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();

$this->adminUser = $this->drupalCreateUser([
protected function defaultAdminUserPermissions() {
return [
'view the administration theme',
'configure store',
'administer stores',
'access administration pages',
]);
$this->drupalLogin($this->adminUser);
];
}
}
Loading