Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GetSelectedTest.php
Go to the documentation of this file.
1 <?php
7 declare(strict_types=1);
8 
10 
15 {
19  public function testExecute() : void
20  {
22  $productRepository = $objectManager->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
23 
24  $product = $productRepository->get('simple');
25  $this->getRequest()
26  ->setPostValue('productId', $product->getId());
27  $this->dispatch('backend/catalog/product/getSelected');
28  $responseBody = $this->getResponse()->getBody();
29  $this->assertContains(
30  '{"value":"1","label":"Simple Product","is_active":1,"path":"simple"}',
31  $responseBody
32  );
33  }
34 
35  public function testExecuteNonExistingSearchKey() : void
36  {
37  $this->getRequest()
38  ->setPostValue('productId', '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
39  $this->dispatch('backend/catalog/product/getSelected');
40  $responseBody = $this->getResponse()->getBody();
41  $this->assertContains('[]', $responseBody);
42  }
43 }
$objectManager
Definition: bootstrap.php:17
dispatch(\Magento\Framework\App\RequestInterface $request)