예제 #1
0
 /**
  * Test _beforeSaveMethod via save() with failed validation
  *
  * @expectedException \Magento\Framework\Exception\LocalizedException
  * @expectedExceptionMessage Cannot save comment:
  */
 public function testSaveValidationFailed()
 {
     $this->entitySnapshotMock->expects($this->once())->method('isModified')->with($this->commentModelMock)->willReturn(true);
     $this->validatorMock->expects($this->once())->method('validate')->with($this->equalTo($this->commentModelMock))->will($this->returnValue(['warning message']));
     $this->commentResource->save($this->commentModelMock);
     $this->assertTrue(true);
 }
예제 #2
0
 /**
  * test _beforeSaveMethod via save() with failed validation
  *
  * @expectedException \Magento\Framework\Exception\LocalizedException
  * @expectedExceptionMessage We can't save the address:
  */
 public function testSaveValidationFailed()
 {
     $this->entitySnapshotMock->expects($this->once())->method('isModified')->with($this->addressMock)->willReturn(true);
     $this->addressMock->expects($this->any())->method('hasDataChanges')->will($this->returnValue(true));
     $this->validatorMock->expects($this->once())->method('validate')->with($this->equalTo($this->addressMock))->will($this->returnValue(['warning message']));
     $this->addressResource->save($this->addressMock);
 }
예제 #3
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);
 }
예제 #4
0
 /**
  * test _beforeSaveMethod via save()
  * @expectedException \Magento\Framework\Exception\LocalizedException
  * @expectedExceptionMessage Cannot save comment:
  */
 public function testValidate()
 {
     $historyMock = $this->getMock('Magento\\Sales\\Model\\Order\\Status\\History', [], [], '', false);
     $this->entitySnapshotMock->expects($this->once())->method('isModified')->with($historyMock)->willReturn(true);
     $historyMock->expects($this->any())->method('isSaveAllowed')->will($this->returnValue(true));
     $this->validatorMock->expects($this->once())->method('validate')->with($historyMock)->will($this->returnValue(['Some warnings']));
     $this->assertEquals($this->historyResource, $this->historyResource->save($historyMock));
 }
 /**
  * @param array $data
  * @dataProvider fetchItemDataProvider
  */
 public function testFetchItem(array $data)
 {
     $item = $this->getMagentoObject()->setData($data);
     $this->statementMock->expects($this->once())->method('fetch')->willReturn($data);
     if (!$data) {
         $this->entitySnapshot->expects($this->never())->method('registerSnapshot');
         $this->assertEquals(false, $this->subject->fetchItem());
     } else {
         $this->entitySnapshot->expects($this->once())->method('registerSnapshot')->with($item);
         $this->assertEquals($item, $this->subject->fetchItem());
     }
 }
예제 #6
0
 public function testIsModified()
 {
     $entityId = 1;
     $data = ['id' => $entityId, 'name' => 'test', 'description' => '', 'custom_not_present_attribute' => ''];
     $fields = ['id' => [], 'name' => [], 'description' => []];
     $modifiedData = array_merge($data, ['name' => 'newName']);
     $this->model->expects($this->any())->method('getId')->willReturn($entityId);
     $this->entityMetadata->expects($this->exactly(2))->method('getFields')->with($this->model)->willReturn($fields);
     $this->model->setData($data);
     $this->entitySnapshot->registerSnapshot($this->model);
     $this->model->setData($modifiedData);
     $this->assertTrue($this->entitySnapshot->isModified($this->model));
     $this->entitySnapshot->registerSnapshot($this->model);
     $this->assertFalse($this->entitySnapshot->isModified($this->model));
 }
예제 #7
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->connectionMock);
     $this->connectionMock->expects($this->any())->method('quoteInto');
     $this->connectionMock->expects($this->any())->method('describeTable')->will($this->returnValue([]));
     $this->connectionMock->expects($this->any())->method('update');
     $this->connectionMock->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);
 }
예제 #8
0
 /**
  * {@inheritdoc}
  */
 public function isModified(DataObject $entity)
 {
     $result = parent::isModified($entity);
     if (!$result && !$entity->getIsCustomerSaveTransaction() && $this->isAddressDefault($entity)) {
         return true;
     }
     return $result;
 }
예제 #9
0
 public function testSaveModifiedItem()
 {
     $this->entitySnapshotMock->expects($this->exactly(2))->method('isModified')->with($this->quoteItemMock)->willReturn(true);
     $this->quoteItemMock->expects($this->once())->method('isOptionsSaved')->willReturn(false);
     $this->quoteItemMock->expects($this->once())->method('saveItemOptions');
     $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->connectionMock);
     $this->assertEquals($this->model, $this->model->save($this->quoteItemMock));
 }
예제 #10
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);
 }
 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);
 }
 /**
  * @inheritdoc
  * @codeCoverageIgnore
  */
 protected function beforeAddLoadedItem(\Magento\Framework\DataObject $item)
 {
     $this->entitySnapshot->registerSnapshot($item);
     return $item;
 }
예제 #13
0
 /**
  * Checks if entity was modified
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return bool
  * @codeCoverageIgnore
  */
 protected function isModified(\Magento\Framework\Model\AbstractModel $object)
 {
     return $this->entitySnapshot->isModified($object);
 }