TreeBehaviorAfterTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * TreeBehaviorAfterTest file
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
  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://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
  16. * @package Cake.Test.Case.Model.Behavior
  17. * @since CakePHP(tm) v 1.2.0.5330
  18. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  19. */
  20. App::uses('Model', 'Model');
  21. App::uses('AppModel', 'Model');
  22. require_once dirname(dirname(__FILE__)) . DS . 'models.php';
  23. /**
  24. * TreeBehaviorAfterTest class
  25. *
  26. * @package Cake.Test.Case.Model.Behavior
  27. */
  28. class TreeBehaviorAfterTest extends CakeTestCase {
  29. /**
  30. * Whether backup global state for each test method or not
  31. *
  32. * @var bool false
  33. */
  34. public $backupGlobals = false;
  35. /**
  36. * settings property
  37. *
  38. * @var array
  39. */
  40. public $settings = array(
  41. 'modelClass' => 'AfterTree',
  42. 'leftField' => 'lft',
  43. 'rightField' => 'rght',
  44. 'parentField' => 'parent_id'
  45. );
  46. /**
  47. * fixtures property
  48. *
  49. * @var array
  50. */
  51. public $fixtures = array('core.after_tree');
  52. /**
  53. * Tests the afterSave callback in the model
  54. *
  55. * @return void
  56. */
  57. public function testAftersaveCallback() {
  58. $this->Tree = new AfterTree();
  59. $this->Tree->order = null;
  60. $expected = array('AfterTree' => array('name' => 'Six and One Half Changed in AfterTree::afterSave() but not in database', 'parent_id' => 6, 'lft' => 11, 'rght' => 12));
  61. $result = $this->Tree->save(array('AfterTree' => array('name' => 'Six and One Half', 'parent_id' => 6)));
  62. $expected['AfterTree']['id'] = $this->Tree->id;
  63. $this->assertEquals($expected, $result);
  64. $expected = array('AfterTree' => array('name' => 'Six and One Half', 'parent_id' => 6, 'lft' => 11, 'rght' => 12, 'id' => 8));
  65. $result = $this->Tree->find('all');
  66. $this->assertEquals($expected, $result[7]);
  67. }
  68. }