public function testGetSetAttributes() { $this->productResource->expects($this->any())->method('loadAllAttributes')->will($this->returnValue($this->productResource)); $this->productResource->expects($this->any())->method('getSortedAttributes')->will($this->returnValue(5)); $this->model->getSetAttributes($this->product); $this->assertEquals(5, $this->model->getSetAttributes($this->product)); }
public function testGetSetAttributes() { $this->productResource->expects($this->once())->method('loadAllAttributes')->will($this->returnValue($this->productResource)); $this->productResource->expects($this->once())->method('getSortedAttributes')->will($this->returnValue(5)); $this->assertEquals(5, $this->model->getSetAttributes($this->product)); //Call the method for a second time, the cached copy should be used $this->assertEquals(5, $this->model->getSetAttributes($this->product)); }
/** * test get group price, attribute is not set */ public function testGroupPriceAttributeIsNotSet() { $this->productMock->expects($this->exactly(2))->method('getCustomerGroupId')->will($this->returnValue(3)); $this->productMock->expects($this->once())->method('getResource')->will($this->returnValue($this->productResourceMock)); $this->productResourceMock->expects($this->once())->method('getAttribute')->with($this->equalTo('group_price'))->will($this->returnValue(null)); $this->assertFalse($this->groupPrice->getValue()); }
/** * @dataProvider validateDataProvider * * @param string $attributeValue * @param string|array $parsedValue * @param string $newValue * @param string $operator * @param array $input */ public function testValidateWithDatetimeValue($attributeValue, $parsedValue, $newValue, $operator, $input) { $this->product->setData('attribute', 'attribute_key'); $this->product->setData('value_parsed', $parsedValue); $this->product->setData('operator', $operator); $this->config->expects($this->any())->method('getAttribute')->will($this->returnValue($this->eavAttributeResource)); $this->eavAttributeResource->expects($this->any())->method('isScopeGlobal')->will($this->returnValue(false)); $this->eavAttributeResource->expects($this->any())->method($input['method'])->will($this->returnValue($input['type'])); $this->productModel->expects($this->any())->method('hasData')->will($this->returnValue(true)); $this->productModel->expects($this->at(0))->method('getData')->will($this->returnValue(['1' => ['1' => $attributeValue]])); $this->productModel->expects($this->any())->method('getData')->will($this->returnValue($newValue)); $this->productModel->expects($this->any())->method('getId')->will($this->returnValue('1')); $this->productModel->expects($this->once())->method('getStoreId')->will($this->returnValue('1')); $this->productModel->expects($this->any())->method('getResource')->will($this->returnValue($this->productResource)); $this->productResource->expects($this->any())->method('getAttribute')->will($this->returnValue($this->eavAttributeResource)); $this->product->collectValidatedAttributes($this->productModel); $this->assertTrue($this->product->validate($this->productModel)); }
public function testStatusAfterLoad() { $this->resource->expects($this->once())->method('load')->with($this->model, 1, null); $this->eventManagerMock->expects($this->exactly(4))->method('dispatch'); $this->model->load(1); $this->assertEquals(Status::STATUS_ENABLED, $this->model->getData(\Magento\Catalog\Model\Product::STATUS)); $this->assertFalse($this->model->hasDataChanges()); $this->model->setStatus(Status::STATUS_DISABLED); $this->assertTrue($this->model->hasDataChanges()); }
public function testGetValue() { $this->priceInfoMock->expects($this->once())->method('getPrice')->with($this->equalTo('regular_price'))->will($this->returnValue($this->regularPrice)); $this->regularPrice->expects($this->once())->method('getValue')->will($this->returnValue(100)); $this->productMock->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue(null)); $this->customerSessionMock->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue(3)); $this->productMock->expects($this->once())->method('getResource')->will($this->returnValue($this->productResourceMock)); $this->productResourceMock->expects($this->once())->method('getAttribute')->with($this->equalTo('group_price'))->will($this->returnValue($this->attributeMock)); $this->attributeMock->expects($this->once())->method('getBackend')->will($this->returnValue($this->backendMock)); $this->backendMock->expects($this->once())->method('afterLoad')->with($this->equalTo($this->productMock))->will($this->returnValue($this->backendMock)); $this->productMock->expects($this->once())->method('getData')->with($this->equalTo('group_price'), $this->equalTo(null))->will($this->returnValue([['cust_group' => 3, 'website_price' => 80]])); $this->assertEquals(20, $this->groupPrice->getValue()); }
/** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @return void */ protected function setUp() { $this->zendDbMock = $this->getMockBuilder('Zend_Db_Statement_Interface')->getMock(); $this->zendDbMock->expects($this->any())->method('fetchColumn')->willReturn([]); $this->selectMock = $this->getMockBuilder('Magento\\Framework\\DB\\Select')->disableOriginalConstructor()->setMethods(['from', 'where', 'joinInner', 'joinLeft', 'having', 'useStraightJoin', 'insertFromSelect', '__toString'])->getMock(); $this->selectMock->expects($this->any())->method('from')->willReturnSelf(); $this->selectMock->expects($this->any())->method('where')->willReturnSelf(); $this->selectMock->expects($this->any())->method('joinInner')->willReturnSelf(); $this->selectMock->expects($this->any())->method('joinLeft')->willReturnSelf(); $this->selectMock->expects($this->any())->method('having')->willReturnSelf(); $this->selectMock->expects($this->any())->method('useStraightJoin')->willReturnSelf(); $this->selectMock->expects($this->any())->method('insertFromSelect')->willReturnSelf(); $this->selectMock->expects($this->any())->method('__toString')->willReturn('string'); $this->connectionMock = $this->getMockBuilder('Magento\\Framework\\DB\\Adapter\\AdapterInterface')->getMock(); $this->connectionMock->expects($this->any())->method('select')->willReturn($this->selectMock); $this->connectionMock->expects($this->any())->method('query')->willReturn($this->zendDbMock); $this->resourceMock = $this->getMockBuilder('Magento\\Framework\\App\\Resource')->disableOriginalConstructor()->getMock(); $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->connectionMock); $this->resourceMock->expects($this->any())->method('getTableName')->will($this->returnCallback(function ($arg) { return $arg; })); $this->contextMock = $this->getMockBuilder('Magento\\Framework\\Model\\Resource\\Db\\Context')->disableOriginalConstructor()->getMock(); $this->contextMock->expects($this->any())->method('getResources')->willReturn($this->resourceMock); $this->loggerMock = $this->getMockBuilder('Psr\\Log\\LoggerInterface')->getMock(); $dateTime = $this->getMockBuilder('DateTime')->getMock(); $this->timezoneMock = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface')->getMock(); $this->timezoneMock->expects($this->any())->method('scopeDate')->willReturn($dateTime); $this->dateTimeMock = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime')->getMock(); $this->flagMock = $this->getMockBuilder('Magento\\Reports\\Model\\Flag')->disableOriginalConstructor()->setMethods(['setReportFlagCode', 'unsetData', 'loadSelf', 'setFlagData', 'setLastUpdate', 'save'])->getMock(); $this->flagFactoryMock = $this->getMockBuilder('Magento\\Reports\\Model\\FlagFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->flagFactoryMock->expects($this->any())->method('create')->willReturn($this->flagMock); $this->validatorMock = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime\\Timezone\\Validator')->disableOriginalConstructor()->getMock(); $this->backendMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\AbstractBackend')->disableOriginalConstructor()->getMock(); $this->attributeMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute')->disableOriginalConstructor()->getMock(); $this->attributeMock->expects($this->any())->method('getBackend')->willReturn($this->backendMock); $this->productMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Resource\\Product')->disableOriginalConstructor()->getMock(); $this->productMock->expects($this->any())->method('getAttribute')->willReturn($this->attributeMock); $this->helperMock = $this->getMockBuilder('Magento\\Reports\\Model\\Resource\\Helper')->disableOriginalConstructor()->getMock(); $this->viewed = new Viewed($this->contextMock, $this->loggerMock, $this->timezoneMock, $this->flagFactoryMock, $this->dateTimeMock, $this->validatorMock, $this->productMock, $this->helperMock); }
public function testGetIdBySku() { $this->resource->expects($this->once())->method('getIdBySku')->will($this->returnValue(5)); $this->assertEquals(5, $this->model->getIdBySku('someSku')); }
/** * @expectedException \Exception * @expectedExceptionMessage error occurred */ public function testAroundDeleteByIdRollBack() { $this->resourceMock->expects($this->once())->method('beginTransaction'); $this->resourceMock->expects($this->once())->method('rollBack'); $this->model->aroundDelete($this->subjectMock, $this->rollbackClosureMock, $this->productMock, $this->saveOption); }