|
5 | 5 | */
|
6 | 6 | namespace Magento\CatalogSearch\Test\Unit\Controller\Advanced;
|
7 | 7 |
|
| 8 | +/** |
| 9 | + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
| 10 | + */ |
8 | 11 | class ResultTest extends \PHPUnit\Framework\TestCase
|
9 | 12 | {
|
10 | 13 | public function testResultActionFiltersSetBeforeLoadLayout()
|
@@ -49,4 +52,90 @@ function ($added) use (&$filters) {
|
49 | 52 | );
|
50 | 53 | $instance->execute();
|
51 | 54 | }
|
| 55 | + |
| 56 | + public function testUrlSetOnException() |
| 57 | + { |
| 58 | + $redirectResultMock = $this->createMock(\Magento\Framework\Controller\Result\Redirect::class); |
| 59 | + $redirectResultMock->expects($this->once()) |
| 60 | + ->method('setUrl'); |
| 61 | + |
| 62 | + $redirectFactoryMock = $this->getMockBuilder(\Magento\Framework\Controller\Result\RedirectFactory::class) |
| 63 | + ->setMethods(['create']) |
| 64 | + ->disableOriginalConstructor() |
| 65 | + ->getMock(); |
| 66 | + |
| 67 | + $redirectFactoryMock->expects($this->any()) |
| 68 | + ->method('create') |
| 69 | + ->willReturn($redirectResultMock); |
| 70 | + |
| 71 | + $catalogSearchAdvanced = $this->createPartialMock( |
| 72 | + \Magento\CatalogSearch\Model\Advanced::class, |
| 73 | + ['addFilters'] |
| 74 | + ); |
| 75 | + |
| 76 | + $catalogSearchAdvanced->expects($this->once())->method('addFilters')->will( |
| 77 | + $this->throwException(new \Magento\Framework\Exception\LocalizedException( |
| 78 | + new \Magento\Framework\Phrase("Test Exception") |
| 79 | + )) |
| 80 | + ); |
| 81 | + |
| 82 | + $responseMock = $this->createMock(\Magento\Framework\Webapi\Response::class); |
| 83 | + $requestMock = $this->createPartialMock( |
| 84 | + \Magento\Framework\App\Request\Http::class, |
| 85 | + ['getQueryValue'] |
| 86 | + ); |
| 87 | + $requestMock->expects($this->any())->method('getQueryValue')->willReturn(['key' => 'value']); |
| 88 | + |
| 89 | + $redirectMock = $this->createMock(\Magento\Framework\App\Response\RedirectInterface::class); |
| 90 | + $redirectMock->expects($this->any())->method('error')->with('urlstring'); |
| 91 | + |
| 92 | + $messageManagerMock = $this->createMock(\Magento\Framework\Message\Manager::class); |
| 93 | + |
| 94 | + $eventManagerMock = $this->createMock(\Magento\Framework\Event\ManagerInterface::class); |
| 95 | + |
| 96 | + $contextMock = $this->createMock(\Magento\Framework\App\Action\Context::class); |
| 97 | + $contextMock->expects($this->any()) |
| 98 | + ->method('getRequest') |
| 99 | + ->willReturn($requestMock); |
| 100 | + $contextMock->expects($this->any()) |
| 101 | + ->method('getResponse') |
| 102 | + ->willReturn($responseMock); |
| 103 | + $contextMock->expects($this->any()) |
| 104 | + ->method('getRedirect') |
| 105 | + ->willReturn($redirectMock); |
| 106 | + $contextMock->expects($this->any()) |
| 107 | + ->method('getMessageManager') |
| 108 | + ->willReturn($messageManagerMock); |
| 109 | + $contextMock->expects($this->any()) |
| 110 | + ->method('getEventManager') |
| 111 | + ->willReturn($eventManagerMock); |
| 112 | + $contextMock->expects($this->any()) |
| 113 | + ->method('getResultRedirectFactory') |
| 114 | + ->willReturn($redirectFactoryMock); |
| 115 | + |
| 116 | + $urlMock = $this->createMock(\Magento\Framework\Url::class); |
| 117 | + $urlMock->expects($this->once()) |
| 118 | + ->method('addQueryParams') |
| 119 | + ->willReturnSelf(); |
| 120 | + $urlMock->expects($this->once()) |
| 121 | + ->method('getUrl') |
| 122 | + ->willReturn("urlstring"); |
| 123 | + |
| 124 | + $urlFactoryMock = $this->createMock(\Magento\Framework\UrlFactory::class); |
| 125 | + $urlFactoryMock->expects($this->once()) |
| 126 | + ->method('create') |
| 127 | + ->will($this->returnValue($urlMock)); |
| 128 | + |
| 129 | + $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); |
| 130 | + |
| 131 | + /** @var \Magento\CatalogSearch\Controller\Advanced\Result $instance */ |
| 132 | + $instance = $objectManager->getObject( |
| 133 | + \Magento\CatalogSearch\Controller\Advanced\Result::class, |
| 134 | + ['context' => $contextMock, |
| 135 | + 'catalogSearchAdvanced' => $catalogSearchAdvanced, |
| 136 | + 'urlFactory' => $urlFactoryMock |
| 137 | + ] |
| 138 | + ); |
| 139 | + $this->assertEquals($redirectResultMock, $instance->execute()); |
| 140 | + } |
52 | 141 | }
|
0 commit comments