[pLog-svn] r3977 -
plog/branches/lifetype-1.1.1/class/test/tests/extra
oscar at devel.lifetype.net
oscar at devel.lifetype.net
Sat Sep 16 23:05:26 GMT 2006
Author: oscar
Date: 2006-09-16 23:05:25 +0000 (Sat, 16 Sep 2006)
New Revision: 3977
Added:
plog/branches/lifetype-1.1.1/class/test/tests/extra/xmlrpcserver_test.class.php
Log:
test case for mantis issue 1047 (http://bugs.lifetype.net/view.php?id=1047) -- xmlrpc.php not using the blog character set in XML responses. This test case does not currently pass, I am working on the fix...
Added: 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-16 16:34:01 UTC (rev 3976)
+++ plog/branches/lifetype-1.1.1/class/test/tests/extra/xmlrpcserver_test.class.php 2006-09-16 23:05:25 UTC (rev 3977)
@@ -0,0 +1,203 @@
+<?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
More information about the pLog-svn
mailing list