IndexTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Robots\Test\Unit\Controller\Index;
  7. class IndexTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Framework\App\Action\Context|\PHPUnit_Framework_MockObject_MockObject
  11. */
  12. private $contextMock;
  13. /**
  14. * @var \Magento\Framework\Controller\Result\RawFactory|\PHPUnit_Framework_MockObject_MockObject
  15. */
  16. private $resultPageFactory;
  17. /**
  18. * @var \Magento\Robots\Controller\Index\Index
  19. */
  20. private $controller;
  21. protected function setUp()
  22. {
  23. $this->contextMock = $this->getMockBuilder(\Magento\Framework\App\Action\Context::class)
  24. ->disableOriginalConstructor()
  25. ->getMock();
  26. $this->resultPageFactory = $this->getMockBuilder(\Magento\Framework\View\Result\PageFactory::class)
  27. ->disableOriginalConstructor()
  28. ->setMethods(['create'])
  29. ->getMock();
  30. $this->controller = new \Magento\Robots\Controller\Index\Index(
  31. $this->contextMock,
  32. $this->resultPageFactory
  33. );
  34. }
  35. /**
  36. * Check the basic flow of execute() method
  37. */
  38. public function testExecute()
  39. {
  40. $resultPageMock = $this->getMockBuilder(\Magento\Framework\View\Result\Page::class)
  41. ->disableOriginalConstructor()
  42. ->getMock();
  43. $resultPageMock->expects($this->once())
  44. ->method('addHandle')
  45. ->with('robots_index_index');
  46. $resultPageMock->expects($this->once())
  47. ->method('setHeader')
  48. ->with('Content-Type', 'text/plain');
  49. $this->resultPageFactory->expects($this->any())
  50. ->method('create')
  51. ->with(true)
  52. ->willReturn($resultPageMock);
  53. $this->assertInstanceOf(
  54. \Magento\Framework\View\Result\Page::class,
  55. $this->controller->execute()
  56. );
  57. }
  58. }