|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2015 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Magento\ConfigurableProduct\Test\Unit\Model\ResourceModel\Product\Type\Configurable; |
| 8 | + |
| 9 | +use Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute as AttributeModel; |
| 10 | +use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute; |
| 11 | +use Magento\Framework\DB\Select; |
| 12 | +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; |
| 13 | + |
| 14 | +class AttributeTest extends \PHPUnit_Framework_TestCase |
| 15 | +{ |
| 16 | + /** @var \PHPUnit_Framework_MockObject_MockObject */ |
| 17 | + protected $connection; |
| 18 | + /** |
| 19 | + * @var Attribute |
| 20 | + */ |
| 21 | + protected $attribute; |
| 22 | + |
| 23 | + /** |
| 24 | + * @var ObjectManagerHelper |
| 25 | + */ |
| 26 | + protected $objectManagerHelper; |
| 27 | + |
| 28 | + /** |
| 29 | + * @var \Magento\Framework\App\ResourceConnection|\PHPUnit_Framework_MockObject_MockObject |
| 30 | + */ |
| 31 | + protected $resource; |
| 32 | + |
| 33 | + /** |
| 34 | + * @var \Magento\Catalog\Model\ResourceModel\Product\Relation|\PHPUnit_Framework_MockObject_MockObject |
| 35 | + */ |
| 36 | + protected $relation; |
| 37 | + |
| 38 | + protected function setUp() |
| 39 | + { |
| 40 | + $this->connection = $this->getMockBuilder('\Magento\Framework\DB\Adapter\AdapterInterface')->getMock(); |
| 41 | + |
| 42 | + $this->resource = $this->getMock('Magento\Framework\App\ResourceConnection', [], [], '', false); |
| 43 | + $this->resource->expects($this->any())->method('getConnection')->will($this->returnValue($this->connection)); |
| 44 | + $this->resource->expects($this->any())->method('getTableName')->willReturnArgument(0); |
| 45 | + |
| 46 | + $this->objectManagerHelper = new ObjectManagerHelper($this); |
| 47 | + $this->attribute = $this->objectManagerHelper->getObject( |
| 48 | + Attribute::class, |
| 49 | + [ |
| 50 | + 'resource' => $this->resource, |
| 51 | + ] |
| 52 | + ); |
| 53 | + } |
| 54 | + |
| 55 | + public function testSaveLabel() |
| 56 | + { |
| 57 | + $attributeId = 4354; |
| 58 | + |
| 59 | + $select = $this->getMockBuilder(Select::class)->disableOriginalConstructor()->getMock(); |
| 60 | + $this->connection->expects($this->once())->method('select')->willReturn($select); |
| 61 | + $select->expects($this->once())->method('from')->willReturnSelf(); |
| 62 | + $select->expects($this->at(1))->method('where')->willReturnSelf(); |
| 63 | + $select->expects($this->at(2))->method('where')->willReturnSelf(); |
| 64 | + $this->connection->expects($this->once())->method('fetchOne')->with( |
| 65 | + $select, |
| 66 | + [ |
| 67 | + 'product_super_attribute_id' => $attributeId, |
| 68 | + 'store_id' => \Magento\Store\Model\Store::DEFAULT_STORE_ID, |
| 69 | + ] |
| 70 | + )->willReturn(0); |
| 71 | + |
| 72 | + $this->connection->expects($this->once())->method('insertOnDuplicate')->with( |
| 73 | + 'catalog_product_super_attribute_label', |
| 74 | + [ |
| 75 | + 'product_super_attribute_id' => $attributeId, |
| 76 | + 'use_default' => 0, |
| 77 | + 'store_id' => 0, |
| 78 | + 'value' => 'test', |
| 79 | + ] |
| 80 | + ); |
| 81 | + $attributeMode = $this->getMockBuilder(AttributeModel::class)->setMethods( |
| 82 | + ['getId', 'getUseDefault', 'getLabel'] |
| 83 | + )->disableOriginalConstructor()->getMock(); |
| 84 | + $attributeMode->expects($this->any())->method('getId')->willReturn($attributeId); |
| 85 | + $attributeMode->expects($this->any())->method('getUseDefault')->willReturn(0); |
| 86 | + $attributeMode->expects($this->any())->method('getLabel')->willReturn('test'); |
| 87 | + $this->assertEquals($this->attribute, $this->attribute->saveLabel($attributeMode)); |
| 88 | + } |
| 89 | +} |
0 commit comments