CakeEventTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * ControllerTestCaseTest file
  4. *
  5. * Test Case for ControllerTestCase class
  6. *
  7. * PHP version 5
  8. *
  9. * CakePHP : Rapid Development Framework (http://cakephp.org)
  10. * Copyright 2005-2012, Cake Software Foundation, Inc.
  11. *
  12. * Licensed under The MIT License
  13. * Redistributions of files must retain the above copyright notice.
  14. *
  15. * @copyright Copyright 2005-2012, Cake Software Foundation, Inc.
  16. * @link http://cakephp.org CakePHP Project
  17. * @package Cake.Test.Case.Event
  18. * @since CakePHP v 2.1
  19. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  20. */
  21. App::uses('CakeEvent', 'Event');
  22. /**
  23. * Tests the CakeEvent class functionality
  24. *
  25. */
  26. class CakeEventTest extends CakeTestCase {
  27. /**
  28. * Tests the name() method
  29. *
  30. * @return void
  31. */
  32. public function testName() {
  33. $event = new CakeEvent('fake.event');
  34. $this->assertEquals('fake.event', $event->name());
  35. }
  36. /**
  37. * Tests the subject() method
  38. *
  39. * @return void
  40. */
  41. public function testSubject() {
  42. $event = new CakeEvent('fake.event', $this);
  43. $this->assertSame($this, $event->subject());
  44. $event = new CakeEvent('fake.event');
  45. $this->assertNull($event->subject());
  46. }
  47. /**
  48. * Tests the event propagation stopping property
  49. *
  50. * @return void
  51. */
  52. public function testPropagation() {
  53. $event = new CakeEvent('fake.event');
  54. $this->assertFalse($event->isStopped());
  55. $event->stopPropagation();
  56. $this->assertTrue($event->isStopped());
  57. }
  58. /**
  59. * Tests that it is possible to get/set custom data in a event
  60. *
  61. * @return void
  62. */
  63. public function testEventData() {
  64. $event = new CakeEvent('fake.event', $this, array('some' => 'data'));
  65. $this->assertEquals(array('some' => 'data'), $event->data);
  66. }
  67. /**
  68. * Tests that it is possible to get the name and subject directly
  69. *
  70. * @return void
  71. */
  72. public function testEventDirectPropertyAccess() {
  73. $event = new CakeEvent('fake.event', $this);
  74. $this->assertEquals($this, $event->subject);
  75. $this->assertEquals('fake.event', $event->name);
  76. }
  77. }