/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); // Create a store. $values = ['name' => t('Default store'), 'uid' => 1, 'mail' => \Drupal::config('system.site')->get('mail'), 'type' => 'default', 'default_currency' => 'USD', 'address' => ['country_code' => 'GB', 'locality' => 'London', 'postal_code' => 'NW1 6XE', 'address_line1' => '221B Baker Street']]; $this->store = Store::create($values); $this->store->save(); // Set as default store. \Drupal::configFactory()->getEditable('commerce_store.settings')->set('default_store', $this->store->uuid())->save(); // Create a product variation. $values = ['type' => 'default', 'sku' => $this->randomMachineName(), 'price' => ['amount' => 999, 'currency_code' => 'USD']]; $this->variation = ProductVariation::create($values); $this->variation->save(); // We need a product too otherwise tests complain about the missing // backreference. $this->createEntity('commerce_product', ['type' => 'default', 'title' => $this->randomMachineName(), 'stores' => [$this->store], 'variations' => [$this->variation]]); }
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 $values = [ 'name' => t('Default store'), 'uid' => 1, 'mail' => \Drupal::config('system.site')->get('mail'), 'type' => 'default', 'default_currency' => 'USD', 'address' => [ 'country_code' => 'GB', 'locality' => 'London', 'postal_code' => 'NW1 6XE', 'address_line1' => '221B Baker Street', ], ]; $this->store = Store::create($values); $this->store->save(); // Set as default store. \Drupal::configFactory()->getEditable('commerce_store.settings') ->set('default_store', $this->store->uuid())->save(); // Create a product variation. $values = [ 'type' => 'default', 'sku' => $this->randomMachineName(), ]; $this->variation = ProductVariation::create($values); $this->variation->save(); $this->drupalLogin($this->adminUser); }
/** * Tests deleting a store. */ public function testDeleteStore() { // Create a new store. $store = $this->createEntity('commerce_store', ['type' => $this->type->id(), 'name' => $this->randomMachineName(8), 'email' => \Drupal::currentUser()->getEmail()]); $store_exists = (bool) Store::load($store->id()); $this->assertTrue($store_exists, 'The new store has been created in the database.'); // Delete the Store and verify deletion. $store->delete(); $store_exists = (bool) Store::load($store->id()); $this->assertFalse($store_exists, 'The new store has been deleted from the database.'); }
/** * Tests deleting a store. */ public function testDeleteStore() { $store = $this->createStore(['type' => 'default', 'name' => $this->randomMachineName(8)]); $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')); \Drupal::service('entity_type.manager')->getStorage('commerce_store')->resetCache([$store->id()]); $store_exists = (bool) Store::load($store->id()); $this->assertFalse($store_exists, 'The new store has been deleted from the database using UI.'); }