Browse Source

test for who did it

euromark 12 years ago
parent
commit
7b21b61821

+ 64 - 0
Test/Case/Model/Behavior/WhoDidItBehaviorTest.php

@@ -0,0 +1,64 @@
+<?php
+
+App::uses('WhoDidItBehavior', 'Tools.Model/Behavior');
+App::uses('MyCakeTestCase', 'Tools.TestSuite');
+
+class WhoDidItBehaviorTest extends MyCakeTestCase {
+
+	/**
+	 * Model for tests
+	 *
+	 * @var
+	 */
+	public $Model;
+
+	/**
+	 * Fixtures for tests
+	 *
+	 * @var array
+	 */
+	public $fixtures = array('plugin.tools.who_did_it_player', 'core.cake_session');
+
+	public function setUp() {
+		parent::setUp();
+
+		$this->Model = ClassRegistry::init('WhoDidItPlayer');
+		$this->Model->Behaviors->load('Tools.WhoDidIt');
+	}
+
+	public function testModel() {
+		$this->assertInstanceOf('AppModel', $this->Model);
+	}
+
+	public function testSaveWithDefaultSettings() {
+		$data = array(
+			'name' => 'Foo'
+		);
+		$this->Model->create();
+		$res = $this->Model->save($data);
+		$this->assertTrue((bool)$res);
+		$this->assertTrue(count($res['WhoDidItPlayer']) === 4);
+
+		// create a new one being logged in
+		CakeSession::write('Auth.User.id', '1');
+		$data = array(
+			'name' => 'Foo2'
+		);
+		$this->Model->create();
+		$res = $this->Model->save($data);
+		$this->assertTrue((bool)$res);
+		$this->assertTrue(count($res['WhoDidItPlayer']) === 6);
+		$this->assertEquals('1', $res['WhoDidItPlayer']['created_by']);
+		$this->assertEquals('1', $res['WhoDidItPlayer']['modified_by']);
+
+		// now update
+		$data = array(
+			'name' => 'Foo2x'
+		);
+		$res = $this->Model->save($data);
+		$this->assertTrue((bool)$res);
+		$this->assertTrue(count($res['WhoDidItPlayer']) === 3);
+		$this->assertEquals('1', $res['WhoDidItPlayer']['modified_by']);
+	}
+
+}

+ 45 - 0
Test/Fixture/WhoDidItPlayerFixture.php

@@ -0,0 +1,45 @@
+<?php
+/**
+ * Fixture for WhoDidIt
+ *
+ * PHP 5
+ *
+ * @author Mark Scherrer
+ * @author Marc Würth
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+ * @link https://github.com/dereuromark/tools
+ */
+
+/**
+ * Class WhoDidItPlayerFixture
+ *
+ */
+class WhoDidItPlayerFixture extends CakeTestFixture {
+
+	/**
+	 * Fields property
+	 *
+	 * @var array
+	 */
+	public $fields = array(
+		'id' => array('type' => 'integer', 'key' => 'primary'),
+		'name' => array('type' => 'string', 'null' => false),
+		'created' => 'datetime',
+		'created_by' => array('type' => 'integer', 'null' => true),
+		'modified' => 'datetime',
+		'modified_by' => array('type' => 'integer', 'null' => true)
+	);
+
+	/**
+	 * Records property
+	 *
+	 * @var array
+	 */
+	public $records = array(
+		array('name' => 'mark', 'created' => '2007-03-17 01:16:23'),
+		array('name' => 'jack', 'created' => '2007-03-17 01:18:23'),
+		array('name' => 'larry', 'created' => '2007-03-17 01:20:23'),
+		array('name' => 'jose', 'created' => '2007-03-17 01:22:23'),
+	);
+
+}