コード例 #1
0
ファイル: CommentTest.php プロジェクト: nja78/magento2
 /**
  * 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
ファイル: AddressTest.php プロジェクト: nja78/magento2
 /**
  * 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
ファイル: QuoteAddressTest.php プロジェクト: nja78/magento2
 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
ファイル: HistoryTest.php プロジェクト: nja78/magento2
 /**
  * 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));
 }
コード例 #5
0
 /**
  * @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
ファイル: SnapshotTest.php プロジェクト: nja78/magento2
 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
ファイル: OrderTest.php プロジェクト: nja78/magento2
 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);
 }
コード例 #8
0
ファイル: AddressTest.php プロジェクト: nja78/magento2
 /**
  * @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);
 }
コード例 #9
0
ファイル: ItemTest.php プロジェクト: nja78/magento2
 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->adapterMock);
     $this->assertEquals($this->model, $this->model->save($this->quoteItemMock));
 }
コード例 #10
0
ファイル: AbstractEntityTest.php プロジェクト: nja78/magento2
 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);
 }
コード例 #11
0
ファイル: AbstractEntity.php プロジェクト: nja78/magento2
 /**
  * Checks if entity was modified
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return bool
  */
 protected function isModified(\Magento\Framework\Model\AbstractModel $object)
 {
     return $this->entitySnapshot->isModified($object);
 }
コード例 #12
0
ファイル: AbstractCollection.php プロジェクト: nja78/magento2
 /**
  * @inheritdoc
  */
 protected function beforeAddLoadedItem(\Magento\Framework\Object $item)
 {
     $this->entitySnapshot->registerSnapshot($item);
     return $item;
 }