EventTest.php 2.2 KB

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