SystemMessagesServiceTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace Elgg;
  3. class SystemMessagesServiceTest extends \PHPUnit_Framework_TestCase {
  4. /**
  5. * @var SystemMessagesService
  6. */
  7. protected $svc;
  8. /**
  9. * @var \ElggSession
  10. */
  11. protected $session;
  12. function setup() {
  13. $this->session = \ElggSession::getMock();
  14. $this->svc = new SystemMessagesService($this->session);
  15. }
  16. function testCanStoreAndDumpMessages() {
  17. $this->svc->addSuccessMessage('s1');
  18. $this->svc->addSuccessMessage(['s2', 's3']);
  19. $this->svc->addErrorMessage('e1');
  20. $this->svc->addErrorMessage(['e2', 'e3']);
  21. $this->svc->addMessageToRegister('n1', 'notice');
  22. $this->svc->addMessageToRegister(['n2', 'n3'], 'notice');
  23. $this->assertEquals([
  24. 'success' => ['s1', 's2', 's3'],
  25. 'error' => ['e1', 'e2', 'e3'],
  26. 'notice' => ['n1', 'n2', 'n3'],
  27. ], $this->svc->dumpRegister());
  28. $this->assertEmpty($this->svc->dumpRegister());
  29. }
  30. function testMessagesStoredInSession() {
  31. $this->svc->addSuccessMessage('s1');
  32. $this->assertEquals(['success' => ['s1']], $this->session->get('msg'));
  33. }
  34. function testCanDumpOneRegister() {
  35. $this->svc->addSuccessMessage(['s2', 's3']);
  36. $this->svc->addErrorMessage(['e1', 'e2', 'e3']);
  37. $this->assertEquals([
  38. 'success' => ['s2', 's3'],
  39. ], $this->svc->dumpRegister('success'));
  40. $this->assertEquals([
  41. 'success' => [],
  42. ], $this->svc->dumpRegister('success'));
  43. $this->assertEquals([
  44. 'error' => ['e1', 'e2', 'e3'],
  45. ], $this->svc->dumpRegister('error'));
  46. $this->assertEmpty($this->svc->dumpRegister());
  47. }
  48. function testCanCount() {
  49. $this->svc->addSuccessMessage(['s2', 's3']);
  50. $this->svc->addErrorMessage(['e1', 'e2', 'e3']);
  51. $this->assertEquals(2, $this->svc->count("success"));
  52. $this->assertEquals(3, $this->svc->count("error"));
  53. $this->assertEquals(5, $this->svc->count());
  54. }
  55. }