Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SuggestConfigurableAttributesTest.php
Go to the documentation of this file.
1 <?php
7 
8 class SuggestConfigurableAttributesTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $suggestAttributes;
14 
18  protected $responseMock;
19 
23  protected $requestMock;
24 
28  protected $helperMock;
29 
33  protected $attributeListMock;
34 
35  protected function setUp()
36  {
37  $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
38  $this->responseMock = $this->createMock(\Magento\Framework\App\Response\Http::class);
39  $this->requestMock = $this->createMock(\Magento\Framework\App\Request\Http::class);
40  $this->helperMock = $this->createMock(\Magento\Framework\Json\Helper\Data::class);
41  $this->attributeListMock = $this->createMock(\Magento\ConfigurableProduct\Model\SuggestedAttributeList::class);
42  $this->suggestAttributes = $helper->getObject(
43  \Magento\ConfigurableProduct\Controller\Adminhtml\Product\Attribute\SuggestConfigurableAttributes::class,
44  [
45  'response' => $this->responseMock,
46  'request' => $this->requestMock,
47  'jsonHelper' => $this->helperMock,
48  'attributeList' => $this->attributeListMock
49  ]
50  );
51  }
52 
53  public function testIndexAction()
54  {
55  $this->requestMock->expects(
56  $this->once()
57  )->method(
58  'getParam'
59  )->with(
60  'label_part'
61  )->will(
62  $this->returnValue('attribute')
63  );
64  $this->attributeListMock->expects(
65  $this->once()
66  )->method(
67  'getSuggestedAttributes'
68  )->with(
69  'attribute'
70  )->will(
71  $this->returnValue('some_value_for_json')
72  );
73  $this->helperMock->expects(
74  $this->once()
75  )->method(
76  'jsonEncode'
77  )->with(
78  'some_value_for_json'
79  )->will(
80  $this->returnValue('body')
81  );
82  $this->responseMock->expects($this->once())->method('representJson')->with('body');
83  $this->suggestAttributes->execute();
84  }
85 }
$helper
Definition: iframe.phtml:13