_cacheMock = $this->createMock(\Magento\Framework\App\CacheInterface::class); $this->_scopeConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class); $this->_curlFactoryMock = $this->createPartialMock( \Magento\Framework\HTTP\Adapter\CurlFactory::class, ['create'] ); $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $arguments = [ 'cache' => $this->_cacheMock, 'scopeConfig' => $this->_scopeConfigMock, 'curlFactory' => $this->_curlFactoryMock, ]; $this->_messageModel = $objectManagerHelper->getObject( \Magento\AdminNotification\Model\System\Message\Security::class, $arguments ); } /** * * @param $expectedResult * @param $cached * @param $response * @return void * @dataProvider isDisplayedDataProvider */ public function testIsDisplayed($expectedResult, $cached, $response) { $this->_cacheMock->expects($this->any())->method('load')->will($this->returnValue($cached)); $this->_cacheMock->expects($this->any())->method('save')->will($this->returnValue(null)); $httpAdapterMock = $this->createMock(\Magento\Framework\HTTP\Adapter\Curl::class); $httpAdapterMock->expects($this->any())->method('read')->will($this->returnValue($response)); $this->_curlFactoryMock->expects($this->any())->method('create')->will($this->returnValue($httpAdapterMock)); $this->_scopeConfigMock->expects($this->any())->method('getValue')->will($this->returnValue(null)); $this->assertEquals($expectedResult, $this->_messageModel->isDisplayed()); } /** * @return array */ public function isDisplayedDataProvider() { return [ 'cached_case' => [false, true, ''], 'accessible_file' => [true, false, 'HTTP/1.1 200'], 'inaccessible_file' => [false, false, 'HTTP/1.1 403'] ]; } public function testGetText() { $messageStart = 'Your web server is set up incorrectly'; $this->assertStringStartsWith($messageStart, (string)$this->_messageModel->getText()); } }