Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
OptionsAvailabilityTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
15 use PHPUnit\Framework\TestCase;
16 
20 class OptionsAvailabilityTest extends TestCase
21 {
25  private $storeManager;
26 
30  private $productRepository;
31 
35  private $configurableView;
36 
40  private $serializer;
41 
45  protected function setUp()
46  {
47  parent::setUp();
48 
49  $this->storeManager = Bootstrap::getObjectManager()->get(StoreManagerInterface::class);
50  $this->configurableView = Bootstrap::getObjectManager()->get(ConfigurableView::class);
51  $this->productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
52  $this->serializer = Bootstrap::getObjectManager()->get(SerializerInterface::class);
53  }
54 
74  public function testGetSalableOptions(string $storeCode, int $expected)
75  {
76  $this->storeManager->setCurrentStore($storeCode);
77 
78  $configurableProduct = $this->productRepository->get('configurable', false, null, true);
79  $this->configurableView->setProduct($configurableProduct);
80  $result = $this->serializer->unserialize($this->configurableView->getJsonConfig());
81  $attributes = reset($result['attributes']);
82  $actual = count($attributes['options'] ?? []);
83 
84  $this->assertEquals(
85  $expected,
86  $actual
87  );
88  }
89 
94  {
95  return [
96  [
97  'store_for_eu_website',
98  0
99  ],
100  [
101  'store_for_us_website',
102  2
103  ],
104  ];
105  }
106 }
$storeCode
Definition: indexer.php:15
$attributes
Definition: matrix.phtml:13