Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ActionFlagTest.php
Go to the documentation of this file.
1 <?php
7 
8 class ActionFlagTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $_actionFlag;
14 
18  protected $_requestMock;
19 
20  protected function setUp()
21  {
22  $this->_requestMock = $this->createMock(\Magento\Framework\App\Request\Http::class);
23  $this->_actionFlag = new \Magento\Framework\App\ActionFlag($this->_requestMock);
24  }
25 
26  public function testSetIfActionNotExist()
27  {
28  $this->_requestMock->expects($this->once())->method('getActionName')->will($this->returnValue('action_name'));
29  $this->_requestMock->expects($this->once())->method('getRouteName');
30  $this->_requestMock->expects($this->once())->method('getControllerName');
31  $this->_actionFlag->set('', 'flag', 'value');
32  }
33 
34  public function testSetIfActionExist()
35  {
36  $this->_requestMock->expects($this->never())->method('getActionName');
37  $this->_requestMock->expects($this->once())->method('getRouteName');
38  $this->_requestMock->expects($this->once())->method('getControllerName');
39  $this->_actionFlag->set('action', 'flag', 'value');
40  }
41 
42  public function testGetIfFlagNotExist()
43  {
44  $this->_requestMock->expects($this->once())->method('getActionName')->will($this->returnValue('action_name'));
45  $this->_requestMock->expects($this->once())->method('getRouteName');
46  $this->_requestMock->expects($this->once())->method('getControllerName');
47  $this->assertEquals([], $this->_actionFlag->get(''));
48  }
49 
50  public function testGetIfFlagExist()
51  {
52  $this->_requestMock->expects($this->never())->method('getActionName');
53  $this->_requestMock->expects(
54  $this->exactly(3)
55  )->method(
56  'getRouteName'
57  )->will(
58  $this->returnValue('route')
59  );
60  $this->_requestMock->expects(
61  $this->exactly(3)
62  )->method(
63  'getControllerName'
64  )->will(
65  $this->returnValue('controller')
66  );
67  $this->_actionFlag->set('action', 'flag', 'value');
68  $this->assertEquals('value', $this->_actionFlag->get('action', 'flag'));
69  }
70 
72  {
73  $this->_requestMock->expects($this->never())->method('getActionName');
74  $this->_requestMock->expects(
75  $this->once()
76  )->method(
77  'getRouteName'
78  )->will(
79  $this->returnValue('route')
80  );
81  $this->_requestMock->expects(
82  $this->once()
83  )->method(
84  'getControllerName'
85  )->will(
86  $this->returnValue('controller')
87  );
88  $this->assertEquals(false, $this->_actionFlag->get('action', 'flag'));
89  }
90 }