Esempio n. 1
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();
 }
Esempio n. 2
0
 public function testDeleteField()
 {
     $obj = new LeanObject("TestObject");
     $obj->delete("tags");
     $this->assertNull($obj->get("tags"));
     $obj->set("tags", array("frontend", "javascript"));
     $this->assertEquals(array("frontend", "javascript"), $obj->get("tags"));
     $obj->delete("tags");
     $this->assertNull($obj->get("tags"));
     $obj->addIn("tags", "frontend");
     $this->assertEquals(array("frontend"), $obj->get("tags"));
 }
Esempio n. 3
0
 public function testEncodeCircularObjectAsPointer()
 {
     $a = new LeanObject("TestObject", "id001");
     $b = new LeanObject("TestObject", "id002");
     $c = new LeanObject("TestObject", "id003");
     $a->set("name", "A");
     $b->set("name", "B");
     $c->set("name", "C");
     $a->addIn("likes", $b);
     $b->addIn("likes", $c);
     $c->addIn("likes", $a);
     $jsonA = LeanClient::encode($a, "toFullJSON");
     $jsonB = $jsonA["likes"][0];
     $jsonC = $jsonB["likes"][0];
     $this->assertEquals("Object", $jsonA["__type"]);
     $this->assertEquals("Object", $jsonB["__type"]);
     $this->assertEquals("Object", $jsonC["__type"]);
     $this->assertEquals("Pointer", $jsonC["likes"][0]["__type"]);
 }