Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SelectAttributesTest.php
Go to the documentation of this file.
1 <?php
7 
15 
16 class SelectAttributesTest extends \PHPUnit\Framework\TestCase
17 {
21  private $selectAttributes;
22 
26  private $contextMock;
27 
31  private $registryMock;
32 
36  private $buttonMock;
37 
41  private $layoutMock;
42 
46  private $urlBuilderMock;
47 
51  protected function setUp()
52  {
53  $this->contextMock = $this->getMockBuilder(Context::class)
54  ->disableOriginalConstructor()
55  ->getMock();
56  $this->registryMock = $this->getMockBuilder(Registry::class)
57  ->getMock();
58  $this->buttonMock = $this->getMockBuilder(Button::class)
59  ->disableOriginalConstructor()
60  ->setMethods(['isAllowed', 'getAuthorization', 'toHtml'])
61  ->getMock();
62  $this->layoutMock = $this->getMockBuilder(LayoutInterface::class)
63  ->disableOriginalConstructor()
64  ->getMock();
65  $this->urlBuilderMock = $this->getMockBuilder(UrlInterface::class)
66  ->disableOriginalConstructor()
67  ->getMock();
68 
69  $this->contextMock->expects($this->any())
70  ->method('getLayout')
71  ->willReturn($this->layoutMock);
72  $this->contextMock->expects($this->any())
73  ->method('getUrlBuilder')
74  ->willReturn($this->urlBuilderMock);
75 
76  $this->selectAttributes = new SelectAttributes(
77  $this->contextMock,
78  $this->registryMock
79  );
80  }
81 
91  {
92  $productMock = $this->getMockBuilder(ProductInterface::class)
93  ->setMethods(['getStoreId'])
94  ->getMockForAbstractClass();
95  $this->registryMock->expects($this->any())
96  ->method('registry')
97  ->with('current_product')
98  ->willReturn($productMock);
99  $this->buttonMock->expects($this->any())
100  ->method('toHtml')
101  ->willReturn($result);
102 
103  $this->layoutMock->expects($this->once())
104  ->method('createBlock')
105  ->willReturn($this->buttonMock);
106  $this->buttonMock->expects($this->once())
107  ->method('getAuthorization')
108  ->willReturnSelf();
109  $this->buttonMock->expects($this->once())
110  ->method('isAllowed')
111  ->with('Magento_Catalog::attributes_attributes')
112  ->willReturn($isAllowed);
113 
114  $this->assertEquals($result, $this->selectAttributes->getAddNewAttributeButton());
115  }
116 
120  public function attributesDataProvider()
121  {
122  return [
123  [false, ''],
124  [true, 'attribute html']
125  ];
126  }
127 }
$isAllowed
Definition: get.php:20