public function testCheckContactUsFormRedirectsCustomerWithWarningMessageWhenCaptchaIsRequiredAndInvalid()
 {
     $formId = 'contact_us';
     $captchaValue = 'some-value';
     $warningMessage = 'Incorrect CAPTCHA.';
     $redirectRoutePath = 'contact/index/index';
     $redirectUrl = 'http://magento.com/contacts/';
     $postData = ['name' => 'Some Name'];
     $request = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false);
     $response = $this->getMock('Magento\\Framework\\App\\Response\\Http', [], [], '', false);
     $request->expects($this->any())->method('getPost')->with(\Magento\Captcha\Helper\Data::INPUT_NAME_FIELD_VALUE, null)->willReturn([$formId => $captchaValue]);
     $request->expects($this->once())->method('getPostValue')->willReturn($postData);
     $this->redirectMock->expects($this->once())->method('redirect')->with($response, $redirectRoutePath, [])->willReturn($redirectUrl);
     $controller = $this->getMock('Magento\\Framework\\App\\Action\\Action', [], [], '', false);
     $controller->expects($this->any())->method('getRequest')->willReturn($request);
     $controller->expects($this->any())->method('getResponse')->willReturn($response);
     $this->captchaMock->expects($this->any())->method('isRequired')->willReturn(true);
     $this->captchaMock->expects($this->once())->method('isCorrect')->with($captchaValue)->willReturn(false);
     $this->captchaStringResolverMock->expects($this->once())->method('resolve')->with($request, $formId)->willReturn($captchaValue);
     $this->helperMock->expects($this->any())->method('getCaptcha')->with($formId)->willReturn($this->captchaMock);
     $this->messageManagerMock->expects($this->once())->method('addError')->with($warningMessage);
     $this->actionFlagMock->expects($this->once())->method('set')->with('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
     $this->dataPersistorMock->expects($this->once())->method('set')->with($formId, $postData);
     $this->checkContactUsFormObserver->execute(new \Magento\Framework\Event\Observer(['controller_action' => $controller]));
 }
 public function testGetDataWithNoItems()
 {
     $scope = 'websites';
     $scopeId = 1;
     $this->request->expects($this->exactly(2))->method('getParam')->willReturnMap([['scope', null, $scope], ['scope_id', null, $scopeId]]);
     $this->designConfigRepository->expects($this->once())->method('getByScope')->with($scope, $scopeId)->willReturn($this->designConfig);
     $this->designConfig->expects($this->once())->method('getExtensionAttributes')->willReturn($this->designConfigExtension);
     $this->designConfigExtension->expects($this->once())->method('getDesignConfigData')->willReturn([$this->designConfigData]);
     $this->designConfigData->expects($this->once())->method('getFieldConfig')->willReturn(['field' => 'field']);
     $this->designConfigData->expects($this->once())->method('getValue')->willReturn('value');
     $this->dataPersistor->expects($this->once())->method('get')->with('theme_design_config')->willReturn(['scope' => $scope, 'scope_id' => $scopeId]);
     $result = $this->model->getData();
     $this->assertTrue(is_array($result));
     $this->assertTrue(array_key_exists($scope, $result));
     $this->assertTrue(is_array($result[$scope]));
     $this->assertTrue(array_key_exists('scope', $result[$scope]));
     $this->assertTrue(array_key_exists('scope_id', $result[$scope]));
     $this->assertEquals($scope, $result[$scope]['scope']);
     $this->assertEquals($scopeId, $result[$scope]['scope_id']);
 }
Beispiel #3
0
 public function testSaveActionThrowsException()
 {
     $this->requestMock->expects($this->any())->method('getPostValue')->willReturn(['block_id' => 1]);
     $this->requestMock->expects($this->atLeastOnce())->method('getParam')->willReturnMap([['block_id', null, 1], ['back', null, true]]);
     $this->objectManagerMock->expects($this->atLeastOnce())->method('create')->with($this->equalTo('Magento\\Cms\\Model\\Block'))->willReturn($this->blockMock);
     $this->blockMock->expects($this->any())->method('load')->willReturnSelf();
     $this->blockMock->expects($this->any())->method('getId')->willReturn(true);
     $this->blockMock->expects($this->once())->method('setData');
     $this->blockMock->expects($this->once())->method('save')->willThrowException(new \Exception('Error message.'));
     $this->messageManagerMock->expects($this->never())->method('addSuccess');
     $this->messageManagerMock->expects($this->once())->method('addException');
     $this->dataPersistorMock->expects($this->any())->method('set')->with('cms_block', ['block_id' => 1]);
     $this->resultRedirect->expects($this->atLeastOnce())->method('setPath')->with('*/*/edit', ['block_id' => $this->blockId])->willReturnSelf();
     $this->assertSame($this->resultRedirect, $this->saveController->execute());
 }
 public function testSaveWithException()
 {
     $scope = 'sadfa';
     $scopeId = 0;
     $this->redirectFactory->expects($this->once())->method('create')->willReturn($this->redirect);
     $this->request->expects($this->exactly(2))->method('getParam')->withConsecutive(['scope'], ['scope_id'])->willReturnOnConsecutiveCalls($scope, $scopeId);
     $this->request->expects($this->once())->method('getParams')->willReturn(['header_default_title' => 'Default title']);
     $this->request->expects($this->once())->method('getFiles')->willReturn($this->fileParams);
     $this->fileParams->expects($this->once())->method('toArray')->willReturn(['header_logo' => ['tmp_name' => '', 'error' => 4]]);
     $this->configFactory->expects($this->once())->method('create')->with($scope, $scopeId, ['header_default_title' => 'Default title'])->willReturn($this->designConfig);
     $exception = new \Exception(__('Exception message'));
     $this->designConfigRepository->expects($this->once())->method('save')->with($this->designConfig)->willThrowException($exception);
     $this->messageManager->expects($this->once())->method('addException')->with($exception, 'Something went wrong while saving this configuration: Exception message');
     $this->dataPersistor->expects($this->once())->method('set')->with('theme_design_config', ['header_default_title' => 'Default title']);
     $this->redirect->expects($this->once())->method('setPath')->with('theme/design_config/edit', ['scope' => $scope, 'scope_id' => $scopeId]);
     $this->assertSame($this->redirect, $this->controller->execute());
 }
Beispiel #5
0
 public function testExecuteValidPost()
 {
     $post = ['name' => 'Name', 'comment' => 'Comment', 'email' => '*****@*****.**', 'hideit' => null];
     $this->dataPersistorMock->expects($this->once())->method('clear')->with('contact_us');
     $this->requestMock->expects($this->any())->method('getPostValue')->willReturn($post);
     $transport = $this->getMock('\\Magento\\Framework\\Mail\\TransportInterface', [], [], '', false);
     $this->transportBuilderMock->expects($this->once())->method('setTemplateIdentifier')->will($this->returnSelf());
     $this->transportBuilderMock->expects($this->once())->method('setTemplateOptions')->with(['area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID])->will($this->returnSelf());
     $this->transportBuilderMock->expects($this->once())->method('setTemplateVars')->will($this->returnSelf());
     $this->transportBuilderMock->expects($this->once())->method('setFrom')->will($this->returnSelf());
     $this->transportBuilderMock->expects($this->once())->method('addTo')->will($this->returnSelf());
     $this->transportBuilderMock->expects($this->once())->method('setReplyTo')->with($post['email'])->will($this->returnSelf());
     $this->transportBuilderMock->expects($this->once())->method('getTransport')->willReturn($transport);
     $transport->expects($this->once())->method('sendMessage');
     $this->inlineTranslationMock->expects($this->once())->method('resume');
     $this->inlineTranslationMock->expects($this->once())->method('suspend');
     $this->controller->execute();
 }