IndexTest.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\ReleaseNotification\Controller\Adminhtml\Dashboard;
  8. use Magento\ReleaseNotification\Model\ContentProvider\Http\HttpContentProvider;
  9. use Magento\ReleaseNotification\Model\ContentProviderInterface;
  10. use Magento\TestFramework\Helper\CacheCleaner;
  11. use Magento\TestFramework\ObjectManager;
  12. class IndexTest extends \Magento\TestFramework\TestCase\AbstractBackendController
  13. {
  14. /** @var ObjectManager */
  15. private $objectManager;
  16. /**
  17. * @var HttpContentProvider | \PHPUnit_Framework_MockObject_MockObject
  18. */
  19. private $contentProviderMock;
  20. protected function setUp()
  21. {
  22. parent::setUp();
  23. $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  24. $this->contentProviderMock = $this->getMockBuilder(HttpContentProvider::class)
  25. ->disableOriginalConstructor()
  26. ->getMock();
  27. $this->objectManager->addSharedInstance($this->contentProviderMock, HttpContentProvider::class);
  28. }
  29. protected function tearDown()
  30. {
  31. $this->objectManager->removeSharedInstance(ContentProviderInterface::class);
  32. parent::tearDown();
  33. }
  34. /**
  35. * @magentoAppArea adminhtml
  36. */
  37. public function testExecute()
  38. {
  39. $content = include __DIR__ . '/../../../_files/validContent.php';
  40. CacheCleaner::cleanAll();
  41. $this->contentProviderMock->expects($this->any())
  42. ->method('getContent')
  43. ->willReturn($content);
  44. $this->dispatch('backend/admin/dashboard/index/');
  45. $this->assertEquals(200, $this->getResponse()->getHttpResponseCode());
  46. $actual = $this->getResponse()->getBody();
  47. $this->assertContains('1-mainContent title', $actual);
  48. $this->assertContains('2-mainContent title', $actual);
  49. $this->assertContains('3-mainContent title', $actual);
  50. $this->assertContains('4-mainContent title', $actual);
  51. }
  52. public function testExecuteEmptyContent()
  53. {
  54. CacheCleaner::cleanAll();
  55. $this->contentProviderMock->expects($this->any())
  56. ->method('getContent')
  57. ->willReturn('[]');
  58. $this->dispatch('backend/admin/dashboard/index/');
  59. $this->assertEquals(200, $this->getResponse()->getHttpResponseCode());
  60. $actual = $this->getResponse()->getBody();
  61. $this->assertNotContains('"autoOpen":true', $actual);
  62. }
  63. public function testExecuteFalseContent()
  64. {
  65. CacheCleaner::cleanAll();
  66. $this->contentProviderMock->expects($this->any())
  67. ->method('getContent')
  68. ->willReturn(false);
  69. $this->dispatch('backend/admin/dashboard/index/');
  70. $this->assertEquals(200, $this->getResponse()->getHttpResponseCode());
  71. $actual = $this->getResponse()->getBody();
  72. $this->assertNotContains('"autoOpen":true', $actual);
  73. }
  74. }