-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
BehaviorRegistryTest.php
133 lines (119 loc) · 3.22 KB
/
BehaviorRegistryTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since CakePHP(tm) v 3.0.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Cake\Test\TestCase\ORM;
use Cake\Core\Configure;
use Cake\Core\Plugin;
use Cake\ORM\Table;
use Cake\ORM\BehaviorRegistry;
use Cake\TestSuite\TestCase;
/**
* Test case for BehaviorRegistry.
*/
class BehaviorRegistryTest extends TestCase {
/**
* setup method.
*
* @return void
*/
public function setUp() {
parent::setUp();
$this->Table = new Table(['table' => 'articles']);
$this->EventManager = $this->Table->getEventManager();
$this->Behaviors = new BehaviorRegistry($this->Table);
Configure::write('App.namespace', 'TestApp');
}
/**
* tearDown
*
* @return void
*/
public function tearDown() {
Plugin::unload();
unset($this->Table, $this->EventManager, $this->Behaviors);
parent::tearDown();
}
/**
* Test loading behaviors.
*
* @return void
*/
public function testLoad() {
$settings = ['replacement' => '-'];
$result = $this->Behaviors->load('Sluggable', $settings);
$this->assertInstanceOf('TestApp\Model\Behavior\SluggableBehavior', $result);
$this->assertEquals($settings, $result->settings);
}
/**
* Test load() binding listeners.
*
* @return void
*/
public function testLoadBindEvents() {
$result = $this->EventManager->listeners('Model.beforeFind');
$this->assertCount(0, $result);
$this->Behaviors->load('Sluggable');
$result = $this->EventManager->listeners('Model.beforeFind');
$this->assertCount(1, $result);
}
/**
* Test load() with enabled = false
*
* @return void
*/
public function testLoadEnabledFalse() {
$result = $this->EventManager->listeners('Model.beforeFind');
$this->assertCount(0, $result);
$this->Behaviors->load('Sluggable', ['enabled' => false]);
$result = $this->EventManager->listeners('Model.beforeFind');
$this->assertCount(0, $result);
}
/**
* Test loading plugin behaviors
*
* @return void
*/
public function testLoadPlugin() {
Plugin::load('TestPlugin');
$result = $this->Behaviors->load('TestPlugin.PersisterOne');
$this->assertInstanceOf('TestPlugin\Model\Behavior\PersisterOneBehavior', $result);
}
/**
* Test load() on undefined class
*
* @expectedException Cake\Error\MissingBehaviorException
* @return void
*/
public function testLoadMissingClass() {
$this->Behaviors->load('DoesNotExist');
}
/**
* Test load() duplicate method error
*
* @expectedException Cake\Error\Exception
* @expectedExceptionMessage TestApp\Model\Behavior\DuplicateBehavior contains duplicate method "dupe"
* @return void
*/
public function testLoadDuplicateMethodError() {
$this->markTestIncomplete('not done');
}
/**
* test hasMethod()
*
* @return void
*/
public function testHasMethod() {
$this->markTestIncomplete('not done');
}
}