TreeBehaviorAfterTest.php 2.1 KB

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