View source
<?php
namespace Drupal\Tests\commerce_cart_api\Functional;
use Drupal\commerce_store\StoreCreationTrait;
use Drupal\Core\Url;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
use Drupal\Tests\rest\Functional\ResourceTestBase;
abstract class CartResourceTestBase extends ResourceTestBase {
use CookieResourceTestTrait;
use StoreCreationTrait;
protected static $auth = 'cookie';
protected $store;
protected $cartManager;
protected $cartProvider;
protected $variation;
protected $variation_2;
public static $modules = [
'commerce_cart_api',
'commerce',
'commerce_cart',
'commerce_order',
'commerce_store',
'commerce_product',
];
protected $defaultTheme = 'stark';
public function setUp() {
parent::setUp();
$this->store = $this
->createStore();
$this->cartManager = \Drupal::service('commerce_cart.cart_manager');
$this->cartProvider = \Drupal::service('commerce_cart.cart_provider');
$this->variation = $this
->createEntity('commerce_product_variation', [
'type' => 'default',
'sku' => $this
->randomMachineName(),
'price' => [
'number' => 1000,
'currency_code' => 'USD',
],
]);
$this->variation_2 = $this
->createEntity('commerce_product_variation', [
'type' => 'default',
'sku' => $this
->randomMachineName(),
'price' => [
'number' => 500,
'currency_code' => 'USD',
],
]);
$this
->createEntity('commerce_product', [
'type' => 'default',
'title' => $this
->randomMachineName(),
'stores' => [
$this->store,
],
'variations' => [
$this->variation,
$this->variation_2,
],
]);
$auth = isset(static::$auth) ? [
static::$auth,
] : [];
$this
->provisionResource([
static::$format,
], $auth);
$this
->initAuthentication();
}
protected function assertNormalizationEdgeCases($method, Url $url, array $request_options) {
}
protected function getExpectedUnauthorizedAccessMessage($method) {
}
protected function getExpectedBcUnauthorizedAccessMessage($method) {
}
protected function getExpectedUnauthorizedAccessCacheability() {
}
protected function setUpAuthorization($method) {
switch ($method) {
case 'GET':
$this
->grantPermissionsToTestedRole([
'restful get ' . static::$resourceConfigId,
]);
break;
case 'POST':
$this
->grantPermissionsToTestedRole([
'restful post ' . static::$resourceConfigId,
]);
break;
case 'PATCH':
$this
->grantPermissionsToTestedRole([
'restful patch ' . static::$resourceConfigId,
]);
break;
case 'DELETE':
$this
->grantPermissionsToTestedRole([
'restful delete ' . static::$resourceConfigId,
]);
break;
default:
throw new \UnexpectedValueException();
}
}
protected function createEntity($entity_type, array $values) {
$storage = \Drupal::service('entity_type.manager')
->getStorage($entity_type);
$entity = $storage
->create($values);
$status = $entity
->save();
$entity = $storage
->load($entity
->id());
return $entity;
}
}