예제 #1
0
 public function testGetById()
 {
     $obj = new LeanObject("TestObject");
     $id = microtime();
     $obj->set("testid", $id);
     $obj->save();
     $query = new LeanQuery("TestObject");
     $obj2 = $query->get($obj->getObjectId());
     $this->assertEquals($obj->get("testid"), $obj2->get("testid"));
     $obj->destroy();
 }
예제 #2
0
 public function testSetGeoPoint()
 {
     $obj = new LeanObject("TestObject");
     $obj->set("location", new GeoPoint(39.9, 116.4));
     $obj->save();
     $obj2 = new LeanObject("TestObject", $obj->getObjectId());
     $obj2->fetch();
     $loc = $obj2->get("location");
     $this->assertTrue($loc instanceof GeoPoint);
     $this->assertEquals(39.9, $loc->getLatitude());
     $this->assertEquals(116.4, $loc->getLongitude());
 }
예제 #3
0
 public function testSaveObjectWithNewChildren()
 {
     $a = new LeanObject("TestObject");
     $b = new LeanObject("TestObject");
     $c = new LeanObject("TestObject");
     $a->set("foo", "aar");
     $b->set("foo", "bar");
     $c->set("foo", "car");
     $a->set("mylikes", array($b, "foo"));
     $a->set("dislikes", array($c, 42));
     $a->save();
     $this->assertNotEmpty($a->getObjectId());
     $this->assertNotEmpty($b->getObjectId());
     $this->assertNotEmpty($c->getObjectId());
     LeanObject::destroyAll(array($a, $b, $c));
 }
예제 #4
0
 public function testSaveObjectWithFile()
 {
     $obj = new LeanObject("TestObject");
     $obj->set("name", "alice");
     $file = LeanFile::createWithData("test.txt", "你好,中国!");
     $obj->addIn("files", $file);
     $obj->save();
     $this->assertNotEmpty($obj->getObjectId());
     $this->assertNotEmpty($file->getObjectId());
     $this->assertNotEmpty($file->getUrl());
     $file->destroy();
     $obj->destroy();
 }