|
12 | 12 | */
|
13 | 13 | class AbstractCollectionTest extends \PHPUnit\Framework\TestCase
|
14 | 14 | {
|
| 15 | + const ATTRIBUTE_CODE = 'any_attribute'; |
| 16 | + const ATTRIBUTE_ID_STRING = '15'; |
| 17 | + const ATTRIBUTE_ID_INT = 15; |
| 18 | + |
15 | 19 | /**
|
16 | 20 | * @var AbstractCollectionStub|\PHPUnit_Framework_MockObject_MockObject
|
17 | 21 | */
|
@@ -105,6 +109,26 @@ protected function setUp()
|
105 | 109 | $entityMock = $this->createMock(\Magento\Eav\Model\Entity\AbstractEntity::class);
|
106 | 110 | $entityMock->expects($this->any())->method('getConnection')->will($this->returnValue($connectionMock));
|
107 | 111 | $entityMock->expects($this->any())->method('getDefaultAttributes')->will($this->returnValue([]));
|
| 112 | + $entityMock->expects($this->any())->method('getLinkField')->willReturn('entity_id'); |
| 113 | + |
| 114 | + $attributeMock = $this->createMock(\Magento\Eav\Model\Attribute::class); |
| 115 | + $attributeMock->expects($this->any())->method('isStatic')->willReturn(false); |
| 116 | + $attributeMock->expects($this->any())->method('getAttributeCode')->willReturn(self::ATTRIBUTE_CODE); |
| 117 | + $attributeMock->expects($this->any())->method('getBackendTable')->willReturn('eav_entity_int'); |
| 118 | + $attributeMock->expects($this->any())->method('getBackendType')->willReturn('int'); |
| 119 | + $attributeMock->expects($this->any())->method('getId')->willReturn(self::ATTRIBUTE_ID_STRING); |
| 120 | + |
| 121 | + $entityMock |
| 122 | + ->expects($this->any()) |
| 123 | + ->method('getAttribute') |
| 124 | + ->with(self::ATTRIBUTE_CODE) |
| 125 | + ->willReturn($attributeMock); |
| 126 | + |
| 127 | + $this->configMock |
| 128 | + ->expects($this->any()) |
| 129 | + ->method('getAttribute') |
| 130 | + ->with(null, self::ATTRIBUTE_CODE) |
| 131 | + ->willReturn($attributeMock); |
108 | 132 |
|
109 | 133 | $this->validatorFactoryMock->expects(
|
110 | 134 | $this->any()
|
@@ -193,6 +217,30 @@ public function testRemoveItemByKey($values, $count)
|
193 | 217 | $this->assertNull($this->model->getItemById($testId));
|
194 | 218 | }
|
195 | 219 |
|
| 220 | + /** |
| 221 | + * @dataProvider getItemsDataProvider |
| 222 | + */ |
| 223 | + public function testAttributeIdIsInt($values) |
| 224 | + { |
| 225 | + $this->resourceHelperMock->expects($this->any())->method('getLoadAttributesSelectGroups')->willReturn([]); |
| 226 | + $this->fetchStrategyMock->expects($this->any())->method('fetchAll')->will($this->returnValue($values)); |
| 227 | + $selectMock = $this->coreResourceMock->getConnection()->select(); |
| 228 | + $selectMock->expects($this->any())->method('from')->willReturn($selectMock); |
| 229 | + $selectMock->expects($this->any())->method('join')->willReturn($selectMock); |
| 230 | + $selectMock->expects($this->any())->method('where')->willReturn($selectMock); |
| 231 | + $selectMock->expects($this->any())->method('columns')->willReturn($selectMock); |
| 232 | + |
| 233 | + $this->model |
| 234 | + ->addAttributeToSelect(self::ATTRIBUTE_CODE) |
| 235 | + ->_loadEntities() |
| 236 | + ->_loadAttributes(); |
| 237 | + |
| 238 | + $_selectAttributesActualValue = $this->readAttribute($this->model, '_selectAttributes'); |
| 239 | + |
| 240 | + $this->assertAttributeEquals([self::ATTRIBUTE_CODE => self::ATTRIBUTE_ID_STRING], '_selectAttributes', $this->model); |
| 241 | + $this->assertSame($_selectAttributesActualValue[self::ATTRIBUTE_CODE], self::ATTRIBUTE_ID_INT); |
| 242 | + } |
| 243 | + |
196 | 244 | /**
|
197 | 245 | * @return array
|
198 | 246 | */
|
|
0 commit comments