⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlrpcserver_test.class.php

📁 一个用PHP编写的
💻 PHP
📖 第 1 页 / 共 3 页
字号:
			$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( "blogger.deletePost", 			           "appkey", 					   $article->getId(),					   $this->owner->getUsername(), 					   "password", 					   true );								// see that the call was successful			$this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.deletePost" );						// make sure that the call returned ok			$response = $c->getResponse();			$this->assertTrue( $response, "blogger.deletePost did not return true" );						// check that the post was marked as 'deleted' in the database			$updatedArticle = $articles->getArticle( $article->getId());			$this->assertEquals( $updatedArticle->getStatus(), 			                     POST_STATUS_DELETED, 			                     "Article was not properly deleted after calling blogger.deletePost" );						// 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 case for blogger.getRecentPosts		 */		function testBloggerGetRecentPosts()		{			// 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( "blogger.getRecentPosts", 			           "appkey", 					   $this->blog->getId(),						   $this->owner->getUsername(), 					   "password", 					   10 );								// see that the call was successful			$this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.getRecentPosts" );						// make sure that the call returned ok			$response = $c->getResponse();			$this->assertTrue( $response, "blogger.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 blogger.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 );					}				/**		 * test case for blogger.getPost		 */		function testBloggerGetPost()		{			// 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( "blogger.getPost", 			           "appkey", 					   $article->getId(),					   $this->owner->getUsername(), 					   "password" );								// see that the call was successful			$this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.getPost" );						// make sure that the call returned ok			$response = $c->getResponse();			$this->assertTrue( $response, "blogger.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\ntext", $response["content"] );			$this->assertEquals( $article->getId(), $response["postid"] );			$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)			// 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				);							$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( "blogger.getPost", 			           "appkey", 					   $article->getId(),					   $this->owner->getUsername(), 					   "password" );								// see that the call was successful			$this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.getPost" );						// make sure that the call returned ok			$response = $c->getResponse();			$this->assertTrue( $response, "blogger.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\nIntro text[@more@]Extended text", $response["content"] );			$this->assertEquals( $article->getId(), $response["postid"] );			$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!" );					}				/** 		 * test case for the metaWeblog.getPost method call		 */		function testMetaWeblogNewPost()		{			// create 3 test categories			$cat1 = TestTools::createArticleCategory( $this->blog->getId());			$cat2 = TestTools::createArticleCategory( $this->blog->getId());			$cat3 = TestTools::createArticleCategory( $this->blog->getId());									$c = new IXR_Client( $this->url );			$c->debug=true;            $content  = array();            $content["title"] = "topic";            $content["description"] = "body text";			$content["categories"] = Array( $cat1->getName(), $cat2->getName(), $cat3->getName());			$res = $c->query( "metaWeblog.newPost", 					   $this->blog->getId(), 					   $this->owner->getUsername(), 					   "password", 					   $content, 					   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( "body text", $article->getText(false));			$this->assertEquals( "topic", $article->getTopic());			// check that the categories are correct			$cats = Array( $cat1->getName(), $cat2->getName(), $cat3->getName());			$postCats = $article->getCategories();						$this->assertEquals( count( $cats ), count( $postCats ), "The post did not have as many categories as expected!" );						// 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 **/            $content  = array();            $content["title"] = "topic";            $content["description"] = "Intro text" . POST_EXTENDED_TEXT_MODIFIER . "Extended text";			$content["categories"] = Array( $cat1->getName(), $cat2->getName(), $cat3->getName());			$res = $c->query( "metaWeblog.newPost", 					   $this->blog->getId(), 					   $this->owner->getUsername(), 					   "password", 					   $content, 					   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 extended text  feature through MovableType**/            $content  = array();            $content["title"] = "topic";            $content["description"] = "Intro text";            $content["mt_text_more"] = "Extended text";			$res = $c->query( "metaWeblog.newPost", 					   $this->blog->getId(), 					   $this->owner->getUsername(), 					   "password", 					   $content, 					   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!" );						// delete the test data			TestTools::deleteDaoTestData( Array( $cat1, $cat2, $cat3 ));		}						/** 		 * test case for the metaWeblog.getPost method call		 */		function testMetaWeblogGetPost()		{			// 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( "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( "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			// create a new post first			$article = new Article(				"topic",				"Intro text" . POST_EXTENDED_TEXT_MODIFIER . "Extended text",				Array( $this->cat->getId()),

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -