TreeBehaviorAfterTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. $expected = array('AfterTree' => array('name' => 'Six and One Half Changed in AfterTree::afterSave() but not in database', 'parent_id' => 6, 'lft' => 11, 'rght' => 12));
  60. $result = $this->Tree->save(array('AfterTree' => array('name' => 'Six and One Half', 'parent_id' => 6)));
  61. $expected['AfterTree']['id'] = $this->Tree->id;
  62. $this->assertEquals($expected, $result);
  63. $expected = array('AfterTree' => array('name' => 'Six and One Half', 'parent_id' => 6, 'lft' => 11, 'rght' => 12, 'id' => 8));
  64. $result = $this->Tree->find('all');
  65. $this->assertEquals($expected, $result[7]);
  66. }
  67. }