AdditionalTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Backend\Test\Unit\Block\Cache;
  7. class AdditionalTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Backend\Block\Cache\Additional
  11. */
  12. private $additionalBlock;
  13. /**
  14. * @var \Magento\Framework\UrlInterface|\PHPUnit_Framework_MockObject_MockObject
  15. */
  16. protected $urlBuilderMock;
  17. /**
  18. * @var \Magento\Framework\App\State | \PHPUnit_Framework_MockObject_MockObject
  19. */
  20. protected $appStateMock;
  21. protected function setUp()
  22. {
  23. $this->urlBuilderMock = $this->createMock(\Magento\Framework\UrlInterface::class);
  24. $this->appStateMock = $this->getMockBuilder(\Magento\Framework\App\State::class)
  25. ->disableOriginalConstructor()
  26. ->getMock();
  27. $objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  28. $context = $objectHelper->getObject(
  29. \Magento\Backend\Block\Template\Context::class,
  30. [
  31. 'urlBuilder' => $this->urlBuilderMock,
  32. 'appState' => $this->appStateMock,
  33. ]
  34. );
  35. $this->additionalBlock = $objectHelper->getObject(
  36. \Magento\Backend\Block\Cache\Additional::class,
  37. ['context' => $context]
  38. );
  39. }
  40. public function testGetCleanImagesUrl()
  41. {
  42. $expectedUrl = 'cleanImagesUrl';
  43. $this->urlBuilderMock->expects($this->once())
  44. ->method('getUrl')
  45. ->with('*/*/cleanImages')
  46. ->will($this->returnValue($expectedUrl));
  47. $this->assertEquals($expectedUrl, $this->additionalBlock->getCleanImagesUrl());
  48. }
  49. public function testGetCleanMediaUrl()
  50. {
  51. $expectedUrl = 'cleanMediaUrl';
  52. $this->urlBuilderMock->expects($this->once())
  53. ->method('getUrl')
  54. ->with('*/*/cleanMedia')
  55. ->will($this->returnValue($expectedUrl));
  56. $this->assertEquals($expectedUrl, $this->additionalBlock->getCleanMediaUrl());
  57. }
  58. public function testGetCleanStaticFiles()
  59. {
  60. $expectedUrl = 'cleanStaticFilesUrl';
  61. $this->urlBuilderMock->expects($this->once())
  62. ->method('getUrl')
  63. ->with('*/*/cleanStaticFiles')
  64. ->will($this->returnValue($expectedUrl));
  65. $this->assertEquals($expectedUrl, $this->additionalBlock->getCleanStaticFilesUrl());
  66. }
  67. /**
  68. * @param string $mode
  69. * @param bool $expected
  70. * @dataProvider isInProductionModeDataProvider
  71. */
  72. public function testIsInProductionMode($mode, $expected)
  73. {
  74. $this->appStateMock->expects($this->once())
  75. ->method('getMode')
  76. ->willReturn($mode);
  77. $this->assertEquals($expected, $this->additionalBlock->isInProductionMode());
  78. }
  79. /**
  80. * @return array
  81. */
  82. public function isInProductionModeDataProvider()
  83. {
  84. return [
  85. [\Magento\Framework\App\State::MODE_DEFAULT, false],
  86. [\Magento\Framework\App\State::MODE_DEVELOPER, false],
  87. [\Magento\Framework\App\State::MODE_PRODUCTION, true],
  88. ];
  89. }
  90. }