[pLog-svn] r4000 - in plog/branches/lifetype-1.1.1/class: net/xmlrpc test/tests/extra test/tests/net/xmlrpc

pwestbro at devel.lifetype.net pwestbro at devel.lifetype.net
Wed Sep 20 16:46:04 GMT 2006


Author: pwestbro
Date: 2006-09-20 16:46:04 +0000 (Wed, 20 Sep 2006)
New Revision: 4000

Removed:
   plog/branches/lifetype-1.1.1/class/test/tests/extra/xmlrpcserver_test.class.php
Modified:
   plog/branches/lifetype-1.1.1/class/net/xmlrpc/xmlrpcserver.class.php
   plog/branches/lifetype-1.1.1/class/test/tests/net/xmlrpc/xmlrpcserver_test.class.php
Log:
Fixed some of the xmlrpc tests.  
Added test for metaWeblog.newPost and metaWeblog.getRecentPosts.  
Added test to make sure thet the extended text seperator is returned.
Removed the old version of the xmlrpcserver test file



Modified: plog/branches/lifetype-1.1.1/class/net/xmlrpc/xmlrpcserver.class.php
===================================================================
--- plog/branches/lifetype-1.1.1/class/net/xmlrpc/xmlrpcserver.class.php	2006-09-20 09:35:24 UTC (rev 3999)
+++ plog/branches/lifetype-1.1.1/class/net/xmlrpc/xmlrpcserver.class.php	2006-09-20 16:46:04 UTC (rev 4000)
@@ -304,7 +304,9 @@
                         $artNotifications = new ArticleNotifications();
                         $artNotifications->addNotification( $postid, $blogid, $userInfo->getId());
                     }
-                    
+
+ 					$this->setResponseCharset( $blogInfo );
+                   
                     return sprintf( "%d", $postid );
                 } else
                 {

Deleted: plog/branches/lifetype-1.1.1/class/test/tests/extra/xmlrpcserver_test.class.php
===================================================================
--- plog/branches/lifetype-1.1.1/class/test/tests/extra/xmlrpcserver_test.class.php	2006-09-20 09:35:24 UTC (rev 3999)
+++ plog/branches/lifetype-1.1.1/class/test/tests/extra/xmlrpcserver_test.class.php	2006-09-20 16:46:04 UTC (rev 4000)
@@ -1,203 +0,0 @@
-<?php
-
-	include_once( PLOG_CLASS_PATH."class/test/helpers/lifetypetestcase.class.php" );
-	include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
-	include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
-	include_once( PLOG_CLASS_PATH."class/dao/bloginfo.class.php" );	
-	include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
-	include_once( PLOG_CLASS_PATH."class/dao/userinfo.class.php" );	
-	include_once( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
-	include_once( PLOG_CLASS_PATH."class/dao/articlecategory.class.php" );
-	include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
-	include_once( PLOG_CLASS_PATH."class/dao/userstatus.class.php" );	
-	include_once( PLOG_CLASS_PATH."class/net/xmlrpc/IXR_Library.lib.php" );
-	include_once( PLOG_CLASS_PATH."class/net/url.class.php" );
-	include_once( 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 at 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", 
-			                            "",
-										$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());
-		}
-
-		/**
-		 * Needed for test case testXmlRpcResponseEncoding, as the IXR_Client class is not
-		 * exposing the "raw" response that was received from the server, and we actually
-		 * need that.
-		 *
-		 * @private
-		 */
-		function rawHttpQuery( $httpUrl, $string, $debug = false )
-		{
-			$url = new Url( $httpUrl );
-	        $length = strlen( $string );
-	        $xml = $string;		
-	        $r = "\r\n";
-			$server = $url->getHost();
-	        $request  = "POST ".$url->getPath()." HTTP/1.0$r";
-	        $request .= "Host: ".$url->getHost()."$r";
-	        $request .= "Content-Type: text/xml$r";
-	        $request .= "User-Agent: LifeType test suite$r";
-	        $request .= "Content-length: {$length}$r$r";
-	        $request .= $xml;
-	        // Now send the request
-	        if ($debug) {
-	            echo '<pre>'.htmlspecialchars($request)."\n</pre>\n\n";
-	        }
-	        $fp = @fsockopen($server, 80);
-	        if (!$fp) {
-	            return false;	
-	        }
-	        fputs($fp, $request);
-	        $contents = '';
-	        $gotFirstLine = false;
-	        $gettingHeaders = true;		
-	        while (!feof($fp)) {
-	            $line = fgets($fp, 4096);
-	            if (!$gotFirstLine) {
-	                // Check line for '200'
-	                if (strstr($line, '200') === false) {
-	                    return false;
-	                }
-	                $gotFirstLine = true;
-	            }
-	            if (trim($line) == '') {
-	                $gettingHeaders = false;
-	            }
-	            if (!$gettingHeaders) {
-	                $contents .= trim($line)."\n";
-	            }
-	        }
-	
-			if( $debug )
-				print("<pre>".htmlspecialchars($contents)."</pre>");
-	
-			return( $contents );
-		}
-		
-		/**
-		 * test case for Mantis issue 1047 (http://bugs.lifetype.net/view.php?id=1047)
-		 * The XMLRPC server is not using the right encoding for responses and it should
-		 * default to the blog's encoding
-		 */
-		function testXmlRpcResponseEncoding()
-		{
-			// send a raw blogger.newPost request
-			$request = "<?xml version=\"1.0\"?>
-<methodCall>
-<methodName>blogger.newPost</methodName>
-<params>
-<param><value><string>appkey</string></value></param>
-<param><value><int>".$this->blog->getId()."</int></value></param>
-<param><value><string>".$this->owner->getUsername()."</string></value></param>
-<param><value><string>password</string></value></param>
-<param><value><string>blah blah blah</string></value></param>
-<param><value><boolean>1</boolean></value></param>
-</params></methodCall>";
-			$response = $this->rawHttpQuery( $this->url, $request, true );	
-			          
-			// check that it worked
-			$this->assertTrue( $response, "Unable to query ".$this->url." with method blogger.newPost" );
-			
-			// delete the post and at the same time check if the post was added correctly
-			$this->assertFalse( strstr( $response, "faultString" ), "Error calling blogger.newPost" );
-			$numMatches = preg_match( "/<string>(.*)<\/string>/i", 
-			                        $response,
-			                        $tmp );
-			$this->assertEquals( 1, $numMatches, "Error calling blogger.newPost" );
-			$postId = $tmp[1];
-			$articles = new Articles();
-			$articles->deleteArticle( $postId, $this->blog->getId(), $this->owner->getId(), true );
-			
-			
-			// check the character encoding in the response
-			$numMatches = preg_match( "/<\\?xml.*version=\"1.0\".*encoding=\"(.*)\".*\?>.*/i", 
-			                        $response,
-			                        $matches );
-			$this->assertEquals( 1, $numMatches, "No encoding information found in XMLRPC response!" );
-			$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();
-			$this->assertEquals( $blogEncoding, $encoding, "The blog encoding and the response of the XMLRPC request did not match!" );			
-		}
-	}
-?>
\ No newline at end of file

Modified: plog/branches/lifetype-1.1.1/class/test/tests/net/xmlrpc/xmlrpcserver_test.class.php
===================================================================
--- plog/branches/lifetype-1.1.1/class/test/tests/net/xmlrpc/xmlrpcserver_test.class.php	2006-09-20 09:35:24 UTC (rev 3999)
+++ plog/branches/lifetype-1.1.1/class/test/tests/net/xmlrpc/xmlrpcserver_test.class.php	2006-09-20 16:46:04 UTC (rev 4000)
@@ -161,6 +161,39 @@
 			$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!" );
+			
 		}
 		
 		/**
@@ -439,11 +472,131 @@
 			// 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 testMetaWebogNewPost()
+		{
+			$c = new IXR_Client( $this->url );
+            $content  = array();
+            $content["title"] = "topic";
+            $content["description"] = "body 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( "body text", $article->getText(false));
+			$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 **/
+            $content  = array();
+            $content["title"] = "topic";
+            $content["description"] = "Intro text" . POST_EXTENDED_TEXT_MODIFIER . "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!" );
+			
+		}
+		
+
+		
+		/** 
+		 * test case for the metaWeblog.getPost method call
+		 */
 		function testMetaWeblogGetPost()
 		{
 			// create a new post first
@@ -475,8 +628,8 @@
 			
 			// 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", $article->getTopic(), "The topic of the post does not match" );
-			$this->assertEquals( "text", $article->getText(), "The text 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" );
@@ -488,6 +641,53 @@
 			// 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( "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" . POST_EXTENDED_TEXT_MODIFIER . "Extended 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!" );			
+
+
 		}
 		
 		/** 
@@ -526,7 +726,54 @@
 		
 		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 );			
+			
 		}
 		
 		/**



More information about the pLog-svn mailing list