function testAssociations() { $company = new DummyDecorator(SActiveStore::findByPk('Company', 1), 'test'); $this->assertEqual(1, $company->products->count()); $this->assertEqual(1, $company->countProducts()); $product = new Product(array('name' => 'CD-R', 'price' => '0.75')); $company->products[] = $product; $this->assertEqual(2, $company->products->count()); $this->assertEqual(2, $company->countProducts()); $company->save(); $companyReloaded = new DummyDecorator(SActiveStore::findByPk('Company', 1), 'test'); $this->assertEqual(2, $companyReloaded->products->count()); $this->assertEqual(2, $companyReloaded->countProducts()); }
public function instanciateFixtures() { $instances = array(); $class = $this->className; if (class_exists($class)) { $temp = new $class(null, true); $pk = $temp->identityField; foreach ($this->values as $obj => $values) { $instances[$obj] = SActiveStore::findByPk($class, $values[$pk]); } return $instances; } return false; }
function testSaveWithTimestamps() { $created_date = new SDateTime(2005, 12, 01, 20, 30, 00); $post = SActiveStore::findByPk('Post', 2); $this->assertIsA($post->created_on, 'SDateTime'); $this->assertEqual($created_date, $post->created_on); $this->assertEqual($post->created_on, $post->updated_on); $post->text = 'blo blo blo'; $post->save(); $this->assertNotEqual($post->created_on, $post->updated_on); $today = SDate::today(); $new_post = new Post(array('title' => 'Timestamps and MySQL', 'author' => 'Goldoraf', 'text' => 'ttttt')); $this->assertNull($new_post->created_on); $this->assertNull($new_post->updated_on); $new_post->save(); $this->assertIsA($new_post->created_on, 'SDateTime'); $this->assertIsA($new_post->created_on, 'SDateTime'); $this->assertEqual($new_post->created_on, $new_post->updated_on); $this->assertEqual($today->year, $new_post->created_on->year); $this->assertEqual($today->month, $new_post->created_on->month); $this->assertEqual($today->day, $new_post->created_on->day); }
public function delete() { SActiveStore::findByPk($this->class_name, $this->params['id'])->delete(); $this->redirectTo(array('action' => 'index')); }
function testBuildBeforeChildSaved() { $client = SActiveStore::findByPk('Client', 3); // client without contract $contract = $client->buildContract(array('code' => 'test')); $this->assertEqual($contract, $client->contract); $this->assertTrue($contract->isNewRecord()); $this->assertTrue($client->save()); $this->assertFalse($contract->isNewRecord()); $this->assertEqual($contract, $client->contract); }
protected function findTarget() { return SActiveStore::findByPk($this->assocClass, $this->owner[$this->foreignKey]); }
function testInsertAt() { $new = new SListDecorator(new Topic(array('forum_id' => 2)), 'forum'); $new->save(); $this->assertEqual(1, $new->position); $new = new SListDecorator(new Topic(array('forum_id' => 2)), 'forum'); $new->save(); $this->assertEqual(2, $new->position); $new = new SListDecorator(new Topic(array('forum_id' => 2)), 'forum'); $new->save(); $this->assertEqual(3, $new->position); $new4 = new SListDecorator(new Topic(array('forum_id' => 2)), 'forum'); $new4->save(); $this->assertEqual(4, $new4->position); $new4->insertAt(3); $this->assertEqual(3, $new4->position); $new = new SListDecorator(SActiveStore::findByPk('Topic', $new->id), 'forum'); $this->assertEqual(4, $new->position); $new->insertAt(2); $this->assertEqual(2, $new->position); $new4 = new SListDecorator(SActiveStore::findByPk('Topic', $new4->id), 'forum'); $this->assertEqual(4, $new4->position); $new5 = new SListDecorator(new Topic(array('forum_id' => 2)), 'forum'); $new5->save(); $this->assertEqual(5, $new5->position); $new5->insertAt(1); $this->assertEqual(1, $new5->position); $new4 = new SListDecorator(SActiveStore::findByPk('Topic', $new4->id), 'forum'); $this->assertEqual(5, $new4->position); }