public function testDelete() { $existing = Companies::first(); $this->assertTrue($existing->exists()); $this->assertTrue($existing->delete()); $this->assertNull(Companies::first(array('conditions' => Companies::key($existing)))); $this->assertIdentical(0, Companies::count()); }
/** * Skip the test if no test database connection available. */ public function skip() { $connection = 'lithium_couch_test'; $config = Connections::get($connection, array('config' => true)); $isAvailable = $config && Connections::get($connection)->isConnected(array('autoConnect' => true)); $this->skipIf(!$isAvailable, "No {$connection} connection available."); $this->_key = Companies::key(); $this->_database = $config['database']; $this->_connection = Connections::get($connection); }
public function testRelationshipQuerying() { $connection = $this->_connection; $message = "Relationships are not supported by this adapter."; $this->skipIf(!$connection::enabled('relationships'), $message); foreach ($this->companiesData as $data) { Companies::create($data)->save(); } $stuffMart = Companies::findFirstByName('StuffMart'); $maAndPas = Companies::findFirstByName('Ma \'n Pa\'s Data Warehousing & Bait Shop'); $this->assertEqual($this->_classes['employees'], $stuffMart->employees->model()); $this->assertEqual($this->_classes['employees'], $maAndPas->employees->model()); foreach (array('Mr. Smith', 'Mr. Jones', 'Mr. Brown') as $name) { $stuffMart->employees[] = Employees::create(compact('name')); } $expected = Companies::key($stuffMart) + array('name' => 'StuffMart', 'active' => true, 'employees' => array(array('name' => 'Mr. Smith'), array('name' => 'Mr. Jones'), array('name' => 'Mr. Brown'))); $this->assertEqual($expected, $stuffMart->data()); $this->assertTrue($stuffMart->save()); $this->assertEqual('Smith', $stuffMart->employees[0]->lastName()); $stuffMartReloaded = Companies::findFirstByName('StuffMart'); $this->assertEqual('Smith', $stuffMartReloaded->employees[0]->lastName()); foreach (array('Ma', 'Pa') as $name) { $maAndPas->employees[] = Employees::create(compact('name')); } $maAndPas->save(); }