/** * 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); }
/** * 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); }
/** * 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)); }
public function testSave() { $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->once())->method('getStore')->willReturn($this->storeMock); $this->storeMock->expects($this->once())->method('getGroup')->willReturn($this->storeGroupMock); $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); }
public function testSave() { $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); }