ActionFlagTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\App\Test\Unit;
  7. class ActionFlagTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Framework\App\ActionFlag
  11. */
  12. protected $_actionFlag;
  13. /**
  14. * @var \PHPUnit_Framework_MockObject_MockObject
  15. */
  16. protected $_requestMock;
  17. protected function setUp()
  18. {
  19. $this->_requestMock = $this->createMock(\Magento\Framework\App\Request\Http::class);
  20. $this->_actionFlag = new \Magento\Framework\App\ActionFlag($this->_requestMock);
  21. }
  22. public function testSetIfActionNotExist()
  23. {
  24. $this->_requestMock->expects($this->once())->method('getActionName')->will($this->returnValue('action_name'));
  25. $this->_requestMock->expects($this->once())->method('getRouteName');
  26. $this->_requestMock->expects($this->once())->method('getControllerName');
  27. $this->_actionFlag->set('', 'flag', 'value');
  28. }
  29. public function testSetIfActionExist()
  30. {
  31. $this->_requestMock->expects($this->never())->method('getActionName');
  32. $this->_requestMock->expects($this->once())->method('getRouteName');
  33. $this->_requestMock->expects($this->once())->method('getControllerName');
  34. $this->_actionFlag->set('action', 'flag', 'value');
  35. }
  36. public function testGetIfFlagNotExist()
  37. {
  38. $this->_requestMock->expects($this->once())->method('getActionName')->will($this->returnValue('action_name'));
  39. $this->_requestMock->expects($this->once())->method('getRouteName');
  40. $this->_requestMock->expects($this->once())->method('getControllerName');
  41. $this->assertEquals([], $this->_actionFlag->get(''));
  42. }
  43. public function testGetIfFlagExist()
  44. {
  45. $this->_requestMock->expects($this->never())->method('getActionName');
  46. $this->_requestMock->expects(
  47. $this->exactly(3)
  48. )->method(
  49. 'getRouteName'
  50. )->will(
  51. $this->returnValue('route')
  52. );
  53. $this->_requestMock->expects(
  54. $this->exactly(3)
  55. )->method(
  56. 'getControllerName'
  57. )->will(
  58. $this->returnValue('controller')
  59. );
  60. $this->_actionFlag->set('action', 'flag', 'value');
  61. $this->assertEquals('value', $this->_actionFlag->get('action', 'flag'));
  62. }
  63. public function testGetIfFlagWithControllerKryNotExist()
  64. {
  65. $this->_requestMock->expects($this->never())->method('getActionName');
  66. $this->_requestMock->expects(
  67. $this->once()
  68. )->method(
  69. 'getRouteName'
  70. )->will(
  71. $this->returnValue('route')
  72. );
  73. $this->_requestMock->expects(
  74. $this->once()
  75. )->method(
  76. 'getControllerName'
  77. )->will(
  78. $this->returnValue('controller')
  79. );
  80. $this->assertEquals(false, $this->_actionFlag->get('action', 'flag'));
  81. }
  82. }