Exemple #1
0
 public function testSave()
 {
     $this->entitySnapshotMock->expects($this->once())->method('isModified')->with($this->addressMock)->willReturn(true);
     $this->entitySnapshotMock->expects($this->once())->method('registerSnapshot')->with($this->addressMock);
     $this->relationCompositeMock->expects($this->once())->method('processRelations')->with($this->addressMock);
     $this->addressResource->save($this->addressMock);
 }
 public function testProcessRelations()
 {
     $this->relationProcessorMock->expects($this->once())->method('processRelation')->with($this->modelMock);
     $this->modelMock->expects($this->once())->method('getEventPrefix')->willReturn('custom_event_prefix');
     $this->eventManagerMock->expects($this->once())->method('dispatch')->with('custom_event_prefix_process_relation', ['object' => $this->modelMock]);
     $this->entityRelationComposite->processRelations($this->modelMock);
 }
Exemple #3
0
 public function testSave()
 {
     $this->orderMock->expects($this->exactly(3))->method('getId')->willReturn(null);
     $this->orderItemMock->expects($this->once())->method('getChildrenItems')->willReturn([]);
     $this->orderItemMock->expects($this->once())->method('getQuoteParentItemId')->willReturn(null);
     $this->orderMock->expects($this->once())->method('setTotalItemCount')->with(1);
     $this->storeGroupMock->expects($this->once())->method('getDefaultStoreId')->willReturn(1);
     $this->orderMock->expects($this->once())->method('getAllItems')->willReturn([$this->orderItemMock]);
     $this->orderMock->expects($this->once())->method('validateBeforeSave')->willReturnSelf();
     $this->orderMock->expects($this->once())->method('beforeSave')->willReturnSelf();
     $this->orderMock->expects($this->once())->method('isSaveAllowed')->willReturn(true);
     $this->orderMock->expects($this->once())->method('getEntityType')->willReturn('order');
     $this->orderMock->expects($this->exactly(2))->method('getStore')->willReturn($this->storeMock);
     $this->storeMock->expects($this->exactly(2))->method('getGroup')->willReturn($this->storeGroupMock);
     $this->storeMock->expects($this->once())->method('getWebsite')->willReturn($this->websiteMock);
     $this->storeGroupMock->expects($this->once())->method('getDefaultStoreId')->willReturn(1);
     $this->salesSequenceManagerMock->expects($this->once())->method('getSequence')->with('order', 1)->willReturn($this->salesSequenceMock);
     $this->salesSequenceMock->expects($this->once())->method('getNextValue')->willReturn('10000001');
     $this->orderMock->expects($this->once())->method('setIncrementId')->with('10000001')->willReturnSelf();
     $this->orderMock->expects($this->once())->method('getIncrementId')->willReturn(null);
     $this->orderMock->expects($this->once())->method('getData')->willReturn(['increment_id' => '10000001']);
     $this->objectRelationProcessorMock->expects($this->once())->method('validateDataIntegrity')->with(null, ['increment_id' => '10000001']);
     $this->relationCompositeMock->expects($this->once())->method('processRelations')->with($this->orderMock);
     $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->adapterMock);
     $this->adapterMock->expects($this->any())->method('quoteInto');
     $this->adapterMock->expects($this->any())->method('describeTable')->will($this->returnValue([]));
     $this->adapterMock->expects($this->any())->method('update');
     $this->adapterMock->expects($this->any())->method('lastInsertId');
     $this->orderMock->expects($this->any())->method('getId')->will($this->returnValue(1));
     $this->entitySnapshotMock->expects($this->once())->method('isModified')->with($this->orderMock)->will($this->returnValue(true));
     $this->resource->save($this->orderMock);
 }
Exemple #4
0
 /**
  * @param $addressId
  * @param $isDefaultBilling
  * @param $isDefaultShipping
  *
  * @dataProvider getSaveDataProvider
  */
 public function testSave($addressId, $isDefaultBilling, $isDefaultShipping)
 {
     /** @var $address \Magento\Customer\Model\Address|\PHPUnit_Framework_MockObject_MockObject */
     $address = $this->getMock('Magento\\Customer\\Model\\Address', ['__wakeup', 'getId', 'getEntityTypeId', 'getIsDefaultBilling', 'getIsDefaultShipping', 'hasDataChanges', 'validateBeforeSave', 'beforeSave', 'afterSave', 'isSaveAllowed'], [], '', false);
     $this->entitySnapshotMock->expects($this->once())->method('isModified')->willReturn(true);
     $this->entityRelationCompositeMock->expects($this->once())->method('processRelations');
     $address->expects($this->once())->method('isSaveAllowed')->willReturn(true);
     $address->expects($this->once())->method('validateBeforeSave');
     $address->expects($this->once())->method('beforeSave');
     $address->expects($this->once())->method('afterSave');
     $address->expects($this->any())->method('getEntityTypeId')->willReturn('3');
     $address->expects($this->any())->method('getId')->willReturn($addressId);
     $address->expects($this->any())->method('getIsDefaultShipping')->willReturn($isDefaultShipping);
     $address->expects($this->any())->method('getIsDefaultBilling')->willReturn($isDefaultBilling);
     $this->addressResource->setType('customer_address');
     $this->addressResource->save($address);
 }
Exemple #5
0
 /**
  * @inheritdoc
  */
 public function save(\Magento\Framework\Model\AbstractModel $object)
 {
     /**
      * Direct deleted items to delete method
      */
     if ($object->isDeleted()) {
         return $this->delete($object);
     }
     $this->beginTransaction();
     try {
         if (!$this->isModified($object)) {
             $this->entityRelationComposite->processRelations($object);
             $this->commit();
             return $this;
         }
         $object->validateBeforeSave();
         $object->beforeSave();
         if ($object->isSaveAllowed()) {
             if (!$this->isPartialSave()) {
                 $this->loadAllAttributes($object);
             }
             if ($this->getEntityTable() == \Magento\Eav\Model\Entity::DEFAULT_ENTITY_TABLE && !$object->getEntityTypeId()) {
                 $object->setEntityTypeId($this->getTypeId());
             }
             $object->setParentId((int) $object->getParentId());
             $this->objectRelationProcessor->validateDataIntegrity($this->getEntityTable(), $object->getData());
             $this->_beforeSave($object);
             $this->_processSaveData($this->_collectSaveData($object));
             $this->_afterSave($object);
             $this->entitySnapshot->registerSnapshot($object);
             $object->afterSave();
             $this->entityRelationComposite->processRelations($object);
         }
         $this->addCommitCallback([$object, 'afterCommitCallback'])->commit();
         $object->setHasDataChanges(false);
     } catch (\Exception $e) {
         $this->rollBack();
         $object->setHasDataChanges(true);
         throw $e;
     }
     return $this;
 }
 public function testSaveNotModified()
 {
     $objectManager = new ObjectManager($this);
     /** @var $object \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject */
     $object = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false);
     $arguments = $objectManager->getConstructArguments('Magento\\Eav\\Model\\Entity\\VersionControl\\AbstractEntity', ['entitySnapshot' => $this->entitySnapshot, 'entityRelationComposite' => $this->entityRelationComposite]);
     /** @var $model AbstractEntity|\PHPUnit_Framework_MockObject_MockObject */
     $model = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\VersionControl\\AbstractEntity')->setConstructorArgs($arguments)->setMethods(['beginTransaction', 'commit'])->getMock();
     $this->entitySnapshot->expects($this->once())->method('isModified')->willReturn(false);
     $this->entitySnapshot->expects($this->never())->method('registerSnapshot');
     $this->entityRelationComposite->expects($this->once())->method('processRelations')->with($object);
     $model->save($object);
 }