Commit: 1ee4d2c83b690569f991101379700462cd1ef84e
Author: Jon Adams | Date: 2010-09-02 11:37:40 -0700
diff --git a/libraries/lithium/tests/integration/data/CouchDbIntegrationTest.php b/libraries/lithium/tests/integration/data/CouchDbIntegrationTest.php
new file mode 100644
index 0000000..871d06c
--- /dev/null
+++ b/libraries/lithium/tests/integration/data/CouchDbIntegrationTest.php
@@ -0,0 +1,104 @@
+<?php
+/**
+ * Lithium: the most rad php framework
+ *
+ * @copyright Copyright 2010, Union of RAD (http://union-of-rad.org)
+ * @license http://opensource.org/licenses/bsd-license.php The BSD License
+ */
+
+namespace lithium\tests\integration\data;
+
+use \lithium\data\Connections;
+
+class MockCouchModel extends \lithium\data\Model {
+ protected $_schema = array(
+ 'someKey' => array()
+ );
+}
+
+class CouchDbIntegrationTest extends \lithium\test\Integration {
+
+ public function setUp() {
+ MockCouchModel::meta(array('connection' => 'test'));
+ }
+
+ public function tearDown() {
+ $results = MockCouchModel::all();
+ if ($results->count()) {
+ $results->delete();
+ }
+ }
+
+ /**
+ * Skip the test if no `test` CouchDb connection available.
+ *
+ * @return void
+ */
+ public function skip() {
+ $isAvailable = (
+ Connections::get('test', array('config' => true)) &&
+ Connections::get('test')->isConnected(array('autoConnect' => true))
+ );
+ $this->skipIf(!$isAvailable, "No test connection available");
+
+ $couchConnection = strpos(get_class(Connections::get('test')), 'CouchDb');
+ $this->skipIf(!$couchConnection, "Test connection is not CouchDb");
+ }
+
+ public function testCreate() {
+ $result = MockCouchModel::create()->save();
+ $this->assertTrue($result);
+ }
+
+ public function testSavingIdWithLockedModel() {
+ $id = 'myCustomId';
+ $model = MockCouchModel::create(compact('id'));
+ $result = $model->save();
+
+ $this->assertTrue($result);
+
+ $data = $model->data();
+ $expected = $id;
+ $this->assertNotEqual($expected, $data['id']);
+ }
+
+ public function testSavingIdWithUnlockedModel() {
+ MockCouchModel::meta(array('locked' => false));
+ $id = 'myCustomId';
+ $model = MockCouchModel::create(compact('id'));
+ $result = $model->save();
+ $this->assertTrue($result);
+
+ $data = $model->data();
+ $expected = $id;
+ $this->assertEqual($expected, $data['id']);
+ }
+
+ public function testUpdate() {
+ $model = MockCouchModel::create(array('someKey' => 'someValue'));
+ $result = $model->save();
+ $this->assertTrue($result);
+
+ $data = $model->data();
+
+ $this->assertTrue(array_key_exists('id', $data));
+ $this->assertTrue(array_key_exists('rev', $data));
+
+ $expected = 'someValue';
+ $this->assertEqual($expected, $data['someKey']);
+
+ $model->someKey = 'someOtherValue';
+ $result = $model->save();
+ $this->assertTrue($result);
+
+ $updated = $model->data();
+
+ $expected = 'someOtherValue';
+ $this->assertEqual($expected, $updated['someKey']);
+ $this->assertEqual($data['id'], $updated['id']);
+ $this->assertNotEqual($data['rev'], $updated['rev']);
+ }
+
+}
+
+?>
\ No newline at end of file
diff --git a/libraries/lithium/tests/integration/data/CouchDbModelTest.php b/libraries/lithium/tests/integration/data/CouchDbModelTest.php
deleted file mode 100644
index c635310..0000000
--- a/libraries/lithium/tests/integration/data/CouchDbModelTest.php
+++ /dev/null
@@ -1,104 +0,0 @@
-<?php
-/**
- * Lithium: the most rad php framework
- *
- * @copyright Copyright 2010, Union of RAD (http://union-of-rad.org)
- * @license http://opensource.org/licenses/bsd-license.php The BSD License
- */
-
-namespace lithium\tests\integration\data;
-
-use \lithium\data\Connections;
-
-class MockCouchModel extends \lithium\data\Model {
- protected $_schema = array(
- 'someKey' => array()
- );
-}
-
-class CouchDbModelTest extends \lithium\test\Unit {
-
- public function setUp() {
- MockCouchModel::meta(array('connection' => 'test'));
- }
-
- public function tearDown() {
- $results = MockCouchModel::all();
- if ($results->count()) {
- $results->delete();
- }
- }
-
- /**
- * Skip the test if no `test` CouchDb connection available.
- *
- * @return void
- */
- public function skip() {
- $isAvailable = (
- Connections::get('test', array('config' => true)) &&
- Connections::get('test')->isConnected(array('autoConnect' => true))
- );
- $this->skipIf(!$isAvailable, "No test connection available");
-
- $couchConnection = strpos(get_class(Connections::get('test')), 'CouchDb');
- $this->skipIf(!$couchConnection, "Test connection is not CouchDb");
- }
-
- public function testCreate() {
- $result = MockCouchModel::create()->save();
- $this->assertTrue($result);
- }
-
- public function testSavingIdWithLockedModel() {
- $id = 'myCustomId';
- $model = MockCouchModel::create(compact('id'));
- $result = $model->save();
-
- $this->assertTrue($result);
-
- $data = $model->data();
- $expected = $id;
- $this->assertNotEqual($expected, $data['id']);
- }
-
- public function testSavingIdWithUnlockedModel() {
- MockCouchModel::meta(array('locked' => false));
- $id = 'myCustomId';
- $model = MockCouchModel::create(compact('id'));
- $result = $model->save();
- $this->assertTrue($result);
-
- $data = $model->data();
- $expected = $id;
- $this->assertEqual($expected, $data['id']);
- }
-
- public function testUpdate() {
- $model = MockCouchModel::create(array('someKey' => 'someValue'));
- $result = $model->save();
- $this->assertTrue($result);
-
- $data = $model->data();
-
- $this->assertTrue(array_key_exists('id', $data));
- $this->assertTrue(array_key_exists('rev', $data));
-
- $expected = 'someValue';
- $this->assertEqual($expected, $data['someKey']);
-
- $model->someKey = 'someOtherValue';
- $result = $model->save();
- $this->assertTrue($result);
-
- $updated = $model->data();
-
- $expected = 'someOtherValue';
- $this->assertEqual($expected, $updated['someKey']);
- $this->assertEqual($data['id'], $updated['id']);
- $this->assertNotEqual($data['rev'], $updated['rev']);
- }
-
-}
-
-?>
\ No newline at end of file