📄 xmlrpcserver_test.class.php
字号:
<?php lt_include( PLOG_CLASS_PATH."class/test/helpers/testtools.class.php" ); lt_include( PLOG_CLASS_PATH."class/test/helpers/lifetypetestcase.class.php" ); lt_include( PLOG_CLASS_PATH."class/config/config.class.php" ); lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" ); lt_include( PLOG_CLASS_PATH."class/dao/bloginfo.class.php" ); lt_include( PLOG_CLASS_PATH."class/dao/users.class.php" ); lt_include( PLOG_CLASS_PATH."class/dao/userinfo.class.php" ); lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" ); lt_include( PLOG_CLASS_PATH."class/dao/articlecategory.class.php" ); lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" ); lt_include( PLOG_CLASS_PATH."class/dao/userstatus.class.php" ); lt_include( PLOG_CLASS_PATH."class/net/xmlrpc/IXR_Library.lib.php" ); lt_include( PLOG_CLASS_PATH."class/net/url.class.php" ); lt_include( PLOG_CLASS_PATH."class/locale/locales.class.php" ); /** * Unit test cases for xmlrpc.php */ class XmlRpcServer_Test extends LifeTypeTestCase { /** * dummy blog we'll be using during the tests */ var $blog; /** * dummy blog owner */ var $owner; /** * dummy category */ var $cat; /** * URL pointing to this server's xmlrpc.php */ function setUp() { // create the blog owner $this->owner = new UserInfo( md5(time()), // name "password", // password "whatever@whatever.com", // email address "", // about "" ); $users = new Users(); if( !$users->addUser( $this->owner )) { throw( new Exception( "Error adding test user" )); die(); } // load a UTF-8 locale $zhLocale =& Locales::getLocale( "zh_CN" ); // create the test blog $blogs = new Blogs(); $this->blog = null; $this->blog = new BlogInfo( "test blog", $this->owner->getId(), "", new BlogSettings()); $this->blog->setLocale( $zhLocale ); if( !$blogs->addBlog( $this->blog )) { throw( new Exception( "Error adding test blog!" )); die(); } // add a default category $this->cat = new ArticleCategory( "General", "Description for category General", $this->blog->getId(), true ); $cats = new ArticleCategories(); if( !$cats->addArticleCategory( $this->cat )) { throw( new Exception( "Error adding test category!" )); die(); } // get the URL pointing to xmlrpc.php $config =& Config::getConfig(); $this->url = $config->getValue( "base_url" )."/xmlrpc.php"; } function tearDown() { $users = new Users(); $users->deleteUser( $this->owner->getId()); $blogs = new Blogs(); $blogs->deleteBlog( $this->blog->getId()); $cats = new ArticleCategories(); $cats->deleteCategory( $this->cat->getId(), $this->blog->getId()); } /** * test the blogger.newPost method call */ function testBloggerNewPost() { $c = new IXR_Client( $this->url ); $res = $c->query( "blogger.newPost", "appkey", $this->blog->getId(), $this->owner->getUsername(), "password", "blah blah", true ); // see that the call was successful $this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.newPost" ); // get the post id and check it in the db $artId = $c->getResponse(); $articles = new Articles(); $article = $articles->getArticle( $artId ); $this->assertTrue( $article, "Could not load article with id = ".$artId ); if( !$article ) return; // check that the post has the expected values $this->assertEquals( "blah blah", $article->getText()); $this->assertEquals( "blah blah", $article->getTopic()); // delete the article $articles->deleteArticle( $artId, $this->owner->getId(), $this->blog->getId(), true ); // get the response and see that it has the right encoding $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog), "The blog encoding and the response of the XMLRPC request did not match!" ); /** test the embedded topic feature **/ $res = $c->query( "blogger.newPost", "appkey", $this->blog->getId(), $this->owner->getUsername(), "password", "topic\nblah blah", true ); // see that the call was successful $this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.newPost" ); // get the post id and check it in the db $artId = $c->getResponse(); $articles = new Articles(); $article = $articles->getArticle( $artId ); $this->assertTrue( $article, "Could not load article with id = ".$artId ); if( !$article ) return; // check that the post has the expected values $this->assertEquals( "blah blah", $article->getText()); $this->assertEquals( "topic", $article->getTopic()); // delete the article $articles->deleteArticle( $artId, $this->owner->getId(), $this->blog->getId(), true ); // get the response and see that it has the right encoding $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog), "The blog encoding and the response of the XMLRPC request did not match!" ); /** test the extended text feature **/ $res = $c->query( "blogger.newPost", "appkey", $this->blog->getId(), $this->owner->getUsername(), "password", "topic\n" . "Intro text" . POST_EXTENDED_TEXT_MODIFIER . "Extended text", true ); // see that the call was successful $this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.newPost" ); // get the post id and check it in the db $artId = $c->getResponse(); $articles = new Articles(); $article = $articles->getArticle( $artId ); $this->assertTrue( $article, "Could not load article with id = ".$artId ); if( !$article ) return; // check that the post has the expected values $this->assertEquals( "topic", $article->getTopic()); $this->assertEquals( "Intro textExtended text", $article->getText()); $this->assertEquals( "Intro text" . POST_EXTENDED_TEXT_MODIFIER . "Extended text", $article->getText(false)); $this->assertEquals( "Intro text", $article->getIntroText()); $this->assertEquals( "Extended text", $article->getExtendedText()); // delete the article $articles->deleteArticle( $artId, $this->owner->getId(), $this->blog->getId(), true ); // get the response and see that it has the right encoding $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog), "The blog encoding and the response of the XMLRPC request did not match!" ); } /** * test the blogger.getUserInfo method cal */ function testBloggerGetUserInfo() { $c = new IXR_Client( $this->url ); $res = $c->query( "blogger.getUserInfo", "appkey", $this->owner->getUsername(), "password" ); // see that the call was successful $this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.getUserInfo" ); // and check the data in the response $userData = $c->getResponse(); $this->assertEquals( $this->owner->getUsername(), $userData["nickname"], "The user nickname did not match!" ); $this->assertEquals( $this->owner->getUsername(), $userData["firstname"], "The user firstname did not match!" ); $this->assertEquals( $this->owner->getEmail(), $userData["email"], "The user email address did not match!" ); $this->assertEquals( $this->owner->getId(), $userData["userid"], "The user id did not match!" ); // get the response and see that it has the right encoding $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog ), "The blog encoding and the response of the XMLRPC request did not match!" ); } /** * test the blogger.getUserInfo method call */ function testBloggerGetUsersBlogs() { $c = new IXR_Client( $this->url ); $res = $c->query( "blogger.getUsersBlogs", "appkey", $this->owner->getUsername(), "password" ); // see that the call was successful $this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.getUsersBlogs" ); // and check the data in the response $blogs = $c->getResponse(); // there should be only one blog $this->assertEquals( $this->blog->getId(), $blogs[0]["blogid"] ); $this->assertEquals( $this->blog->getBlog(), $blogs[0]["blogName"] ); $url = $this->blog->getBlogRequestGenerator(); $this->assertEquals( $url->blogLink(), $blogs[0]["url"] ); // get the response and see that it has the right encoding $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog ), "The blog encoding and the response of the XMLRPC request did not match!" ); } /** * test the metaWeblog.getUsersBlogs method call */ function testMetaweblogGetUsersBlogs() { $c = new IXR_Client( $this->url ); $res = $c->query( "metaWeblog.getUsersBlogs", "appkey", $this->owner->getUsername(), "password" ); // see that the call was successful $this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.getUsersBlogs" ); // and check the data in the response $blogs = $c->getResponse(); // there should be only one blog $this->assertEquals( $this->blog->getId(), $blogs[0]["blogid"] ); $this->assertEquals( $this->blog->getBlog(), $blogs[0]["blogName"] ); $url = $this->blog->getBlogRequestGenerator(); $this->assertEquals( $url->blogLink(), $blogs[0]["url"] ); // get the response and see that it has the right encoding $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog ), "The blog encoding and the response of the XMLRPC request did not match!" ); } /** * test the blogger.editPost method call */ function testBloggerEditPost() { // create a new post first $article = new Article( "topic", "text", Array( $this->cat->getId()), $this->owner->getId(), $this->blog->getId(), POST_STATUS_PUBLISHED, 0 ); $articles = new Articles(); $this->assertTrue( $articles->addArticle( $article ), "Unable to add a new article" ); // make the method call $c = new IXR_Client( $this->url ); $res = $c->query( "blogger.editPost", "appkey", $article->getId(), $this->owner->getUsername(), "password", "updated text", true ); // see that the call was successful $this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.editPost" ); // check the data in the response and make sure we got a 'true' $success = $c->getResponse(); $this->assertTrue( $success, "XMLRPC server returned error while updating the post" ); // check that the post was successfully updated $updatedArticle = $articles->getArticle( $article->getId()); // check that the text is the updated version $this->assertEquals( "updated text", $updatedArticle->getText()); $this->assertEquals( "updated text", $updatedArticle->getTopic()); // get the response and see that it has the right encoding $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog ), "The blog encoding and the response of the XMLRPC request did not match!" ); /*** test the embedded topic feature ***/ // make the method call $c = new IXR_Client( $this->url ); $res = $c->query( "blogger.editPost", "appkey", $article->getId(), $this->owner->getUsername(), "password", "topic\nupdated text", true ); // see that the call was successful $this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.editPost" ); // check the data in the response and make sure we got a 'true' $success = $c->getResponse(); $this->assertTrue( $success, "XMLRPC server returned error while updating the post" ); // check that the post was successfully updated $updatedArticle = $articles->getArticle( $article->getId()); // check that the text is the updated version $this->assertEquals( "updated text", $updatedArticle->getText(), "Article text did not mach the expected text!" ); $this->assertEquals( "topic", $updatedArticle->getTopic(), "Article topic was not set correctly" ); // get the response and see that it has the right encoding $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog ), "The blog encoding and the response of the XMLRPC request did not match!" ); // delete the post $articles->deleteArticle( $updatedArticle->getId(), $this->owner->getId(), $this->blog->getId()); } /** * Test case the blogger.deletePost method call */ function testBloggerDeletePost() { // create a new post first
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -