protected function OrderReportGenerateFormTest::setUp in Commerce Reporting 8
Overrides CommerceBrowserTestBase::setUp
File
- tests/
src/ Functional/ OrderReportGenerateFormTest.php, line 65
Class
- OrderReportGenerateFormTest
- Tests the OrderReportGenerateForm.
Namespace
Drupal\Tests\commerce_reports\FunctionalCode
protected function setUp() {
parent::setUp();
$variation = $this
->createEntity('commerce_product_variation', [
'type' => 'default',
'sku' => $this
->randomMachineName(),
'price' => [
'number' => 999,
'currency_code' => 'USD',
],
]);
$product = $this
->createEntity('commerce_product', [
'type' => 'default',
'title' => $this
->randomMachineName(),
'stores' => [
$this->store,
],
'variations' => [
$variation,
],
]);
$profile = $this
->createEntity('profile', [
'type' => 'customer',
'address' => [
'country_code' => 'US',
'postal_code' => '53177',
'locality' => 'Milwaukee',
'address_line1' => 'Pabst Blue Ribbon Dr',
'administrative_area' => 'WI',
'given_name' => 'Frederick',
'family_name' => 'Pabst',
],
'uid' => 0,
]);
// Create ORDER_COUNT orders, with 1/3 in draft state.
for ($i = 0; $i < self::ORDER_COUNT; $i++) {
$order_item_storage = \Drupal::service('entity_type.manager')
->getStorage('commerce_order_item');
$order_item = $order_item_storage
->createFromPurchasableEntity($variation, [
'quantity' => rand(1, 10),
]);
$order_item
->save();
$order_item = $order_item_storage
->load($order_item
->id());
$order_storage = \Drupal::service('entity_type.manager')
->getStorage('commerce_order');
$is_completed = $i % 3 != 0;
$order = $this
->createEntity('commerce_order', [
'type' => 'default',
'store_id' => $this->store
->id(),
'cart' => !$is_completed,
'state' => !$is_completed ? 'draft' : 'completed',
'mail' => $this
->randomString() . '@example.com',
'uid' => User::getAnonymousUser(),
'ip_address' => '127.0.0.1',
'order_number' => '6',
'billing_profile' => $profile,
'placed' => $is_completed ? time() : NULL,
]);
$order
->addItem($order_item);
$order
->save();
$this->orders[] = $order_storage
->load($order
->id());
}
}