objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $this->contentProviderMock = $this->getMockBuilder(HttpContentProvider::class) ->disableOriginalConstructor() ->getMock(); $this->objectManager->addSharedInstance($this->contentProviderMock, HttpContentProvider::class); } protected function tearDown() { $this->objectManager->removeSharedInstance(ContentProviderInterface::class); parent::tearDown(); } /** * @magentoAppArea adminhtml */ public function testExecute() { $content = include __DIR__ . '/../../../_files/validContent.php'; CacheCleaner::cleanAll(); $this->contentProviderMock->expects($this->any()) ->method('getContent') ->willReturn($content); $this->dispatch('backend/admin/dashboard/index/'); $this->assertEquals(200, $this->getResponse()->getHttpResponseCode()); $actual = $this->getResponse()->getBody(); $this->assertContains('1-mainContent title', $actual); $this->assertContains('2-mainContent title', $actual); $this->assertContains('3-mainContent title', $actual); $this->assertContains('4-mainContent title', $actual); } public function testExecuteEmptyContent() { CacheCleaner::cleanAll(); $this->contentProviderMock->expects($this->any()) ->method('getContent') ->willReturn('[]'); $this->dispatch('backend/admin/dashboard/index/'); $this->assertEquals(200, $this->getResponse()->getHttpResponseCode()); $actual = $this->getResponse()->getBody(); $this->assertNotContains('"autoOpen":true', $actual); } public function testExecuteFalseContent() { CacheCleaner::cleanAll(); $this->contentProviderMock->expects($this->any()) ->method('getContent') ->willReturn(false); $this->dispatch('backend/admin/dashboard/index/'); $this->assertEquals(200, $this->getResponse()->getHttpResponseCode()); $actual = $this->getResponse()->getBody(); $this->assertNotContains('"autoOpen":true', $actual); } }