EventTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * EventTest file
  4. *
  5. * Test Case for Event class
  6. *
  7. * CakePHP : Rapid Development Framework (http://cakephp.org)
  8. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * For full copyright and license information, please see the LICENSE.txt
  12. * Redistributions of files must retain the above copyright notice.
  13. *
  14. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  15. * @link http://cakephp.org CakePHP Project
  16. * @since 2.1.0
  17. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  18. */
  19. namespace Cake\Test\TestCase\Event;
  20. use Cake\Event\Event;
  21. use Cake\TestSuite\TestCase;
  22. /**
  23. * Tests the Cake\Event\Event class functionality
  24. */
  25. class EventTest extends TestCase
  26. {
  27. /**
  28. * Tests the name() method
  29. *
  30. * @return void
  31. * @triggers fake.event
  32. */
  33. public function testName()
  34. {
  35. $event = new Event('fake.event');
  36. $this->assertEquals('fake.event', $event->name());
  37. }
  38. /**
  39. * Tests the subject() method
  40. *
  41. * @return void
  42. * @triggers fake.event $this
  43. * @triggers fake.event
  44. */
  45. public function testSubject()
  46. {
  47. $event = new Event('fake.event', $this);
  48. $this->assertSame($this, $event->subject());
  49. $event = new Event('fake.event');
  50. $this->assertNull($event->subject());
  51. }
  52. /**
  53. * Tests the event propagation stopping property
  54. *
  55. * @return void
  56. * @triggers fake.event
  57. */
  58. public function testPropagation()
  59. {
  60. $event = new Event('fake.event');
  61. $this->assertFalse($event->isStopped());
  62. $event->stopPropagation();
  63. $this->assertTrue($event->isStopped());
  64. }
  65. /**
  66. * Tests that it is possible to get/set custom data in a event
  67. *
  68. * @return void
  69. * @triggers fake.event $this, array('some' => 'data')
  70. */
  71. public function testEventData()
  72. {
  73. $event = new Event('fake.event', $this, ['some' => 'data']);
  74. $this->assertEquals(['some' => 'data'], $event->data());
  75. }
  76. /**
  77. * Tests that it is possible to get the name and subject directly
  78. *
  79. * @return void
  80. * @triggers fake.event $this
  81. */
  82. public function testEventDirectPropertyAccess()
  83. {
  84. $event = new Event('fake.event', $this);
  85. $this->assertEquals($this, $event->subject());
  86. $this->assertEquals('fake.event', $event->name());
  87. }
  88. }