EventTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. */
  26. class EventTest extends TestCase
  27. {
  28. /**
  29. * Tests the name() method
  30. *
  31. * @return void
  32. * @triggers fake.event
  33. */
  34. public function testName()
  35. {
  36. $event = new Event('fake.event');
  37. $this->assertEquals('fake.event', $event->name());
  38. }
  39. /**
  40. * Tests the subject() method
  41. *
  42. * @return void
  43. * @triggers fake.event $this
  44. * @triggers fake.event
  45. */
  46. public function testSubject()
  47. {
  48. $event = new Event('fake.event', $this);
  49. $this->assertSame($this, $event->subject());
  50. $event = new Event('fake.event');
  51. $this->assertNull($event->subject());
  52. }
  53. /**
  54. * Tests the event propagation stopping property
  55. *
  56. * @return void
  57. * @triggers fake.event
  58. */
  59. public function testPropagation()
  60. {
  61. $event = new Event('fake.event');
  62. $this->assertFalse($event->isStopped());
  63. $event->stopPropagation();
  64. $this->assertTrue($event->isStopped());
  65. }
  66. /**
  67. * Tests that it is possible to get/set custom data in a event
  68. *
  69. * @return void
  70. * @triggers fake.event $this, array('some' => 'data')
  71. */
  72. public function testEventData()
  73. {
  74. $event = new Event('fake.event', $this, ['some' => 'data']);
  75. $this->assertEquals(['some' => 'data'], $event->data);
  76. }
  77. /**
  78. * Tests that it is possible to get the name and subject directly
  79. *
  80. * @return void
  81. * @triggers fake.event $this
  82. */
  83. public function testEventDirectPropertyAccess()
  84. {
  85. $event = new Event('fake.event', $this);
  86. $this->assertEquals($this, $event->subject);
  87. $this->assertEquals('fake.event', $event->name);
  88. }
  89. }