Пример #1
0
 /**
  * @dataProvider dataForExecute
  */
 public function testExecute($fileResult, $expectedResult)
 {
     $this->uploaderFactoryMock->expects($this->once())->method('create')->willReturn($this->uploaderMock);
     $this->adapterFactoryMock->expects($this->once())->method('create')->willReturn($this->adapterMock);
     $this->filesystemMock->expects($this->once())->method('getDirectoryRead')->with('media')->willReturn($this->mediaDirectoryMock);
     $this->uploaderMock->expects($this->once())->method('save')->willReturn($fileResult);
     $this->configMock->expects($this->once())->method('getTmpMediaUrl')->with($fileResult['file'])->willReturn('http://domain.com/tpm_dir/m/a/magento.png');
     $this->swatchHelperMock->expects($this->once())->method('moveImageFromTmp')->with('/m/a/magento.png.tmp')->willReturn('/m/a/magento.png');
     $this->swatchHelperMock->expects($this->once())->method('generateSwatchVariations');
     $this->swatchHelperMock->expects($this->once())->method('getSwatchMediaUrl')->willReturn('http://domain.com/media/path/');
     $this->responseMock->expects($this->once())->method('setBody')->willReturn(json_encode($expectedResult));
     $this->controller->execute();
 }
 public function testExecuteException()
 {
     $html = '<script>window.location.href = ' . self::REVIEW_URL . ';</script>';
     $shippingMethod = 'flat_rate';
     $this->requestMock->expects($this->at(0))->method('getParam')->with('isAjax')->willReturn(true);
     $this->requestMock->expects($this->at(1))->method('getParam')->with('shipping_method')->willReturn($shippingMethod);
     $this->setupCart();
     $exceptionMsg = new \Magento\Framework\Phrase('error');
     $exception = new \Magento\Framework\Exception\LocalizedException($exceptionMsg);
     $this->checkoutMock->expects($this->once())->method('updateShippingMethod')->with($shippingMethod)->willThrowException($exception);
     $this->messageManager->expects($this->once())->method('addExceptionMessage')->with($exception, $exceptionMsg);
     $this->responseMock->expects($this->once())->method('setBody')->with($html);
     $this->controller->execute();
 }