Skip to content

Commit

Permalink
Updating the DocumentTest integration test.
Browse files Browse the repository at this point in the history
  • Loading branch information
jails committed Mar 28, 2013
1 parent 435befb commit 7787a1a
Showing 1 changed file with 16 additions and 40 deletions.
56 changes: 16 additions & 40 deletions tests/integration/data/DocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,66 +9,42 @@
namespace lithium\tests\integration\data;

use lithium\data\Connections;
use lithium\tests\mocks\data\Companies;
use lithium\tests\fixture\model\gallery\Galleries;

class DocumentTest extends \lithium\test\Integration {

protected $_database;

protected $_connection = null;

protected $_key = null;
class DocumentTest extends \lithium\tests\integration\data\Base {

/**
* Creating the test database
* Skip the test if no allowed database connection available.
*/
public function setUp() {
$this->_connection->connection->put($this->_database);
public function skip() {
parent::connect($this->_connection);
$this->skipIf(!$this->with(array('MongoDb', 'CouchDb')));
}

/**
* Dropping the test database
*/
public function tearDown() {
$this->_connection->connection->delete($this->_database);
public function setUp() {
Galleries::config(array('meta' => array('connection' => 'test')));
}

/**
* Skip the test if no test database connection available.
*/
public function skip() {
$connection = 'test';
$config = Connections::get($connection, array('config' => true));
$isConnected = $config && Connections::get($connection)->isConnected(array(
'autoConnect' => true
));
$isAvailable = $config && $isConnected;
$this->skipIf(!$isAvailable, "No {$connection} connection available.");

$hasDb = (isset($this->_dbConfig['adapter']) && $this->_dbConfig['adapter'] === 'CouchDb');
$message = 'Test database is either unavailable, or not using a CouchDb adapter';
$this->skipIf(!$hasDb, $message);

$this->_key = Companies::key();
$this->_database = $config['database'];
$this->_connection = Connections::get($connection);
public function tearDown() {
Galleries::remove();
Galleries::reset();
}

public function testUpdateWithNewArray() {
$new = Companies::create(array('name' => 'Acme, Inc.', 'active' => true));
$new = Galleries::create(array('name' => 'Poneys', 'active' => true));

$expected = array('name' => 'Acme, Inc.', 'active' => true);
$expected = array('name' => 'Poneys', 'active' => true);
$result = $new->data();
$this->assertEqual($expected, $result);

$new->foo = array('bar');
$expected = array('name' => 'Acme, Inc.', 'active' => true, 'foo' => array('bar'));
$expected = array('name' => 'Poneys', 'active' => true, 'foo' => array('bar'));
$result = $new->data();
$this->assertEqual($expected, $result);

$this->assertTrue($new->save());

$updated = Companies::find((string) $new->_id);
$updated = Galleries::find((string) $new->_id);
$expected = 'bar';
$result = $updated->foo[0];
$this->assertEqual($expected, $result);
Expand All @@ -77,7 +53,7 @@ public function testUpdateWithNewArray() {

$this->assertTrue($updated->save());

$updated = Companies::find((string) $updated->_id);
$updated = Galleries::find((string) $updated->_id);
$expected = 'baz';
$result = $updated->foo[1];
$this->assertEqual($expected, $result);
Expand Down

0 comments on commit 7787a1a

Please sign in to comment.