You are here

public function ShippingMethodStorageTest::testFilteringByStore in Commerce Shipping 8.2

Tests shipping method filtering by store.

File

tests/src/Kernel/ShippingMethodStorageTest.php, line 146

Class

ShippingMethodStorageTest
Tests the shipping method storage.

Namespace

Drupal\Tests\commerce_shipping\Kernel

Code

public function testFilteringByStore() {
  $second_store = $this
    ->createStore('Default store 2', 'admin@example.com');
  $shipping_method1 = ShippingMethod::create([
    'stores' => $this->store
      ->id(),
    'name' => 'Example 1',
    'plugin' => [
      'target_plugin_id' => 'flat_rate',
      'target_plugin_configuration' => [],
    ],
    'status' => TRUE,
  ]);
  $shipping_method1
    ->save();
  $shipping_method2 = ShippingMethod::create([
    'stores' => $second_store
      ->id(),
    'name' => 'Example 2',
    'plugin' => [
      'target_plugin_id' => 'flat_rate',
      'target_plugin_configuration' => [],
    ],
    'status' => TRUE,
  ]);
  $shipping_method2
    ->save();
  $shipping_methods = $this->storage
    ->loadMultipleForShipment($this->shipment);
  $this
    ->assertCount(1, $shipping_methods);
  $this
    ->assertEquals($shipping_method1
    ->id(), reset($shipping_methods)
    ->id());
}