📄 xmlrpcserver_test.class.php
字号:
$this->owner->getId(), $this->blog->getId(), POST_STATUS_PUBLISHED, 0 ); $this->assertTrue( $articles->addArticle( $article ), "Unable to add a new test article" ); // make the method call $c = new IXR_Client( $this->url ); $res = $c->query( "metaWeblog.getPost", $article->getId(), $this->owner->getUsername(), "password" ); // see that the call was successful $this->assertTrue( $res, "Unable to query ".$this->url." with method metaweblog.getPost" ); // make sure that the call returned ok $response = $c->getResponse(); $this->assertTrue( $response, "metaWeblog.getPost did not return a valid response" ); // and now compare that the returned values match with what we expected $this->assertEquals( $this->owner->getId(), $response["userid"], "The user id of the article does not match" ); $this->assertEquals( "topic", $response["title"], "The topic of the post does not match" ); $this->assertEquals( "Intro text", $response["description"], "The text of the article does not match" ); $this->assertEquals( $article->getId(), $response["postid"] ); $url = $this->blog->getBlogRequestGenerator(); $this->assertEquals( $url->postLink( $article ), $response["link"], "The post permalink does not match" ); $this->assertEquals( $url->postPermalink( $article ), $response["permaLink"], "The post permalink does not match" ); $this->assertTrue( $articles->deleteArticle( $article->getId(), $this->owner->getId(), $this->blog->getId(), true ), "Error deleting article" ); // 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!" ); // EXTENDED TEXT, with extended text in mt_more_text // create a new post first $article = new Article( "topic", "Intro text" . POST_EXTENDED_TEXT_MODIFIER . "Extended text", Array( $this->cat->getId()), $this->owner->getId(), $this->blog->getId(), POST_STATUS_PUBLISHED, 0 ); // Store the setting that mt_more_text should be used $blogSettings = $this->blog->getSettings(); $blogSettings->setValue( "xmlrpc_movabletype_enabled", true ); $this->blog->setSettings( $blogSettings ); $blogs = new Blogs(); $blogs->updateBlog( $this->blog ); $this->assertTrue( $articles->addArticle( $article ), "Unable to add a new test article" ); // make the method call $c = new IXR_Client( $this->url ); $res = $c->query( "metaWeblog.getPost", $article->getId(), $this->owner->getUsername(), "password" ); // see that the call was successful $this->assertTrue( $res, "Unable to query ".$this->url." with method metaweblog.getPost" ); // make sure that the call returned ok $response = $c->getResponse(); $this->assertTrue( $response, "metaWeblog.getPost did not return a valid response" ); // and now compare that the returned values match with what we expected $this->assertEquals( $this->owner->getId(), $response["userid"], "The user id of the article does not match" ); $this->assertEquals( "topic", $response["title"], "The topic of the post does not match" ); $this->assertEquals( "Intro text", $response["description"], "The text of the article does not match" ); $this->assertEquals( "Extended text", $response["mt_text_more"], "The text of the extended text does not match" ); $this->assertEquals( $article->getId(), $response["postid"] ); $url = $this->blog->getBlogRequestGenerator(); $this->assertEquals( $url->postLink( $article ), $response["link"], "The post permalink does not match" ); $this->assertEquals( $url->postPermalink( $article ), $response["permaLink"], "The post permalink does not match" ); $this->assertTrue( $articles->deleteArticle( $article->getId(), $this->owner->getId(), $this->blog->getId(), true ), "Error deleting article" ); // 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!" ); // Restore the setting $blogSettings = $this->blog->getSettings(); $blogSettings->setValue( "xmlrpc_movabletype_enabled", false ); $this->blog->setSettings( $blogSettings ); $blogs->updateBlog( $this->blog ); } /** * Test the metaWeblog.getCategories */ function testMetaWeblogGetCategories() { // make the method call $c = new IXR_Client( $this->url ); $res = $c->query( "metaWeblog.getCategories", $this->blog->getId(), $this->owner->getUsername(), "password" ); // see that the call was successful $this->assertTrue( $res, "Unable to query ".$this->url." with method metaweblog.getCategories" ); // make sure that the call returned ok $response = $c->getResponse(); $this->assertTrue( $response, "metaWeblog.getCategories did not return a valid response" ); // there should only be one category $this->assertTrue(( count( $response ) == 1 ), "There should only be one category returned by metaWeblog.getCategories" ); // check that the category settings are correct $this->assertEquals( $this->cat->getName(), key($response), "The category name did not match" ); $this->assertEquals( $this->cat->getDescription(), $response["General"]["description"], "The category description did not match" ); $url = $this->blog->getBlogRequestGenerator(); $url->setXHTML( false ); $this->assertEquals( $url->categoryLink( $this->cat ), $response["General"]["htmlUrl"], "The category link 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!" ); } function testMTGetCategoryList() { // make the method call $c = new IXR_Client( $this->url ); $res = $c->query( "mt.getCategoryList", $this->blog->getId(), $this->owner->getUsername(), "password" ); // see that the call was successful $this->assertTrue( $res, "Unable to query ".$this->url." with method mt.getCategoryList" ); // make sure that the call returned ok $response = $c->getResponse(); $this->assertTrue( $response, "mt.getCategoryList did not return a valid response" ); // there should only be one category $this->assertTrue(( count( $response ) == 1 ), "There should only be one category returned by mt.getCategoryList" ); // check that the category settings are correct $this->assertEquals( $this->cat->getName(), $response[0]["categoryName"], "The category name did not match" ); $this->assertEquals( $this->cat->getId(), $response[0]["categoryId"], "The category description 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!" ); } function testMetaWeblogGetRecentPosts() { // 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 the first tet article" ); $article2 = new Article( "topic 2", "text 2", Array( $this->cat->getId()), $this->owner->getId(), $this->blog->getId(), POST_STATUS_PUBLISHED, 0 ); $this->assertTrue( $articles->addArticle( $article ), "Unable to add the second test article" ); // make the method call $c = new IXR_Client( $this->url ); $res = $c->query( "metaWeblog.getRecentPosts", $this->blog->getId(), $this->owner->getUsername(), "password", 10 ); // see that the call was successful $this->assertTrue( $res, "Unable to query ".$this->url." with method metaWeblog.getRecentPosts" ); // make sure that the call returned ok $response = $c->getResponse(); $this->assertTrue( $response, "metaWeblog.getRecentPosts did not return a valid response" ); // and make sure that we got two articles $this->assertEquals( 2, count($response), "The number of articles returned by metaWeblog.getRecentPosts is not correct" ); // 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 articles $articles->deleteArticle( $article->getId(), $this->owner->getId(), $this->blog->getId(), true ); $articles->deleteArticle( $article2->getId(), $this->owner->getId(), $this->blog->getId(), true ); } function testMTSupportedTextFilters() { // make the method call $c = new IXR_Client( $this->url ); $res = $c->query( "mt.supportedTextFilters"); // see that the call was successful $this->assertTrue( $res, "Unable to query ".$this->url." with method mt.supportedTextFilters" ); // make sure that the call returned ok // there should be no filters $response = $c->getResponse(); $this->assertFalse( $response, "mt.supportedTextFilters return an unexpected response" ); } function testMTGetPostCategories() { // 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 test article" ); // make the method call $c = new IXR_Client( $this->url ); $res = $c->query( "mt.getPostCategories", $article->getId(), $this->owner->getUsername(), "password" ); // see that the call was successful $this->assertTrue( $res, "Unable to query ".$this->url." with method mt.getPostCategories" ); // make sure that the call returned ok $response = $c->getResponse(); $this->assertTrue( $response, "mt.getPostCategories did not return a valid response" ); // There should only be one category $this->assertEquals( 1, count($response), "The number of categories returned by mt.getPostCategories is not correct" ); // and now compare that the returned values match with what we expected $this->assertEquals( $this->cat->getName(), $response[0]["categoryName"], "The category name did not match" ); $this->assertEquals( $this->cat->getId(), $response[0]["categoryId"], "The category description did not match" ); $this->assertTrue( $articles->deleteArticle( $article->getId(), $this->owner->getId(), $this->blog->getId(), true ), "Error deleting article" ); // 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!" ); } function testMTSetPostCategories() { // create a new post first, with no category $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 test article" ); // another category $cat2 = new ArticleCategory( "General2", "Description for category General2", $this->blog->getId(), true ); $cats = new ArticleCategories(); if( !$cats->addArticleCategory( $cat2 )) { throw( new Exception( "Error adding test category!" )); die(); } // Construct the Category Struct $categories = Array(); $theCategory = Array(); $theCategory["categoryName"] = $cat2->getName(); $theCategory["categoryId"] = $cat2->getId(); $categories[] = $theCategory; // make the method call $c = new IXR_Client( $this->url ); $res = $c->query( "mt.setPostCategories", $article->getId(), $this->owner->getUsername(), "password", $categories ); // see that the call was successful $this->assertTrue( $res, "Unable to query ".$this->url." with method mt.setPostCategories" ); // make sure that the call returned ok $response = $c->getResponse(); $this->assertTrue( $response, "mt.setPostCategories did not return a valid response" ); // check that the post was successfully updated $updatedArticle = $articles->getArticle( $article->getId()); $this->assertEquals( $cat2->getId(), $updatedArticle->_categoryIds[0]); $cats->deleteCategory( $cat2->getId(), $this->blog->getId()); // 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!" ); } /** * @private */ function checkResponseEncoding( $response, $blog ) { // check the character encoding in the response $numMatches = preg_match( "/<\\?xml.*version=\"1.0\".*encoding=\"(.*)\".*\?>.*/i", $response, $matches ); if( $numMatches != 1 ) return false; $encoding = $matches[1]; // check that the blog encoding and what we got in the response is the same $locale = $this->blog->getLocale(); $blogEncoding = $locale->getCharSet(); return( $locale->getCharset() == $encoding ); } }?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -