Esempio n. 1
0
 /**
  * Check if validation throws a localized catched exception in case of incorrect id
  */
 public function testExecuteException()
 {
     $taxRateId = 999;
     $exceptionMessage = __('An error occurred while loading this tax rate.');
     $noSuchEntityEx = new \Exception();
     $objectManager = new ObjectManager($this);
     $this->request->expects($this->any())->method('getParam')->will($this->returnValue($taxRateId));
     $this->taxRateRepository->expects($this->any())->method('get')->with($taxRateId)->willThrowException($noSuchEntityEx);
     $jsonObject = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Json')->disableOriginalConstructor()->setMethods(['setData'])->getMock();
     $jsonObject->expects($this->once())->method('setData')->with(['success' => false, 'error_message' => $exceptionMessage]);
     $this->resultFactory->expects($this->any())->method('create')->with(\Magento\Framework\Controller\ResultFactory::TYPE_JSON)->willReturn($jsonObject);
     $notification = $objectManager->getObject('Magento\\Tax\\Controller\\Adminhtml\\Rate\\AjaxLoad', ['taxRateRepository' => $this->taxRateRepository, 'request' => $this->request, 'resultFactory' => $this->resultFactory]);
     //exception thrown with catch
     $this->assertSame($jsonObject, $notification->execute());
 }
 /**
  * @expectedException \Magento\Framework\Exception\InputException
  * @expectedExceptionMessage One or more input exceptions have occurred.
  */
 public function testValidate()
 {
     $regionId = 2;
     $rateTitles = ['Label 1', 'Label 2'];
     $regionMock = $this->getMock('Magento\\Directory\\Model\\Region', [], [], '', false);
     $regionMock->expects($this->any())->method('getId')->will($this->returnValue(''));
     $regionMock->expects($this->any())->method('load')->with($regionId)->will($this->returnSelf());
     $this->regionFactoryMock->expects($this->once())->method('create')->will($this->returnValue($regionMock));
     $rateMock = $this->getTaxRateMock(['id' => null, 'tax_country_id' => '', 'tax_region_id' => $regionId, 'region_name' => null, 'tax_postcode' => null, 'zip_is_range' => true, 'zip_from' => -90000, 'zip_to' => '', 'rate' => '', 'code' => '', 'titles' => $rateTitles]);
     $this->model->save($rateMock);
 }