Пример #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
 public function testSqlCreate()
 {
     $this->assertEqual(TLO::sqlCreate('Test1'), "CREATE TABLE test1 (id CHAR(40), foo VARCHAR(25), connected_to__key__id CHAR(40), connected_to__var__somevar VARCHAR(25), connected_to__var__time VARCHAR(25), PRIMARY KEY (id));\n");
     $this->assertFalse(TLO::sqlCreate('Test2'));
     $this->assertEqual(TLO::sqlCreate('Test3'), "CREATE TABLE test3 (id CHAR(40), parent__key__id CHAR(40), baz VARCHAR(25), bar VARCHAR(25), PRIMARY KEY (id));\n");
     $this->assertEqual(TLO::sqlCreate('TestNamed'), "CREATE TABLE test_named (key1 VARCHAR(25), key2 VARCHAR(25), parent__key__id CHAR(40), key1 VARCHAR(25), key2 VARCHAR(25), stuff VARCHAR(25), bar VARCHAR(25), PRIMARY KEY (key1, key2));\n");
 }