WhoDidItBehaviorTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. App::uses('WhoDidItBehavior', 'Tools.Model/Behavior');
  3. App::uses('MyCakeTestCase', 'Tools.TestSuite');
  4. class WhoDidItBehaviorTest extends MyCakeTestCase {
  5. /**
  6. * Model for tests
  7. *
  8. * @var
  9. */
  10. public $Model;
  11. /**
  12. * Fixtures for tests
  13. *
  14. * @var array
  15. */
  16. public $fixtures = array('plugin.tools.who_did_it_player', 'core.cake_session');
  17. public function setUp() {
  18. parent::setUp();
  19. $this->Model = ClassRegistry::init('WhoDidItPlayer');
  20. $this->Model->Behaviors->load('Tools.WhoDidIt');
  21. }
  22. public function testModel() {
  23. $this->assertInstanceOf('AppModel', $this->Model);
  24. }
  25. public function testSaveWithDefaultSettings() {
  26. $data = array(
  27. 'name' => 'Foo'
  28. );
  29. $this->Model->create();
  30. $res = $this->Model->save($data);
  31. $this->assertTrue((bool)$res);
  32. $this->assertTrue(count($res['WhoDidItPlayer']) === 4);
  33. // create a new one being logged in
  34. CakeSession::write('Auth.User.id', '1');
  35. $data = array(
  36. 'name' => 'Foo2'
  37. );
  38. $this->Model->create();
  39. $res = $this->Model->save($data);
  40. $this->assertTrue((bool)$res);
  41. $this->assertTrue(count($res['WhoDidItPlayer']) === 6);
  42. $this->assertEquals('1', $res['WhoDidItPlayer']['created_by']);
  43. $this->assertEquals('1', $res['WhoDidItPlayer']['modified_by']);
  44. // now update
  45. $data = array(
  46. 'name' => 'Foo2x'
  47. );
  48. $res = $this->Model->save($data);
  49. $this->assertTrue((bool)$res);
  50. $this->assertTrue(count($res['WhoDidItPlayer']) === 3);
  51. $this->assertEquals('1', $res['WhoDidItPlayer']['modified_by']);
  52. }
  53. }