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"); }
public function testNamed() { # create one, update and write to it, then read it into a new var and assert the changes are there $this->assertIsA($named = TLO::newObject($this->db, 'TestNamed', array('one', 'two')), 'TestNamed'); $named->key1 = 'oneone'; $named->stuff = 'testing'; $named->write($this->db); $this->assertFalse(TLO::getObject($this->db, 'TestNamed', array('one', 'two'))); $this->assertIsA($named2 = TLO::getObject($this->db, 'TestNamed', array('oneone', 'two')), 'TestNamed'); $this->assertEqual($named2->stuff, 'testing'); $named->key2 = 'twotwo'; $named->write($this->db); $this->assertFalse(TLO::getObject($this->db, 'TestNamed', array('one', 'two'))); $this->assertFalse(TLO::getObject($this->db, 'TestNamed', array('oneone', 'two'))); $this->assertIsA($named3 = TLO::getObject($this->db, 'TestNamed', array('oneone', 'twotwo')), 'TestNamed'); $this->assertEqual($named3->stuff, 'testing'); }