TYPO3 CMS  TYPO3_6-2
FlashMessageQueueTest.php
Go to the documentation of this file.
1 <?php
3 
20 
24  protected $flashMessageQueue;
25 
29  protected $frontendUser;
30 
31  public function setUp() {
32  $this->frontendUser = $this->getMock('TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication', array('dummy'));
33  $this->flashMessageQueue = $this->getAccessibleMock(
34  'TYPO3\CMS\Core\Messaging\FlashMessageQueue',
35  array('getUserByContext'),
36  array('core.template.flashMessages')
37  );
38 
39  $this->flashMessageQueue->expects($this->any())->method('getUserByContext')->will($this->returnValue($this->frontendUser));
40  }
41 
45  public function userSessionInitiallyIsEmpty() {
46  $this->assertSame(array(), $this->flashMessageQueue->_call('getFlashMessagesFromSession'));
47  }
48 
53  $this->flashMessageQueue->enqueue(new \TYPO3\CMS\Core\Messaging\FlashMessage('Foo', 'Bar', \TYPO3\CMS\Core\Messaging\FlashMessage::OK, FALSE));
54 
55  $this->assertSame(array(), $this->flashMessageQueue->_call('getFlashMessagesFromSession'));
56  }
57 
62  $flashMessage = new \TYPO3\CMS\Core\Messaging\FlashMessage('Foo', 'Bar', \TYPO3\CMS\Core\Messaging\FlashMessage::OK, TRUE);
63  $this->flashMessageQueue->enqueue($flashMessage);
64 
65  $this->assertSame(array($flashMessage), $this->flashMessageQueue->_call('getFlashMessagesFromSession'));
66  }
67 
72  $flashMessage1 = new \TYPO3\CMS\Core\Messaging\FlashMessage('Transient', 'Title', \TYPO3\CMS\Core\Messaging\FlashMessage::OK, FALSE);
73  $flashMessage2 = new \TYPO3\CMS\Core\Messaging\FlashMessage('Session', 'Title', \TYPO3\CMS\Core\Messaging\FlashMessage::OK, TRUE);
74  $this->flashMessageQueue->enqueue($flashMessage1);
75  $this->flashMessageQueue->enqueue($flashMessage2);
76 
77  $this->assertCount(2, $this->flashMessageQueue->getAllMessages());
78  }
79 
83  public function clearClearsTheQueue() {
84  $flashMessage1 = new \TYPO3\CMS\Core\Messaging\FlashMessage('Transient', 'Title', \TYPO3\CMS\Core\Messaging\FlashMessage::OK, FALSE);
85  $flashMessage2 = new \TYPO3\CMS\Core\Messaging\FlashMessage('Transient', 'Title', \TYPO3\CMS\Core\Messaging\FlashMessage::OK, FALSE);
86  $this->flashMessageQueue->enqueue($flashMessage1);
87  $this->flashMessageQueue->enqueue($flashMessage2);
88  $this->flashMessageQueue->clear();
89 
90  $this->assertSame(0, $this->flashMessageQueue->count());
91  }
92 
97  $flashMessage1 = new \TYPO3\CMS\Core\Messaging\FlashMessage('Transient', 'Title', \TYPO3\CMS\Core\Messaging\FlashMessage::OK, FALSE);
98  $flashMessage2 = new \TYPO3\CMS\Core\Messaging\FlashMessage('Transient', 'Title', \TYPO3\CMS\Core\Messaging\FlashMessage::OK, TRUE);
99  $this->flashMessageQueue->enqueue($flashMessage1);
100  $this->flashMessageQueue->enqueue($flashMessage2);
101 
102  $this->assertCount(1, $this->flashMessageQueue->toArray());
103  }
104 
109  $this->assertSame(array(), $this->flashMessageQueue->toArray());
110  }
111 
115  public function getAllMessagesAndFlushClearsSessionStack() {
116  $flashMessage = new \TYPO3\CMS\Core\Messaging\FlashMessage('Transient', 'Title', \TYPO3\CMS\Core\Messaging\FlashMessage::OK, TRUE);
117  $this->flashMessageQueue->enqueue($flashMessage);
118  $this->flashMessageQueue->getAllMessagesAndFlush();
119 
121  $frontendUser = $this->flashMessageQueue->_call('getUserByContext');
122 
123  $this->assertNull($frontendUser->getSessionData('core.template.flashMessages'));
124  }
125 
126 }
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)