Ejemplo n.º 1
0
 public function test_equal()
 {
     $res1 = $this->model->create($this->get_fixture("user1"));
     $res2 = $this->model->create($this->get_fixture("user1"));
     $res3 = $this->model->create($this->get_fixture("user2"));
     $res4 = $this->model->create($this->get_fixture("user2"));
     $this->assertTrue($res1->equals($res2));
     $this->assertTrue($res2->equals($res1));
     $this->assertFalse($res1->equals($res3));
     $this->assertFalse($res3->equals($res1));
     $prop = new ExampleProperty();
     $prop1 = $prop->create(array('name' => 'Property 1'));
     $prop2 = $prop->create(array('name' => 'Property 2'));
     $res1->propertiesLazy = $prop1;
     $res1->propertiesLazy = $prop2;
     $res3->propertiesLazy = $prop1;
     $res3->propertiesLazy = $prop2;
     $this->assertFalse($res1->equals($res2));
     $this->assertFalse($res2->equals($res3));
     $this->assertFalse($res3->equals($res4));
     $this->assertFalse($res4->equals($res1));
     $this->assertFalse($res4->equals($res3));
     $this->assertFalse($res3->equals($res2));
     $this->assertFalse($res2->equals($res1));
     $this->assertFalse($res1->equals($res4));
     $res2->propertiesLazy = $prop1;
     $res2->propertiesLazy = $prop2;
     $res4->propertiesLazy = $prop1;
     $res4->propertiesLazy = $prop2;
     $this->assertTrue($res1->equals($res2));
     $this->assertTrue($res2->equals($res1));
     $this->assertTrue($res3->equals($res4));
     $this->assertTrue($res4->equals($res3));
 }
Ejemplo n.º 2
0
 public function test_many_many()
 {
     $model = $this->model->create($this->get_fixture("user1"));
     $props = new ExampleProperty();
     $prop1 = $props->create(array("name" => "Property 1"));
     $prop2 = $props->create(array("name" => "Property 2"));
     $model->propertiesLazy = $prop1;
     $model->propertiesEager = $prop2;
     $this->assertIsA($model->propertiesLazy, "WaxModelAssociation");
     $this->assertIsA($model->propertiesLazy[0], "ExampleProperty");
     $this->assertIsA($model->propertiesLazy[0]->examples[0], "Example");
     $this->assertIsA($model->propertiesEager, "WaxModelAssociation");
     $this->assertIsA($model->propertiesEager[0], "ExampleProperty");
     $this->assertIsA($model->propertiesEager[0]->examples[0], "Example");
     $this->assertEqual($model->propertiesLazy->count(), 2);
     $this->assertEqual($model->propertiesEager->count(), 2);
     $this->assertEqual($model->propertiesEager(array("name" => "Property 1"))->count(), 1);
     $this->assertEqual($model->propertiesLazy(array("name" => "Property 1"))->count(), 1);
     $model->propertiesLazy->unlink($prop2);
     $this->assertEqual($model->propertiesLazy->count(), 1);
     $model->propertiesLazy = $prop2;
     $this->assertEqual($model->propertiesLazy->count(), 2);
     $model->propertiesEager->unlink($prop1);
     $this->assertEqual($model->propertiesEager->count(), 1);
     $model->propertiesEager = $prop1;
     $this->assertEqual($model->propertiesEager->count(), 2);
     $model->propertiesLazy->unlink($props->all());
     $this->assertEqual($model->propertiesLazy->count(), 0);
     $this->assertEqual($model->propertiesLazy->first(), false);
     $model->propertiesLazy = $prop1;
     $model->propertiesEager = $prop2;
     $model->propertiesEager->unlink($props->all());
     $this->assertEqual($model->propertiesEager->count(), 0);
     $this->assertEqual($model->propertiesEager->first(), false);
 }