getRepository($parameters); return $repository; } function printForum($forum) { foreach($forum->getTopics() as $topic) { printTopic('', $topic); } } function printTopic($indent, $topic) { echo $indent . "Topic:\r\n"; echo $indent . "Name = " . $topic->getName() . "\r\n"; echo $indent . "Description = " . $topic->getDescription() . "\r\n"; foreach($topic->getPosts() as $post) { printPost($indent . ' ', $post); } } function printPost($indent, $post) { echo $indent . "Post:\r\n"; echo $indent . "Author = " . $post->getAuthor() . "\r\n"; echo $indent . "Time = " . date('Y-m-d H:i:s', $post->getTime()) . "\r\n"; echo $indent . "Title = " . $post->getTitle() . "\r\n"; echo $indent . "Body = " . $post->getBody() . "\r\n"; foreach($post->getVersions() as $v) { echo $indent . "Version = (" . date('Y-m-d H:i:s', $v->getTime()) . "," . $v->getBody() . ")\r\n"; } foreach($post->getComments() as $comment) { printComment($indent . ' ', $comment); } } function printComment($indent, $comment) { echo $indent . "Comment:\r\n"; echo $indent . "Author = " . $comment->getAuthor() . "\r\n"; echo $indent . "Time = " . date('Y-m-d H:i:s', $comment->getTime()) . "\r\n"; echo $indent . "Number = " . $comment->getNumber() . "\r\n"; echo $indent . "Text = " . $comment->getText() . "\r\n"; foreach($comment->getVersions() as $v) { echo $indent . "Version = (" . date('Y-m-d H:i:s', $v->getTime()) . "," . $v->getText() . ")\r\n"; } foreach($comment->getComments() as $comment2) { printComment($indent . ' ', $comment2); } } function testForumLoad($forummanager) { $modelmapper = new ModelMapper($forummanager); printForum($modelmapper->loadForum()); } function testTopicLoad($forummanager, $path) { echo 'Load: ' . $path . "\r\n"; $modelmapper = new ModelMapper($forummanager); printTopic("", $modelmapper->loadTopic($path, true)); } function testPostLoad($forummanager, $path) { echo 'Load: ' . $path . "\r\n"; $modelmapper = new ModelMapper($forummanager); printPost("", $modelmapper->loadPost($path, true)); } function testCommentLoad($forummanager, $path) { echo 'Load: ' . $path . "\r\n"; $modelmapper = new ModelMapper($forummanager); printComment("", $modelmapper->loadComment($path, true)); } function testPostAuthorSearch($forummanager, $author) { echo 'Post author search for ' . $author . ":\r\n"; $modelmapper = new ModelMapper($forummanager); foreach($modelmapper->findPostByAuthor($author, true) as $p) { printPost('', $p); } } function testPostContentSearch($forummanager, $content) { echo 'Post content search for ' . $content . ":\r\n"; $modelmapper = new ModelMapper($forummanager); foreach($modelmapper->findPostByContent($content, true) as $p) { printPost('', $p); } } function testCommentAuthorSearch($forummanager, $author) { echo 'Comment author search for ' . $author . ":\r\n"; $modelmapper = new ModelMapper($forummanager); foreach($modelmapper->findCommentByAuthor($author, true) as $c) { printComment('', $c); } } function testCommentContentSearch($forummanager, $content) { echo 'Comment content search for ' . $content . ":\r\n"; $modelmapper = new ModelMapper($forummanager); foreach($modelmapper->findCommentByContent($content, true) as $c) { printComment('', $c); } } function test($factory, $parameters, $usr, $pwd, $verssup = true) { $repo = getRepository($factory, $parameters); $forummanager = new ForumManager($repo, $usr, $pwd, $verssup); // add 2 topics $smart = $forummanager->addTopic('Smart questions', 'This is for smart questions'); $dumb = $forummanager->addTopic('Dumb questions', 'This is for dumb questions'); // add 3 posts $plus1 = $forummanager->addPost($dumb, 'What is 1+1?', 'I have a math question: what is 1+1?', 'arne'); $plus2 = $forummanager->addPost($dumb, 'What is 2+2?', 'I have another math question: what is 2+2?', 'arne'); $life = $forummanager->addPost($smart, 'What is the purpose of life?', 'I am in the philosophical mood. What is the purpose of life?', 'arne'); // add 4 comments $plus1a = $forummanager->addCommentAutoNumber($plus1, '2', 'arne'); $plus2a = $forummanager->addCommentAutoNumber($plus2, '4', 'arne'); $lifea1 = $forummanager->addCommentAutoNumber($life, 'Good question.', 'arne'); $lifea2 = $forummanager->addCommentAutoNumber($life, 'Please tell me if you find out.', 'arne'); // add 2 comments to comments to comments $forummanager->addCommentAutoNumber($plus1a, 'Hmmm.', 'Arne'); $forummanager->addCommentAutoNumber($plus2a, 'Hmmm.', 'Arne'); // update 1 comment twice if($verssup) { sleep(1); $forummanager->updateComment($plus1a, 'Forget it.'); $forummanager->updateComment($plus2a, 'Forget it.'); sleep(1); $forummanager->updateComment($plus1a, 'Sorry.'); $forummanager->updateComment($plus2a, 'Sorry.'); } // test load testForumLoad($forummanager); testTopicLoad($forummanager, $smart); testPostLoad($forummanager, $life); testCommentLoad($forummanager, $lifea1); testCommentLoad($forummanager, $lifea2); // test search testPostAuthorSearch($forummanager, 'xxx'); testPostAuthorSearch($forummanager, 'arne'); testPostContentSearch($forummanager, 'math'); testPostContentSearch($forummanager, 'foobar'); testCommentAuthorSearch($forummanager, 'xxx'); testCommentAuthorSearch($forummanager, 'arne'); testCommentContentSearch($forummanager, 'good'); testCommentContentSearch($forummanager, 'foobar'); } ?>