24 private $resultFactory;
29 private $taxRateRepository;
36 $this->request = $this->getMockBuilder(\
Magento\Framework\
App\Request\Http::class)
37 ->disableOriginalConstructor()
38 ->setMethods([
'getParam'])
41 $this->resultFactory = $this->getMockBuilder(\
Magento\Framework\Controller\ResultFactory::class)
42 ->disableOriginalConstructor()
43 ->setMethods([
'create'])
46 $this->taxRateRepository = $this->getMockBuilder(\
Magento\Tax\Model\Calculation\RateRepository::class)
47 ->disableOriginalConstructor()
59 'tax_calculation_rate_id' =>
null,
60 'tax_country_id' =>
'US',
62 'tax_postcode' =>
null,
63 'code' =>
'Tax Rate Code',
66 'title[1]' =>
'texas',
70 \
Magento\Tax\Model\Calculation\Rate\Title::class,
71 [
'data' => [
'store_id' => 1,
'value' =>
'texas']]
75 \
Magento\Tax\Model\Calculation\Rate::class,
79 'tax_country_id' =>
'US',
81 'tax_postcode' =>
null,
83 'code' =>
'Tax Rate Code',
84 'titles' => $rateTitles,
89 $this->request->expects($this->any())
91 ->will($this->returnValue($taxRateId));
93 $this->taxRateRepository->expects($this->any())
96 ->will($this->returnValue($rateMock));
98 $taxRateConverter = $this->getMockBuilder(\
Magento\Tax\Model\Calculation\Rate\Converter::class)
99 ->disableOriginalConstructor()
102 $taxRateConverter->expects($this->any())
103 ->method(
'createArrayFromServiceObject')
104 ->with($rateMock,
true)
105 ->willReturn($returnArray);
107 $jsonObject= $this->getMockBuilder(\
Magento\Framework\Controller\Result\Json::class)
108 ->disableOriginalConstructor()
109 ->setMethods([
'setData'])
112 $jsonObject->expects($this->once())
114 ->with([
'success' =>
true,
'error_message' =>
'',
'result'=>
118 $this->resultFactory->expects($this->any())
120 ->with(\
Magento\Framework\Controller\ResultFactory::TYPE_JSON)
121 ->willReturn($jsonObject);
124 \
Magento\Tax\Controller\Adminhtml\Rate\AjaxLoad::class,
126 'taxRateRepository' => $this->taxRateRepository,
127 'taxRateConverter' => $taxRateConverter,
128 'request' => $this->request,
129 'resultFactory' => $this->resultFactory,
134 $this->assertSame($jsonObject, $notification->execute());
143 $exceptionMessage=
'No such entity with taxRateId = '.$taxRateId;
148 $this->request->expects($this->any())
150 ->will($this->returnValue($taxRateId));
152 $this->taxRateRepository->expects($this->any())
155 ->willThrowException($noSuchEntityEx);
157 $jsonObject= $this->getMockBuilder(\
Magento\Framework\Controller\Result\Json::class)
158 ->disableOriginalConstructor()
159 ->setMethods([
'setData'])
162 $jsonObject->expects($this->once())
166 'error_message' => $exceptionMessage,
169 $this->resultFactory->expects($this->any())
171 ->with(\
Magento\Framework\Controller\ResultFactory::TYPE_JSON)
172 ->willReturn($jsonObject);
175 \
Magento\Tax\Controller\Adminhtml\Rate\AjaxLoad::class,
177 'taxRateRepository' => $this->taxRateRepository,
178 'request' => $this->request,
179 'resultFactory' => $this->resultFactory,
184 $this->assertSame($jsonObject, $notification->execute());
193 $exceptionMessage=
__(
'An error occurred while loading this tax rate.');
194 $noSuchEntityEx= new \Exception();
198 $this->request->expects($this->any())
200 ->will($this->returnValue($taxRateId));
202 $this->taxRateRepository->expects($this->any())
205 ->willThrowException($noSuchEntityEx);
207 $jsonObject= $this->getMockBuilder(\
Magento\Framework\Controller\Result\Json::class)
208 ->disableOriginalConstructor()
209 ->setMethods([
'setData'])
212 $jsonObject->expects($this->once())
216 'error_message' => $exceptionMessage,
219 $this->resultFactory->expects($this->any())
221 ->with(\
Magento\Framework\Controller\ResultFactory::TYPE_JSON)
222 ->willReturn($jsonObject);
225 \
Magento\Tax\Controller\Adminhtml\Rate\AjaxLoad::class,
227 'taxRateRepository' => $this->taxRateRepository,
228 'request' => $this->request,
229 'resultFactory' => $this->resultFactory,
234 $this->assertSame($jsonObject, $notification->execute());
testExecuteLocalizedException()