|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\ConfigurableProduct\Test\Unit\Block\Adminhtml\Product\Steps; |
| 7 | + |
| 8 | +use Magento\ConfigurableProduct\Block\Adminhtml\Product\Steps\SelectAttributes; |
| 9 | +use Magento\Framework\View\Element\Template\Context; |
| 10 | +use Magento\Framework\Registry; |
| 11 | +use Magento\Backend\Block\Widget\Button; |
| 12 | +use Magento\Framework\View\LayoutInterface; |
| 13 | +use Magento\Catalog\Api\Data\ProductInterface; |
| 14 | +use Magento\Framework\UrlInterface; |
| 15 | + |
| 16 | +class SelectAttributesTest extends \PHPUnit_Framework_TestCase |
| 17 | +{ |
| 18 | + /** |
| 19 | + * @var SelectAttributes |
| 20 | + */ |
| 21 | + protected $selectAttributes; |
| 22 | + |
| 23 | + /** |
| 24 | + * @var Context|\PHPUnit_Framework_MockObject_MockObject |
| 25 | + */ |
| 26 | + protected $contextMock; |
| 27 | + |
| 28 | + /** |
| 29 | + * @var Registry|\PHPUnit_Framework_MockObject_MockObject |
| 30 | + */ |
| 31 | + protected $registryMock; |
| 32 | + |
| 33 | + /** |
| 34 | + * @var Button|\PHPUnit_Framework_MockObject_MockObject |
| 35 | + */ |
| 36 | + protected $buttonMock; |
| 37 | + |
| 38 | + /** |
| 39 | + * @var LayoutInterface|\PHPUnit_Framework_MockObject_MockObject |
| 40 | + */ |
| 41 | + protected $layoutMock; |
| 42 | + |
| 43 | + /** |
| 44 | + * @var UrlInterface|\PHPUnit_Framework_MockObject_MockObject |
| 45 | + */ |
| 46 | + protected $urlBuilderMock; |
| 47 | + |
| 48 | + /** |
| 49 | + * {@inheritDoc} |
| 50 | + */ |
| 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 | + |
| 82 | + /** |
| 83 | + * @param bool $isAllowed |
| 84 | + * @param string $result |
| 85 | + * |
| 86 | + * @dataProvider attributesDataProvider |
| 87 | + * |
| 88 | + * @return void |
| 89 | + */ |
| 90 | + public function testGetAddNewAttributeButton($isAllowed, $result) |
| 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 | + |
| 117 | + public function attributesDataProvider() |
| 118 | + { |
| 119 | + return [ |
| 120 | + [false, ''], |
| 121 | + [true, 'attribute html'] |
| 122 | + ]; |
| 123 | + } |
| 124 | +} |
0 commit comments