pictcode / lib / Cake / Test / Case / Event / CakeEventTest.php @ f4745fee
履歴 | 表示 | アノテート | ダウンロード (2.25 KB)
| 1 | 635eef61 | spyder1211 | <?php
|
|---|---|---|---|
| 2 | /**
|
||
| 3 | * ControllerTestCaseTest file
|
||
| 4 | *
|
||
| 5 | * Test Case for ControllerTestCase 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 | * @package Cake.Test.Case.Event
|
||
| 17 | * @since CakePHP v 2.1
|
||
| 18 | * @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||
| 19 | */
|
||
| 20 | |||
| 21 | App::uses('CakeEvent', 'Event'); |
||
| 22 | |||
| 23 | /**
|
||
| 24 | * Tests the CakeEvent class functionality
|
||
| 25 | */
|
||
| 26 | class CakeEventTest extends CakeTestCase { |
||
| 27 | |||
| 28 | /**
|
||
| 29 | * Tests the name() method
|
||
| 30 | *
|
||
| 31 | * @return void
|
||
| 32 | * @triggers fake.event
|
||
| 33 | */
|
||
| 34 | public function testName() { |
||
| 35 | $event = new CakeEvent('fake.event'); |
||
| 36 | $this->assertEquals('fake.event', $event->name()); |
||
| 37 | } |
||
| 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 | $event = new CakeEvent('fake.event', $this); |
||
| 48 | $this->assertSame($this, $event->subject()); |
||
| 49 | |||
| 50 | $event = new CakeEvent('fake.event'); |
||
| 51 | $this->assertNull($event->subject()); |
||
| 52 | } |
||
| 53 | |||
| 54 | /**
|
||
| 55 | * Tests the event propagation stopping property
|
||
| 56 | *
|
||
| 57 | * @return void
|
||
| 58 | * @triggers fake.event
|
||
| 59 | */
|
||
| 60 | public function testPropagation() { |
||
| 61 | $event = new CakeEvent('fake.event'); |
||
| 62 | $this->assertFalse($event->isStopped()); |
||
| 63 | $event->stopPropagation();
|
||
| 64 | $this->assertTrue($event->isStopped()); |
||
| 65 | } |
||
| 66 | |||
| 67 | /**
|
||
| 68 | * Tests that it is possible to get/set custom data in a event
|
||
| 69 | *
|
||
| 70 | * @return void
|
||
| 71 | * @triggers fake.event $this, array('some' => 'data')
|
||
| 72 | */
|
||
| 73 | public function testEventData() { |
||
| 74 | $event = new CakeEvent('fake.event', $this, array('some' => 'data')); |
||
| 75 | $this->assertEquals(array('some' => 'data'), $event->data); |
||
| 76 | } |
||
| 77 | |||
| 78 | /**
|
||
| 79 | * Tests that it is possible to get the name and subject directly
|
||
| 80 | *
|
||
| 81 | * @return void
|
||
| 82 | * @triggers fake.event $this
|
||
| 83 | */
|
||
| 84 | public function testEventDirectPropertyAccess() { |
||
| 85 | $event = new CakeEvent('fake.event', $this); |
||
| 86 | $this->assertEquals($this, $event->subject); |
||
| 87 | $this->assertEquals('fake.event', $event->name); |
||
| 88 | } |
||
| 89 | } |