TreeBehaviorAfterTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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-2012, 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-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
  15. * @package Cake.Test.Case.Model.Behavior
  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.Test.Case.Model.Behavior
  26. */
  27. class TreeBehaviorAfterTest extends CakeTestCase {
  28. /**
  29. * Whether backup global state for each test method or not
  30. *
  31. * @var bool false
  32. */
  33. public $backupGlobals = false;
  34. /**
  35. * settings property
  36. *
  37. * @var array
  38. */
  39. public $settings = array(
  40. 'modelClass' => 'AfterTree',
  41. 'leftField' => 'lft',
  42. 'rightField' => 'rght',
  43. 'parentField' => 'parent_id'
  44. );
  45. /**
  46. * fixtures property
  47. *
  48. * @var array
  49. */
  50. public $fixtures = array('core.after_tree');
  51. /**
  52. * Tests the afterSave callback in the model
  53. *
  54. * @return void
  55. */
  56. public function testAftersaveCallback() {
  57. $this->Tree = new AfterTree();
  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($result[7], $expected);
  65. }
  66. }