TreeBehaviorAfterTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. * @since CakePHP(tm) v 1.2.0.5330
  17. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  18. */
  19. namespace Cake\Test\TestCase\Model\Behavior;
  20. use Cake\Model\Model;
  21. use Cake\TestSuite\TestCase;
  22. require_once dirname(__DIR__) . DS . 'models.php';
  23. /**
  24. * TreeBehaviorAfterTest class
  25. *
  26. */
  27. class TreeBehaviorAfterTest extends TestCase {
  28. /**
  29. * Whether backup global state for each test method or not
  30. *
  31. * @var boolean
  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. public function setUp() {
  52. parent::setUp();
  53. $this->markTestIncomplete('Not runnable until Models are fixed.');
  54. }
  55. /**
  56. * Tests the afterSave callback in the model
  57. *
  58. * @return void
  59. */
  60. public function testAftersaveCallback() {
  61. $this->Tree = new AfterTree();
  62. $this->Tree->order = null;
  63. $expected = array('AfterTree' => array('name' => 'Six and One Half Changed in AfterTree::afterSave() but not in database', 'parent_id' => 6, 'lft' => 11, 'rght' => 12));
  64. $result = $this->Tree->save(array('AfterTree' => array('name' => 'Six and One Half', 'parent_id' => 6)));
  65. $expected['AfterTree']['id'] = $this->Tree->id;
  66. $this->assertEquals($expected, $result);
  67. $expected = array('AfterTree' => array('name' => 'Six and One Half', 'parent_id' => 6, 'lft' => 11, 'rght' => 12, 'id' => 8));
  68. $result = $this->Tree->find('all');
  69. $this->assertEquals($expected, $result[7]);
  70. }
  71. }