예제 #1
0
 /**
  * Retrieve all necessary objects mocks which used inside customer storage
  *
  * @return array
  */
 protected function _getModelDependencies()
 {
     $select = $this->getMockBuilder('Magento\\Framework\\DB\\Select')->disableOriginalConstructor()->setMethods(['from'])->getMock();
     $select->expects($this->any())->method('from')->will($this->returnCallback(array($this, 'validateFrom')));
     $customerCollection = $this->getMockBuilder('Magento\\Customer\\Model\\Resource\\Customer\\Collection')->disableOriginalConstructor()->setMethods(['load', 'removeAttributeToSelect', 'getResource', 'getSelect'])->getMock();
     $resourceStub = new \Magento\Framework\Object();
     $resourceStub->setEntityTable($this->_entityTable);
     $customerCollection->expects($this->once())->method('getResource')->will($this->returnValue($resourceStub));
     $customerCollection->expects($this->once())->method('getSelect')->will($this->returnValue($select));
     $byPagesIterator = $this->getMock('stdClass', array('iterate'));
     $byPagesIterator->expects($this->once())->method('iterate')->will($this->returnCallback(array($this, 'iterate')));
     return array('customer_collection' => $customerCollection, 'collection_by_pages_iterator' => $byPagesIterator, 'page_size' => 10);
 }
예제 #2
0
 public function testWalkAttributes()
 {
     $code = 'test_attr';
     $set = 10;
     $object = $this->getMock('Magento\\Catalog\\Model\\Product', array('__wakeup'), array(), '', false);
     $object->setData(array('test_attr' => 'test_attr', 'attribute_set_id' => $set));
     $entityType = new \Magento\Framework\Object();
     $entityType->setEntityTypeCode('test');
     $entityType->setEntityTypeId(0);
     $entityType->setEntityTable('table');
     $attributes = $this->_getAttributes();
     $attribute = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute', array('isInSet', 'getBackend', '__wakeup'), array(), '', false);
     $attribute->setAttributeId($code);
     $attribute->setAttributeCode($code);
     $attribute->expects($this->once())->method('isInSet')->with($this->equalTo($set))->will($this->returnValue(false));
     $attributes[$code] = $attribute;
     /** @var $model \Magento\Catalog\Model\Resource\AbstractResource */
     $model = $this->getMock('Magento\\Catalog\\Model\\Resource\\AbstractResource', array('getAttributesByCode'), array($this->getMock('Magento\\Framework\\App\\Resource', array(), array(), '', false, false), $this->getMock('Magento\\Eav\\Model\\Config', array(), array(), '', false, false), $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute\\Set', array(), array(), '', false, false), $this->getMock('Magento\\Framework\\Locale\\FormatInterface'), $this->getMock('Magento\\Eav\\Model\\Resource\\Helper', array(), array(), '', false, false), $this->getMock('Magento\\Framework\\Validator\\UniversalFactory', array(), array(), '', false, false), $this->getMock('Magento\\Framework\\StoreManagerInterface', array(), array(), '', false), $this->getMock('Magento\\Catalog\\Model\\Factory', array(), array(), '', false), array()));
     $model->expects($this->once())->method('getAttributesByCode')->will($this->returnValue($attributes));
     $model->walkAttributes('backend/afterSave', array($object));
 }
예제 #3
0
 /**
  * @param string $attributeCode
  * @param int $attributeSetId
  * @param array $productData
  * @param array $productOrigData
  *
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  * @dataProvider productAttributesDataProvider
  */
 public function testSave($attributeCode, $attributeSetId, $productData, $productOrigData)
 {
     $object = $this->getMock('Magento\\Catalog\\Model\\Product', ['getOrigData', '__wakeup', 'beforeSave', 'afterSave', 'validateBeforeSave'], [], '', false);
     $object->setEntityTypeId(1);
     foreach ($productData as $key => $value) {
         $object->setData($key, $value);
     }
     $object->expects($this->any())->method('getOrigData')->will($this->returnValue($productOrigData));
     $entityType = new \Magento\Framework\Object();
     $entityType->setEntityTypeCode('test');
     $entityType->setEntityTypeId(0);
     $entityType->setEntityTable('table');
     $attributes = $this->_getAttributes();
     $attribute = $this->_getAttributeMock($attributeCode, $attributeSetId);
     /** @var $backendModel \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend */
     $backendModel = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\AbstractBackend', ['getBackend', 'getBackendTable', 'getAffectedFields', 'isStatic', 'getEntityValueId', 'getEntityIdField']);
     $backendModel->expects($this->once())->method('getAffectedFields')->will($this->returnValue(['test_table' => [['value_id' => 0, 'attribute_id' => $attributeCode]]]));
     $backendModel->expects($this->any())->method('isStatic')->will($this->returnValue(false));
     $backendModel->expects($this->never())->method('getEntityValueId');
     $backendModel->expects(isset($productData['entity_id']) ? $this->never() : $this->once())->method('getEntityIdField')->will($this->returnValue('entity_id'));
     $backendModel->setAttribute($attribute);
     $attribute->expects($this->any())->method('getBackend')->will($this->returnValue($backendModel));
     $attribute->setId(222);
     $attributes[$attributeCode] = $attribute;
     $eavConfig = $this->getMockBuilder('Magento\\Eav\\Model\\Config')->disableOriginalConstructor()->getMock();
     $objectManager = new ObjectManager($this);
     $this->entitySnapshot->expects($this->once())->method('isModified')->willReturn(true);
     $this->entitySnapshot->expects($this->once())->method('registerSnapshot')->with($object);
     $this->entityRelationComposite->expects($this->once())->method('processRelations')->with($object);
     $arguments = $objectManager->getConstructArguments('Magento\\Eav\\Model\\Entity\\VersionControl\\AbstractEntity', ['eavConfig' => $eavConfig, 'entitySnapshot' => $this->entitySnapshot, 'entityRelationComposite' => $this->entityRelationComposite, 'data' => ['type' => $entityType, 'entityTable' => 'entityTable', 'attributesByCode' => $attributes]]);
     /** @var $model AbstractEntity|\PHPUnit_Framework_MockObject_MockObject */
     $model = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\VersionControl\\AbstractEntity')->setConstructorArgs($arguments)->setMethods(['_getValue', 'beginTransaction', 'commit', 'rollback'])->getMock();
     $model->expects($this->any())->method('_getValue')->will($this->returnValue($eavConfig));
     $eavConfig->expects($this->any())->method('getAttribute')->will($this->returnCallback(function ($entityType, $attributeCode) use($attributes) {
         return $entityType && isset($attributes[$attributeCode]) ? $attributes[$attributeCode] : null;
     }));
     $model->setConnection($this->_getAdapterMock());
     $model->isPartialSave(true);
     $model->save($object);
 }
예제 #4
0
 public function testWalkAttributes()
 {
     $objectManager = new ObjectManager($this);
     $code = 'test_attr';
     $set = 10;
     $object = $this->getMock('Magento\\Catalog\\Model\\Product', ['__wakeup'], [], '', false);
     $object->setData(['test_attr' => 'test_attr', 'attribute_set_id' => $set]);
     $entityType = new \Magento\Framework\Object();
     $entityType->setEntityTypeCode('test');
     $entityType->setEntityTypeId(0);
     $entityType->setEntityTable('table');
     $attributes = $this->_getAttributes();
     $attribute = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute', ['isInSet', 'getBackend', '__wakeup'], [], '', false);
     $attribute->setAttributeId($code);
     $attribute->setAttributeCode($code);
     $attribute->expects($this->once())->method('isInSet')->with($this->equalTo($set))->will($this->returnValue(false));
     $attributes[$code] = $attribute;
     /** @var $model \Magento\Catalog\Model\Resource\AbstractResource */
     $arguments = $objectManager->getConstructArguments('Magento\\Catalog\\Model\\Resource\\AbstractResource');
     $model = $this->getMock('Magento\\Catalog\\Model\\Resource\\AbstractResource', ['getAttributesByCode'], $arguments);
     $model->expects($this->once())->method('getAttributesByCode')->will($this->returnValue($attributes));
     $model->walkAttributes('backend/afterSave', [$object]);
 }
예제 #5
0
 /**
  * @param string $attributeCode
  * @param int $attributeSetId
  * @param array $productData
  * @param array $productOrigData
  *
  * @dataProvider productAttributesDataProvider
  */
 public function testSave($attributeCode, $attributeSetId, $productData, $productOrigData)
 {
     $object = $this->getMock('Magento\\Catalog\\Model\\Product', array('getOrigData', '__wakeup'), array(), '', false);
     $object->setEntityTypeId(1);
     $object->setData($productData);
     $object->expects($this->any())->method('getOrigData')->will($this->returnValue($productOrigData));
     $entityType = new \Magento\Framework\Object();
     $entityType->setEntityTypeCode('test');
     $entityType->setEntityTypeId(0);
     $entityType->setEntityTable('table');
     $attributes = $this->_getAttributes();
     $attribute = $this->_getAttributeMock($attributeCode, $attributeSetId);
     $logger = $this->getMock('Magento\\Framework\\Logger', array(), array(), '', false);
     /** @var $backendModel \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend */
     $backendModel = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\AbstractBackend', array('getBackend', 'getBackendTable', 'getAffectedFields', 'isStatic', 'getEntityValueId', 'getEntityIdField'), array($logger));
     $backendModel->expects($this->once())->method('getAffectedFields')->will($this->returnValue(array('test_table' => array(array('value_id' => 0, 'attribute_id' => $attributeCode)))));
     $backendModel->expects($this->any())->method('isStatic')->will($this->returnValue(false));
     $backendModel->expects($this->never())->method('getEntityValueId');
     $backendModel->expects(isset($productData['entity_id']) ? $this->never() : $this->once())->method('getEntityIdField')->will($this->returnValue('entity_id'));
     $backendModel->setAttribute($attribute);
     $attribute->expects($this->any())->method('getBackend')->will($this->returnValue($backendModel));
     $attribute->setId(222);
     $attributes[$attributeCode] = $attribute;
     $eavConfig = $this->getMockBuilder('Magento\\Eav\\Model\\Config')->disableOriginalConstructor()->getMock();
     $data = array($this->getMock('Magento\\Framework\\App\\Resource', array(), array(), '', false), $eavConfig, $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute\\Set', array(), array(), '', false), $this->getMock('Magento\\Framework\\Locale\\FormatInterface'), $this->getMock('Magento\\Eav\\Model\\Resource\\Helper', array(), array(), '', false), $this->getMock('Magento\\Framework\\Validator\\UniversalFactory', array(), array(), '', false), array('type' => $entityType, 'entityTable' => 'entityTable', 'attributesByCode' => $attributes));
     /** @var $model \Magento\Framework\Model\AbstractModel|\PHPUnit_Framework_MockObject_MockObject */
     $model = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\AbstractEntity')->setConstructorArgs($data)->setMethods(['_getValue'])->getMock();
     $model->expects($this->any())->method('_getValue')->will($this->returnValue($eavConfig));
     $eavConfig->expects($this->any())->method('getAttribute')->will($this->returnCallback(function ($entityType, $attributeCode) use($attributes) {
         return $entityType && isset($attributes[$attributeCode]) ? $attributes[$attributeCode] : null;
     }));
     $model->setConnection($this->_getAdapterMock());
     $model->isPartialSave(true);
     $model->save($object);
 }