TreeBehaviorAfterTest.php 2.1 KB

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