| 13532 |
anikendra |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* TreeBehaviorAfterTest file
|
|
|
4 |
*
|
|
|
5 |
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
|
|
6 |
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
7 |
*
|
|
|
8 |
* Licensed under The MIT License
|
|
|
9 |
* For full copyright and license information, please see the LICENSE.txt
|
|
|
10 |
* Redistributions of files must retain the above copyright notice
|
|
|
11 |
*
|
|
|
12 |
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
13 |
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
|
|
14 |
* @package Cake.Test.Case.Model.Behavior
|
|
|
15 |
* @since CakePHP(tm) v 1.2.0.5330
|
|
|
16 |
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
|
|
17 |
*/
|
|
|
18 |
|
|
|
19 |
App::uses('Model', 'Model');
|
|
|
20 |
App::uses('AppModel', 'Model');
|
|
|
21 |
|
|
|
22 |
require_once dirname(dirname(__FILE__)) . DS . 'models.php';
|
|
|
23 |
|
|
|
24 |
/**
|
|
|
25 |
* TreeBehaviorAfterTest class
|
|
|
26 |
*
|
|
|
27 |
* @package Cake.Test.Case.Model.Behavior
|
|
|
28 |
*/
|
|
|
29 |
class TreeBehaviorAfterTest extends CakeTestCase {
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
* Whether backup global state for each test method or not
|
|
|
33 |
*
|
|
|
34 |
* @var boolean
|
|
|
35 |
*/
|
|
|
36 |
public $backupGlobals = false;
|
|
|
37 |
|
|
|
38 |
/**
|
|
|
39 |
* settings property
|
|
|
40 |
*
|
|
|
41 |
* @var array
|
|
|
42 |
*/
|
|
|
43 |
public $settings = array(
|
|
|
44 |
'modelClass' => 'AfterTree',
|
|
|
45 |
'leftField' => 'lft',
|
|
|
46 |
'rightField' => 'rght',
|
|
|
47 |
'parentField' => 'parent_id'
|
|
|
48 |
);
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
* fixtures property
|
|
|
52 |
*
|
|
|
53 |
* @var array
|
|
|
54 |
*/
|
|
|
55 |
public $fixtures = array('core.after_tree');
|
|
|
56 |
|
|
|
57 |
/**
|
|
|
58 |
* Tests the afterSave callback in the model
|
|
|
59 |
*
|
|
|
60 |
* @return void
|
|
|
61 |
*/
|
|
|
62 |
public function testAftersaveCallback() {
|
|
|
63 |
$this->Tree = new AfterTree();
|
|
|
64 |
$this->Tree->order = null;
|
|
|
65 |
|
|
|
66 |
$expected = array('AfterTree' => array('name' => 'Six and One Half Changed in AfterTree::afterSave() but not in database', 'parent_id' => 6, 'lft' => 11, 'rght' => 12));
|
|
|
67 |
$result = $this->Tree->save(array('AfterTree' => array('name' => 'Six and One Half', 'parent_id' => 6)));
|
|
|
68 |
$expected['AfterTree']['id'] = $this->Tree->id;
|
|
|
69 |
$this->assertEquals($expected, $result);
|
|
|
70 |
|
|
|
71 |
$expected = array('AfterTree' => array('name' => 'Six and One Half', 'parent_id' => 6, 'lft' => 11, 'rght' => 12, 'id' => 8));
|
|
|
72 |
$result = $this->Tree->find('all');
|
|
|
73 |
$this->assertEquals($expected, $result[7]);
|
|
|
74 |
}
|
|
|
75 |
}
|