27 private $clientResolverMock;
42 private $resultJsonFactory;
47 private $tagFilterMock;
61 $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
62 $this->requestMock = $this->createPartialMock(\
Magento\Framework\
App\Request\Http::class, [
'getParams']);
65 $context = $this->getMockBuilder(\
Magento\Backend\
App\Action\Context::class)
66 ->setMethods([
'getRequest',
'getResponse',
'getMessageManager',
'getSession'])
71 'request' => $this->requestMock
76 $context->expects($this->once())->method(
'getRequest')->will($this->returnValue($this->requestMock));
77 $context->expects($this->once())->method(
'getResponse')->will($this->returnValue($responseMock));
79 $this->clientResolverMock = $this->getMockBuilder(\
Magento\AdvancedSearch\Model\Client\ClientResolver::class)
80 ->disableOriginalConstructor()
81 ->setMethods([
'create'])
84 $this->clientMock = $this->createMock(\
Magento\AdvancedSearch\Model\Client\ClientInterface::class);
86 $this->resultJson = $this->getMockBuilder(\
Magento\Framework\Controller\Result\Json::class)
87 ->disableOriginalConstructor()
90 $this->resultJsonFactory = $this->getMockBuilder(\
Magento\Framework\Controller\Result\JsonFactory::class)
91 ->disableOriginalConstructor()
92 ->setMethods([
'create'])
95 $this->tagFilterMock = $this->getMockBuilder(\
Magento\Framework\Filter\StripTags::class)
96 ->disableOriginalConstructor()
97 ->setMethods([
'filter'])
102 $this->clientResolverMock,
103 $this->resultJsonFactory,
110 $this->requestMock->expects($this->once())->method(
'getParams')
111 ->will($this->returnValue([
'engine' =>
'']));
113 $this->resultJsonFactory->expects($this->once())->method(
'create')
114 ->will($this->returnValue($this->resultJson));
116 $result = [
'success' =>
false,
'errorMessage' =>
'Missing search engine parameter.'];
118 $this->resultJson->expects($this->once())->method(
'setData')
119 ->with($this->equalTo(
$result));
121 $this->controller->execute();
126 $this->requestMock->expects($this->once())->method(
'getParams')
127 ->will($this->returnValue([
'engine' =>
'engineName']));
129 $this->clientResolverMock->expects($this->once())->method(
'create')
130 ->with($this->equalTo(
'engineName'))
131 ->will($this->returnValue($this->clientMock));
133 $this->clientMock->expects($this->once())->method(
'testConnection')
134 ->will($this->returnValue(
true));
136 $this->resultJsonFactory->expects($this->once())->method(
'create')
137 ->will($this->returnValue($this->resultJson));
139 $result = [
'success' =>
true,
'errorMessage' =>
''];
141 $this->resultJson->expects($this->once())->method(
'setData')
142 ->with($this->equalTo(
$result));
144 $this->controller->execute();
149 $this->requestMock->expects($this->once())->method(
'getParams')
150 ->will($this->returnValue([
'engine' =>
'engineName']));
152 $this->clientResolverMock->expects($this->once())->method(
'create')
153 ->with($this->equalTo(
'engineName'))
154 ->will($this->returnValue($this->clientMock));
156 $this->clientMock->expects($this->once())->method(
'testConnection')
157 ->will($this->returnValue(
false));
159 $this->resultJsonFactory->expects($this->once())->method(
'create')
160 ->will($this->returnValue($this->resultJson));
162 $result = [
'success' =>
false,
'errorMessage' =>
''];
164 $this->resultJson->expects($this->once())->method(
'setData')
165 ->with($this->equalTo(
$result));
167 $this->controller->execute();