Пример #1
0
 public function testExample1()
 {
     ob_start();
     $this->assertEqual(TLO::sqlCreate('Blog'), "CREATE TABLE blog (id CHAR(40), title VARCHAR(25), content VARCHAR(25), PRIMARY KEY (id));\n");
     $this->assertEqual(TLO::sqlCreate('Link'), "CREATE TABLE link (id CHAR(40), url VARCHAR(25), attached__key__id CHAR(40), PRIMARY KEY (id));\n");
     $this->assertIsA($db = new PDO('sqlite::memory:'), 'PDO');
     $db->exec(TLO::sqlCreateAll());
     TLO::init();
     $this->assertIsA($blog1 = TLO::newObject($db, 'Blog'), 'Blog');
     $blog1->title = "News sites";
     $blog1->content = "I like reading news websites, attached to\n                                   this blog are some of my favourites";
     $blog1->write();
     foreach (array('http://news.bbc.co.uk', 'http://news.yahoo.com') as $url) {
         /*
          * Create the link
          */
         $this->assertIsA($link = TLO::newObject($db, 'Link'), 'Link');
         $link->url = $url;
         $link->write();
         /*
          * Now create a relationship between the blog
          * and the link
          */
         $this->assertIsA($blog1->newRelMany('Attached', $link), 'Attached');
     }
     $this->assertIsA($blog2 = TLO::newObject($db, 'Blog'), 'Blog');
     $blog2->title = "Social media";
     $blog2->content = "I recently discovered lots of 'social media'\n                                   websites where people link lots of\n                                   interesting articles. See attached for some\n                                   examples of this.";
     $blog2->write();
     foreach (array('http://reddit.com', 'http://news.ycombinator.com/') as $url) {
         /*
          * Create the link
          */
         $this->assertIsA($link = TLO::newObject($db, 'Link'), 'Link');
         $link->url = $url;
         $link->write();
         /*
          * Now create a relationship between the blog
          * and the link
          */
         $this->assertIsA($blog2->newRelMany('Attached', $link), 'Attached');
     }
     foreach (TLO::getObjects($db, 'Blog') as $blog) {
         $this->assertIsA($blog, 'Blog');
         printf("Title: %s<br/>\n", $blog->title);
         printf("Content: %s<br/>\n", $blog->content);
         printf("<ol>Attachments:\n");
         foreach ($blog->getRelsMany('Attached') as $attached) {
             $this->assertIsA($attached, 'Attached');
             $this->assertIsA($link = $attached->getRelation(), 'Link');
             printf("<li>%s</li>\n", $link->url);
         }
         printf("</ol>\n");
     }
     printf("<br/>\n\n");
     $output = ob_get_contents();
     ob_end_clean();
     $this->assertEqual($output, "Title: News sites<br/>\nContent: I like reading news websites, attached to\n                                   this blog are some of my favourites<br/>\n<ol>Attachments:\n<li>http://news.bbc.co.uk</li>\n<li>http://news.yahoo.com</li>\n</ol>\nTitle: Social media<br/>\nContent: I recently discovered lots of 'social media'\n                                   websites where people link lots of\n                                   interesting articles. See attached for some\n                                   examples of this.<br/>\n<ol>Attachments:\n<li>http://reddit.com</li>\n<li>http://news.ycombinator.com/</li>\n</ol>\n<br/>\n\n");
 }
Пример #2
0
 /** Fetch a TLORelationship object from the database and add a TLO object to it **/
 public function fetch()
 {
     if ($obj = $this->_statement->fetch()) {
         $obj->setDb($this->_db);
         $obj->storeKeys();
         $obj->storeRelation($this->_rel_class, $this->_rel_key_names);
         # remove the keys
         $objclass = get_class($obj);
         foreach (array_merge(TLO::keyNames($objclass::relationMany()), $this->_rel_key_names) as $key) {
             unset($this->{$key});
         }
         $obj->__setup();
     }
     return $obj;
 }
Пример #3
0
 public function testRelationshipResultIteration()
 {
     $t = TLO::getObject($this->db, 'Test3', array($this->guid2));
     foreach (TLORelationship::getMany($this->db, 'ConnectedTo', $t) as $i => $o) {
         $this->assertNoPattern('/[^0-9]/', $i);
         $this->assertIsA($o, 'ConnectedTo');
         $this->assertIsA($o->getRelation(), 'Test1');
     }
     $this->assertEqual($i, 2);
 }