| [ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 lt_include( PLOG_CLASS_PATH."class/test/helpers/testtools.class.php" ); 4 lt_include( PLOG_CLASS_PATH."class/test/helpers/lifetypetestcase.class.php" ); 5 lt_include( PLOG_CLASS_PATH."class/config/config.class.php" ); 6 lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" ); 7 lt_include( PLOG_CLASS_PATH."class/dao/bloginfo.class.php" ); 8 lt_include( PLOG_CLASS_PATH."class/dao/users.class.php" ); 9 lt_include( PLOG_CLASS_PATH."class/dao/userinfo.class.php" ); 10 lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" ); 11 lt_include( PLOG_CLASS_PATH."class/dao/articlecategory.class.php" ); 12 lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" ); 13 lt_include( PLOG_CLASS_PATH."class/dao/userstatus.class.php" ); 14 lt_include( PLOG_CLASS_PATH."class/net/xmlrpc/IXR_Library.lib.php" ); 15 lt_include( PLOG_CLASS_PATH."class/net/url.class.php" ); 16 lt_include( PLOG_CLASS_PATH."class/locale/locales.class.php" ); 17 18 /** 19 * Unit test cases for xmlrpc.php 20 */ 21 class XmlRpcServer_Test extends LifeTypeTestCase 22 { 23 /** 24 * dummy blog we'll be using during the tests 25 */ 26 var $blog; 27 28 /** 29 * dummy blog owner 30 */ 31 var $owner; 32 33 /** 34 * dummy category 35 */ 36 var $cat; 37 38 /** 39 * URL pointing to this server's xmlrpc.php 40 */ 41 42 function setUp() 43 { 44 // create the blog owner 45 $this->owner = new UserInfo( md5(time()), // name 46 "password", // password 47 "whatever@whatever.com", // email address 48 "", // about 49 "" ); 50 $users = new Users(); 51 if( !$users->addUser( $this->owner )) { 52 throw( new Exception( "Error adding test user" )); 53 die(); 54 } 55 56 // load a UTF-8 locale 57 $zhLocale =& Locales::getLocale( "zh_CN" ); 58 59 // create the test blog 60 $blogs = new Blogs(); 61 $this->blog = null; 62 $this->blog = new BlogInfo( "test blog", 63 $this->owner->getId(), 64 "", 65 new BlogSettings()); 66 $this->blog->setLocale( $zhLocale ); 67 if( !$blogs->addBlog( $this->blog )) { 68 throw( new Exception( "Error adding test blog!" )); 69 die(); 70 } 71 72 // add a default category 73 $this->cat = new ArticleCategory( "General", 74 "Description for category General", 75 $this->blog->getId(), 76 true ); 77 78 $cats = new ArticleCategories(); 79 if( !$cats->addArticleCategory( $this->cat )) { 80 throw( new Exception( "Error adding test category!" )); 81 die(); 82 } 83 84 // get the URL pointing to xmlrpc.php 85 $config =& Config::getConfig(); 86 $this->url = $config->getValue( "base_url" )."/xmlrpc.php"; 87 } 88 89 function tearDown() 90 { 91 $users = new Users(); 92 $users->deleteUser( $this->owner->getId()); 93 94 $blogs = new Blogs(); 95 $blogs->deleteBlog( $this->blog->getId()); 96 97 $cats = new ArticleCategories(); 98 $cats->deleteCategory( $this->cat->getId(), $this->blog->getId()); 99 } 100 101 /** 102 * test the blogger.newPost method call 103 */ 104 function testBloggerNewPost() 105 { 106 $c = new IXR_Client( $this->url ); 107 $res = $c->query( "blogger.newPost", 108 "appkey", 109 $this->blog->getId(), 110 $this->owner->getUsername(), 111 "password", 112 "blah blah", 113 true ); 114 115 // see that the call was successful 116 $this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.newPost" ); 117 118 // get the post id and check it in the db 119 $artId = $c->getResponse(); 120 $articles = new Articles(); 121 $article = $articles->getArticle( $artId ); 122 $this->assertTrue( $article, "Could not load article with id = ".$artId ); 123 if( !$article ) 124 return; 125 // check that the post has the expected values 126 $this->assertEquals( "blah blah", $article->getText()); 127 $this->assertEquals( "blah blah", $article->getTopic()); 128 129 // delete the article 130 $articles->deleteArticle( $artId, $this->owner->getId(), $this->blog->getId(), true ); 131 132 // get the response and see that it has the right encoding 133 $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog), 134 "The blog encoding and the response of the XMLRPC request did not match!" ); 135 136 /** test the embedded topic feature **/ 137 $res = $c->query( "blogger.newPost", 138 "appkey", 139 $this->blog->getId(), 140 $this->owner->getUsername(), 141 "password", 142 "topic\nblah blah", 143 true ); 144 145 // see that the call was successful 146 $this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.newPost" ); 147 148 // get the post id and check it in the db 149 $artId = $c->getResponse(); 150 $articles = new Articles(); 151 $article = $articles->getArticle( $artId ); 152 $this->assertTrue( $article, "Could not load article with id = ".$artId ); 153 if( !$article ) 154 return; 155 // check that the post has the expected values 156 $this->assertEquals( "blah blah", $article->getText()); 157 $this->assertEquals( "topic", $article->getTopic()); 158 159 // delete the article 160 $articles->deleteArticle( $artId, $this->owner->getId(), $this->blog->getId(), true ); 161 162 // get the response and see that it has the right encoding 163 $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog), 164 "The blog encoding and the response of the XMLRPC request did not match!" ); 165 166 /** test the extended text feature **/ 167 $res = $c->query( "blogger.newPost", 168 "appkey", 169 $this->blog->getId(), 170 $this->owner->getUsername(), 171 "password", 172 "topic\n" . "Intro text" . POST_EXTENDED_TEXT_MODIFIER . "Extended text", 173 true ); 174 175 // see that the call was successful 176 $this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.newPost" ); 177 178 // get the post id and check it in the db 179 $artId = $c->getResponse(); 180 $articles = new Articles(); 181 $article = $articles->getArticle( $artId ); 182 $this->assertTrue( $article, "Could not load article with id = ".$artId ); 183 if( !$article ) 184 return; 185 // check that the post has the expected values 186 $this->assertEquals( "topic", $article->getTopic()); 187 $this->assertEquals( "Intro textExtended text", $article->getText()); 188 $this->assertEquals( "Intro text" . POST_EXTENDED_TEXT_MODIFIER . "Extended text", $article->getText(false)); 189 $this->assertEquals( "Intro text", $article->getIntroText()); 190 $this->assertEquals( "Extended text", $article->getExtendedText()); 191 192 // delete the article 193 $articles->deleteArticle( $artId, $this->owner->getId(), $this->blog->getId(), true ); 194 195 // get the response and see that it has the right encoding 196 $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog), 197 "The blog encoding and the response of the XMLRPC request did not match!" ); 198 199 } 200 201 /** 202 * test the blogger.getUserInfo method cal 203 */ 204 function testBloggerGetUserInfo() 205 { 206 $c = new IXR_Client( $this->url ); 207 $res = $c->query( "blogger.getUserInfo", 208 "appkey", 209 $this->owner->getUsername(), 210 "password" ); 211 212 // see that the call was successful 213 $this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.getUserInfo" ); 214 215 // and check the data in the response 216 $userData = $c->getResponse(); 217 218 $this->assertEquals( $this->owner->getUsername(), $userData["nickname"], "The user nickname did not match!" ); 219 $this->assertEquals( $this->owner->getUsername(), $userData["firstname"], "The user firstname did not match!" ); 220 $this->assertEquals( $this->owner->getEmail(), $userData["email"], "The user email address did not match!" ); 221 $this->assertEquals( $this->owner->getId(), $userData["userid"], "The user id did not match!" ); 222 223 // get the response and see that it has the right encoding 224 $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog ), 225 "The blog encoding and the response of the XMLRPC request did not match!" ); 226 } 227 228 /** 229 * test the blogger.getUserInfo method call 230 */ 231 function testBloggerGetUsersBlogs() 232 { 233 $c = new IXR_Client( $this->url ); 234 $res = $c->query( "blogger.getUsersBlogs", 235 "appkey", 236 $this->owner->getUsername(), 237 "password" ); 238 239 // see that the call was successful 240 $this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.getUsersBlogs" ); 241 242 // and check the data in the response 243 $blogs = $c->getResponse(); 244 // there should be only one blog 245 $this->assertEquals( $this->blog->getId(), $blogs[0]["blogid"] ); 246 $this->assertEquals( $this->blog->getBlog(), $blogs[0]["blogName"] ); 247 $url = $this->blog->getBlogRequestGenerator(); 248 $this->assertEquals( $url->blogLink(), $blogs[0]["url"] ); 249 250 // get the response and see that it has the right encoding 251 $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog ), 252 "The blog encoding and the response of the XMLRPC request did not match!" ); 253 } 254 255 /** 256 * test the metaWeblog.getUsersBlogs method call 257 */ 258 function testMetaweblogGetUsersBlogs() 259 { 260 $c = new IXR_Client( $this->url ); 261 $res = $c->query( "metaWeblog.getUsersBlogs", 262 "appkey", 263 $this->owner->getUsername(), 264 "password" ); 265 266 // see that the call was successful 267 $this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.getUsersBlogs" ); 268 269 // and check the data in the response 270 $blogs = $c->getResponse(); 271 // there should be only one blog 272 $this->assertEquals( $this->blog->getId(), $blogs[0]["blogid"] ); 273 $this->assertEquals( $this->blog->getBlog(), $blogs[0]["blogName"] ); 274 $url = $this->blog->getBlogRequestGenerator(); 275 $this->assertEquals( $url->blogLink(), $blogs[0]["url"] ); 276 277 // get the response and see that it has the right encoding 278 $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog ), 279 "The blog encoding and the response of the XMLRPC request did not match!" ); 280 } 281 282 /** 283 * test the blogger.editPost method call 284 */ 285 function testBloggerEditPost() 286 { 287 // create a new post first 288 $article = new Article( 289 "topic", 290 "text", 291 Array( $this->cat->getId()), 292 $this->owner->getId(), 293 $this->blog->getId(), 294 POST_STATUS_PUBLISHED, 295 0 296 ); 297 $articles = new Articles(); 298 $this->assertTrue( $articles->addArticle( $article ), "Unable to add a new article" ); 299 300 // make the method call 301 $c = new IXR_Client( $this->url ); 302 $res = $c->query( "blogger.editPost", 303 "appkey", 304 $article->getId(), 305 $this->owner->getUsername(), 306 "password", 307 "updated text", 308 true ); 309 310 // see that the call was successful 311 $this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.editPost" ); 312 313 // check the data in the response and make sure we got a 'true' 314 $success = $c->getResponse(); 315 $this->assertTrue( $success, "XMLRPC server returned error while updating the post" ); 316 317 // check that the post was successfully updated 318 $updatedArticle = $articles->getArticle( $article->getId()); 319 // check that the text is the updated version 320 $this->assertEquals( "updated text", $updatedArticle->getText()); 321 $this->assertEquals( "updated text", $updatedArticle->getTopic()); 322 323 // get the response and see that it has the right encoding 324 $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog ), 325 "The blog encoding and the response of the XMLRPC request did not match!" ); 326 327 /*** test the embedded topic feature ***/ 328 329 // make the method call 330 $c = new IXR_Client( $this->url ); 331 $res = $c->query( "blogger.editPost", 332 "appkey", 333 $article->getId(), 334 $this->owner->getUsername(), 335 "password", 336 "topic\nupdated text", 337 true ); 338 339 // see that the call was successful 340 $this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.editPost" ); 341 342 // check the data in the response and make sure we got a 'true' 343 $success = $c->getResponse(); 344 $this->assertTrue( $success, "XMLRPC server returned error while updating the post" ); 345 346 // check that the post was successfully updated 347 $updatedArticle = $articles->getArticle( $article->getId()); 348 // check that the text is the updated version 349 $this->assertEquals( "updated text", $updatedArticle->getText(), "Article text did not mach the expected text!" ); 350 $this->assertEquals( "topic", $updatedArticle->getTopic(), "Article topic was not set correctly" ); 351 352 // get the response and see that it has the right encoding 353 $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog ), 354 "The blog encoding and the response of the XMLRPC request did not match!" ); 355 356 // delete the post 357 $articles->deleteArticle( $updatedArticle->getId(), $this->owner->getId(), $this->blog->getId()); 358 } 359 360 /** 361 * Test case the blogger.deletePost method call 362 */ 363 function testBloggerDeletePost() 364 { 365 // create a new post first 366 $article = new Article( 367 "topic", 368 "text", 369 Array( $this->cat->getId()), 370 $this->owner->getId(), 371 $this->blog->getId(), 372 POST_STATUS_PUBLISHED, 373 0 374 ); 375 $articles = new Articles(); 376 $this->assertTrue( $articles->addArticle( $article ), "Unable to add a new test article" ); 377 378 // make the method call 379 $c = new IXR_Client( $this->url ); 380 $res = $c->query( "blogger.deletePost", 381 "appkey", 382 $article->getId(), 383 $this->owner->getUsername(), 384 "password", 385 true ); 386 387 // see that the call was successful 388 $this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.deletePost" ); 389 390 // make sure that the call returned ok 391 $response = $c->getResponse(); 392 $this->assertTrue( $response, "blogger.deletePost did not return true" ); 393 394 // check that the post was marked as 'deleted' in the database 395 $updatedArticle = $articles->getArticle( $article->getId()); 396 $this->assertEquals( $updatedArticle->getStatus(), 397 POST_STATUS_DELETED, 398 "Article was not properly deleted after calling blogger.deletePost" ); 399 400 // get the response and see that it has the right encoding 401 $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog ), 402 "The blog encoding and the response of the XMLRPC request did not match!" ); 403 } 404 405 /** 406 * test case for blogger.getRecentPosts 407 */ 408 function testBloggerGetRecentPosts() 409 { 410 // create a new post first 411 $article = new Article( 412 "topic", 413 "text", 414 Array( $this->cat->getId()), 415 $this->owner->getId(), 416 $this->blog->getId(), 417 POST_STATUS_PUBLISHED, 418 0 419 ); 420 $articles = new Articles(); 421 $this->assertTrue( $articles->addArticle( $article ), "Unable to add the first tet article" ); 422 $article2 = new Article( 423 "topic 2", 424 "text 2", 425 Array( $this->cat->getId()), 426 $this->owner->getId(), 427 $this->blog->getId(), 428 POST_STATUS_PUBLISHED, 429 0 430 ); 431 $this->assertTrue( $articles->addArticle( $article ), "Unable to add the second test article" ); 432 433 // make the method call 434 $c = new IXR_Client( $this->url ); 435 $res = $c->query( "blogger.getRecentPosts", 436 "appkey", 437 $this->blog->getId(), 438 $this->owner->getUsername(), 439 "password", 440 10 ); 441 442 // see that the call was successful 443 $this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.getRecentPosts" ); 444 445 // make sure that the call returned ok 446 $response = $c->getResponse(); 447 $this->assertTrue( $response, "blogger.getRecentPosts did not return a valid response" ); 448 // and make sure that we got two articles 449 $this->assertEquals( 2, count($response), "The number of articles returned by blogger.getRecentPosts is not correct" ); 450 451 // get the response and see that it has the right encoding 452 $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog ), 453 "The blog encoding and the response of the XMLRPC request did not match!" ); 454 455 // delete the articles 456 $articles->deleteArticle( $article->getId(), $this->owner->getId(), $this->blog->getId(), true ); 457 $articles->deleteArticle( $article2->getId(), $this->owner->getId(), $this->blog->getId(), true ); 458 } 459 460 /** 461 * test case for blogger.getPost 462 */ 463 function testBloggerGetPost() 464 { 465 // create a new post first 466 $article = new Article( 467 "topic", 468 "text", 469 Array( $this->cat->getId()), 470 $this->owner->getId(), 471 $this->blog->getId(), 472 POST_STATUS_PUBLISHED, 473 0 474 ); 475 $articles = new Articles(); 476 $this->assertTrue( $articles->addArticle( $article ), "Unable to add a new test article" ); 477 478 // make the method call 479 $c = new IXR_Client( $this->url ); 480 $res = $c->query( "blogger.getPost", 481 "appkey", 482 $article->getId(), 483 $this->owner->getUsername(), 484 "password" ); 485 486 // see that the call was successful 487 $this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.getPost" ); 488 489 // make sure that the call returned ok 490 $response = $c->getResponse(); 491 $this->assertTrue( $response, "blogger.getPost did not return a valid response" ); 492 493 // and now compare that the returned values match with what we expected 494 $this->assertEquals( $this->owner->getId(), $response["userid"], "The user id of the article does not match" ); 495 $this->assertEquals( "topic\ntext", $response["content"] ); 496 $this->assertEquals( $article->getId(), $response["postid"] ); 497 498 $this->assertTrue( $articles->deleteArticle( $article->getId(), $this->owner->getId(), $this->blog->getId(), true ), 499 "Error deleting article" ); 500 501 // get the response and see that it has the right encoding 502 $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog ), 503 "The blog encoding and the response of the XMLRPC request did not match!" ); 504 505 // (extended text) 506 // create a new post first 507 $article = new Article( 508 "topic", 509 "Intro text" . POST_EXTENDED_TEXT_MODIFIER . "Extended text", 510 Array( $this->cat->getId()), 511 $this->owner->getId(), 512 $this->blog->getId(), 513 POST_STATUS_PUBLISHED, 514 0 515 ); 516 517 $this->assertTrue( $articles->addArticle( $article ), "Unable to add a new test article" ); 518 // make the method call 519 $c = new IXR_Client( $this->url ); 520 $res = $c->query( "blogger.getPost", 521 "appkey", 522 $article->getId(), 523 $this->owner->getUsername(), 524 "password" ); 525 526 // see that the call was successful 527 $this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.getPost" ); 528 529 // make sure that the call returned ok 530 $response = $c->getResponse(); 531 532 $this->assertTrue( $response, "blogger.getPost did not return a valid response" ); 533 534 // and now compare that the returned values match with what we expected 535 $this->assertEquals( $this->owner->getId(), $response["userid"], "The user id of the article does not match" ); 536 $this->assertEquals( "topic\nIntro text[@more@]Extended text", $response["content"] ); 537 $this->assertEquals( $article->getId(), $response["postid"] ); 538 539 $this->assertTrue( $articles->deleteArticle( $article->getId(), $this->owner->getId(), $this->blog->getId(), true ), 540 "Error deleting article" ); 541 542 // get the response and see that it has the right encoding 543 $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog ), 544 "The blog encoding and the response of the XMLRPC request did not match!" ); 545 546 547 } 548 549 /** 550 * test case for the metaWeblog.getPost method call 551 */ 552 function testMetaWeblogNewPost() 553 { 554 // create 3 test categories 555 $cat1 = TestTools::createArticleCategory( $this->blog->getId()); 556 $cat2 = TestTools::createArticleCategory( $this->blog->getId()); 557 $cat3 = TestTools::createArticleCategory( $this->blog->getId()); 558 559 $c = new IXR_Client( $this->url ); 560 $c->debug=true; 561 $content = array(); 562 $content["title"] = "topic"; 563 $content["description"] = "body text"; 564 $content["categories"] = Array( $cat1->getName(), $cat2->getName(), $cat3->getName()); 565 566 $res = $c->query( "metaWeblog.newPost", 567 $this->blog->getId(), 568 $this->owner->getUsername(), 569 "password", 570 $content, 571 true ); 572 573 // see that the call was successful 574 $this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.newPost" ); 575 576 // get the post id and check it in the db 577 $artId = $c->getResponse(); 578 $articles = new Articles(); 579 $article = $articles->getArticle( $artId ); 580 $this->assertTrue( $article, "Could not load article with id = ".$artId ); 581 if( !$article ) 582 return; 583 // check that the post has the expected values 584 $this->assertEquals( "body text", $article->getText(false)); 585 $this->assertEquals( "topic", $article->getTopic()); 586 // check that the categories are correct 587 $cats = Array( $cat1->getName(), $cat2->getName(), $cat3->getName()); 588 $postCats = $article->getCategories(); 589 590 $this->assertEquals( count( $cats ), count( $postCats ), "The post did not have as many categories as expected!" ); 591 592 // delete the article 593 $articles->deleteArticle( $artId, $this->owner->getId(), $this->blog->getId(), true ); 594 595 // get the response and see that it has the right encoding 596 $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog), 597 "The blog encoding and the response of the XMLRPC request did not match!" ); 598 599 /** test the extended text feature **/ 600 $content = array(); 601 $content["title"] = "topic"; 602 $content["description"] = "Intro text" . POST_EXTENDED_TEXT_MODIFIER . "Extended text"; 603 $content["categories"] = Array( $cat1->getName(), $cat2->getName(), $cat3->getName()); 604 $res = $c->query( "metaWeblog.newPost", 605 $this->blog->getId(), 606 $this->owner->getUsername(), 607 "password", 608 $content, 609 true ); 610 611 // see that the call was successful 612 $this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.newPost" ); 613 614 // get the post id and check it in the db 615 $artId = $c->getResponse(); 616 $articles = new Articles(); 617 $article = $articles->getArticle( $artId ); 618 $this->assertTrue( $article, "Could not load article with id = ".$artId ); 619 if( !$article ) 620 return; 621 // check that the post has the expected values 622 $this->assertEquals( "topic", $article->getTopic()); 623 $this->assertEquals( "Intro textExtended text", $article->getText()); 624 $this->assertEquals( "Intro text" . POST_EXTENDED_TEXT_MODIFIER . "Extended text", $article->getText(false)); 625 $this->assertEquals( "Intro text", $article->getIntroText()); 626 $this->assertEquals( "Extended text", $article->getExtendedText()); 627 628 // delete the article 629 $articles->deleteArticle( $artId, $this->owner->getId(), $this->blog->getId(), true ); 630 631 // get the response and see that it has the right encoding 632 $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog), 633 "The blog encoding and the response of the XMLRPC request did not match!" ); 634 635 /** test the extended text feature through MovableType**/ 636 $content = array(); 637 $content["title"] = "topic"; 638 $content["description"] = "Intro text"; 639 $content["mt_text_more"] = "Extended text"; 640 $res = $c->query( "metaWeblog.newPost", 641 $this->blog->getId(), 642 $this->owner->getUsername(), 643 "password", 644 $content, 645 true ); 646 647 // see that the call was successful 648 $this->assertTrue( $res, "Unable to query ".$this->url." with method blogger.newPost" ); 649 650 // get the post id and check it in the db 651 $artId = $c->getResponse(); 652 $articles = new Articles(); 653 $article = $articles->getArticle( $artId ); 654 $this->assertTrue( $article, "Could not load article with id = ".$artId ); 655 if( !$article ) 656 return; 657 // check that the post has the expected values 658 $this->assertEquals( "topic", $article->getTopic()); 659 $this->assertEquals( "Intro textExtended text", $article->getText()); 660 $this->assertEquals( "Intro text" . POST_EXTENDED_TEXT_MODIFIER . "Extended text", $article->getText(false)); 661 $this->assertEquals( "Intro text", $article->getIntroText()); 662 $this->assertEquals( "Extended text", $article->getExtendedText()); 663 664 // delete the article 665 $articles->deleteArticle( $artId, $this->owner->getId(), $this->blog->getId(), true ); 666 667 // get the response and see that it has the right encoding 668 $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog), 669 "The blog encoding and the response of the XMLRPC request did not match!" ); 670 671 // delete the test data 672 TestTools::deleteDaoTestData( Array( $cat1, $cat2, $cat3 )); 673 } 674 675 676 677 /** 678 * test case for the metaWeblog.getPost method call 679 */ 680 function testMetaWeblogGetPost() 681 { 682 // create a new post first 683 $article = new Article( 684 "topic", 685 "text", 686 Array( $this->cat->getId()), 687 $this->owner->getId(), 688 $this->blog->getId(), 689 POST_STATUS_PUBLISHED, 690 0 691 ); 692 $articles = new Articles(); 693 $this->assertTrue( $articles->addArticle( $article ), "Unable to add a new test article" ); 694 695 // make the method call 696 $c = new IXR_Client( $this->url ); 697 $res = $c->query( "metaWeblog.getPost", 698 $article->getId(), 699 $this->owner->getUsername(), 700 "password" ); 701 702 // see that the call was successful 703 $this->assertTrue( $res, "Unable to query ".$this->url." with method metaweblog.getPost" ); 704 705 // make sure that the call returned ok 706 $response = $c->getResponse(); 707 $this->assertTrue( $response, "metaWeblog.getPost did not return a valid response" ); 708 709 // and now compare that the returned values match with what we expected 710 $this->assertEquals( $this->owner->getId(), $response["userid"], "The user id of the article does not match" ); 711 $this->assertEquals( "topic", $response["title"], "The topic of the post does not match" ); 712 $this->assertEquals( "text", $response["description"], "The text of the article does not match" ); 713 $this->assertEquals( $article->getId(), $response["postid"] ); 714 $url = $this->blog->getBlogRequestGenerator(); 715 $this->assertEquals( $url->postLink( $article ), $response["link"], "The post permalink does not match" ); 716 $this->assertEquals( $url->postPermalink( $article ), $response["permaLink"], "The post permalink does not match" ); 717 718 $this->assertTrue( $articles->deleteArticle( $article->getId(), $this->owner->getId(), $this->blog->getId(), true ), 719 "Error deleting article" ); 720 721 // get the response and see that it has the right encoding 722 $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog ), 723 "The blog encoding and the response of the XMLRPC request did not match!" ); 724 725 // EXTENDED TEXT 726 // create a new post first 727 $article = new Article( 728 "topic", 729 "Intro text" . POST_EXTENDED_TEXT_MODIFIER . "Extended text", 730 Array( $this->cat->getId()), 731 $this->owner->getId(), 732 $this->blog->getId(), 733 POST_STATUS_PUBLISHED, 734 0 735 ); 736 737 738 $this->assertTrue( $articles->addArticle( $article ), "Unable to add a new test article" ); 739 740 // make the method call 741 $c = new IXR_Client( $this->url ); 742 $res = $c->query( "metaWeblog.getPost", 743 $article->getId(), 744 $this->owner->getUsername(), 745 "password" ); 746 747 // see that the call was successful 748 $this->assertTrue( $res, "Unable to query ".$this->url." with method metaweblog.getPost" ); 749 750 // make sure that the call returned ok 751 $response = $c->getResponse(); 752 $this->assertTrue( $response, "metaWeblog.getPost did not return a valid response" ); 753 754 // and now compare that the returned values match with what we expected 755 $this->assertEquals( $this->owner->getId(), $response["userid"], "The user id of the article does not match" ); 756 $this->assertEquals( "topic", $response["title"], "The topic of the post does not match" ); 757 $this->assertEquals( "Intro text", $response["description"], "The text of the article does not match" ); 758 $this->assertEquals( $article->getId(), $response["postid"] ); 759 $url = $this->blog->getBlogRequestGenerator(); 760 $this->assertEquals( $url->postLink( $article ), $response["link"], "The post permalink does not match" ); 761 $this->assertEquals( $url->postPermalink( $article ), $response["permaLink"], "The post permalink does not match" ); 762 763 $this->assertTrue( $articles->deleteArticle( $article->getId(), $this->owner->getId(), $this->blog->getId(), true ), 764 "Error deleting article" ); 765 766 // get the response and see that it has the right encoding 767 $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog ), 768 "The blog encoding and the response of the XMLRPC request did not match!" ); 769 770 771 772 // EXTENDED TEXT, with extended text in mt_more_text 773 // create a new post first 774 $article = new Article( 775 "topic", 776 "Intro text" . POST_EXTENDED_TEXT_MODIFIER . "Extended text", 777 Array( $this->cat->getId()), 778 $this->owner->getId(), 779 $this->blog->getId(), 780 POST_STATUS_PUBLISHED, 781 0 782 ); 783 784 // Store the setting that mt_more_text should be used 785 $blogSettings = $this->blog->getSettings(); 786 $blogSettings->setValue( "xmlrpc_movabletype_enabled", true ); 787 $this->blog->setSettings( $blogSettings ); 788 $blogs = new Blogs(); 789 $blogs->updateBlog( $this->blog ); 790 791 792 $this->assertTrue( $articles->addArticle( $article ), "Unable to add a new test article" ); 793 794 // make the method call 795 $c = new IXR_Client( $this->url ); 796 $res = $c->query( "metaWeblog.getPost", 797 $article->getId(), 798 $this->owner->getUsername(), 799 "password" ); 800 801 // see that the call was successful 802 $this->assertTrue( $res, "Unable to query ".$this->url." with method metaweblog.getPost" ); 803 804 // make sure that the call returned ok 805 $response = $c->getResponse(); 806 $this->assertTrue( $response, "metaWeblog.getPost did not return a valid response" ); 807 808 // and now compare that the returned values match with what we expected 809 $this->assertEquals( $this->owner->getId(), $response["userid"], "The user id of the article does not match" ); 810 $this->assertEquals( "topic", $response["title"], "The topic of the post does not match" ); 811 $this->assertEquals( "Intro text", $response["description"], "The text of the article does not match" ); 812 $this->assertEquals( "Extended text", $response["mt_text_more"], "The text of the extended text does not match" ); 813 $this->assertEquals( $article->getId(), $response["postid"] ); 814 $url = $this->blog->getBlogRequestGenerator(); 815 $this->assertEquals( $url->postLink( $article ), $response["link"], "The post permalink does not match" ); 816 $this->assertEquals( $url->postPermalink( $article ), $response["permaLink"], "The post permalink does not match" ); 817 818 $this->assertTrue( $articles->deleteArticle( $article->getId(), $this->owner->getId(), $this->blog->getId(), true ), 819 "Error deleting article" ); 820 821 // get the response and see that it has the right encoding 822 $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog ), 823 "The blog encoding and the response of the XMLRPC request did not match!" ); 824 825 // Restore the setting 826 $blogSettings = $this->blog->getSettings(); 827 $blogSettings->setValue( "xmlrpc_movabletype_enabled", false ); 828 $this->blog->setSettings( $blogSettings ); 829 $blogs->updateBlog( $this->blog ); 830 831 832 } 833 834 /** 835 * Test the metaWeblog.getCategories 836 */ 837 function testMetaWeblogGetCategories() 838 { 839 // make the method call 840 $c = new IXR_Client( $this->url ); 841 $res = $c->query( "metaWeblog.getCategories", 842 $this->blog->getId(), 843 $this->owner->getUsername(), 844 "password" ); 845 846 // see that the call was successful 847 $this->assertTrue( $res, "Unable to query ".$this->url." with method metaweblog.getCategories" ); 848 849 // make sure that the call returned ok 850 $response = $c->getResponse(); 851 $this->assertTrue( $response, "metaWeblog.getCategories did not return a valid response" ); 852 853 // there should only be one category 854 $this->assertTrue(( count( $response ) == 1 ), "There should only be one category returned by metaWeblog.getCategories" ); 855 856 // check that the category settings are correct 857 $this->assertEquals( $this->cat->getName(), key($response), "The category name did not match" ); 858 $this->assertEquals( $this->cat->getDescription(), $response["General"]["description"], "The category description did not match" ); 859 $url = $this->blog->getBlogRequestGenerator(); 860 $url->setXHTML( false ); 861 $this->assertEquals( $url->categoryLink( $this->cat ), $response["General"]["htmlUrl"], "The category link did not match" ); 862 863 // get the response and see that it has the right encoding 864 $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog ), 865 "The blog encoding and the response of the XMLRPC request did not match!" ); 866 } 867 868 function testMTGetCategoryList() 869 { 870 // make the method call 871 $c = new IXR_Client( $this->url ); 872 $res = $c->query( "mt.getCategoryList", 873 $this->blog->getId(), 874 $this->owner->getUsername(), 875 "password" ); 876 877 // see that the call was successful 878 $this->assertTrue( $res, "Unable to query ".$this->url." with method mt.getCategoryList" ); 879 880 // make sure that the call returned ok 881 $response = $c->getResponse(); 882 $this->assertTrue( $response, "mt.getCategoryList did not return a valid response" ); 883 884 // there should only be one category 885 $this->assertTrue(( count( $response ) == 1 ), "There should only be one category returned by mt.getCategoryList" ); 886 887 // check that the category settings are correct 888 $this->assertEquals( $this->cat->getName(), $response[0]["categoryName"], "The category name did not match" ); 889 $this->assertEquals( $this->cat->getId(), $response[0]["categoryId"], "The category description did not match" ); 890 891 // get the response and see that it has the right encoding 892 $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog ), 893 "The blog encoding and the response of the XMLRPC request did not match!" ); 894 } 895 896 function testMetaWeblogGetRecentPosts() 897 { 898 // create a new post first 899 $article = new Article( 900 "topic", 901 "text", 902 Array( $this->cat->getId()), 903 $this->owner->getId(), 904 $this->blog->getId(), 905 POST_STATUS_PUBLISHED, 906 0 907 ); 908 $articles = new Articles(); 909 $this->assertTrue( $articles->addArticle( $article ), "Unable to add the first tet article" ); 910 $article2 = new Article( 911 "topic 2", 912 "text 2", 913 Array( $this->cat->getId()), 914 $this->owner->getId(), 915 $this->blog->getId(), 916 POST_STATUS_PUBLISHED, 917 0 918 ); 919 $this->assertTrue( $articles->addArticle( $article ), "Unable to add the second test article" ); 920 921 // make the method call 922 $c = new IXR_Client( $this->url ); 923 $res = $c->query( "metaWeblog.getRecentPosts", 924 $this->blog->getId(), 925 $this->owner->getUsername(), 926 "password", 927 10 ); 928 929 // see that the call was successful 930 $this->assertTrue( $res, "Unable to query ".$this->url." with method metaWeblog.getRecentPosts" ); 931 932 // make sure that the call returned ok 933 $response = $c->getResponse(); 934 $this->assertTrue( $response, "metaWeblog.getRecentPosts did not return a valid response" ); 935 // and make sure that we got two articles 936 $this->assertEquals( 2, count($response), "The number of articles returned by metaWeblog.getRecentPosts is not correct" ); 937 938 // get the response and see that it has the right encoding 939 $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog ), 940 "The blog encoding and the response of the XMLRPC request did not match!" ); 941 942 // delete the articles 943 $articles->deleteArticle( $article->getId(), $this->owner->getId(), $this->blog->getId(), true ); 944 $articles->deleteArticle( $article2->getId(), $this->owner->getId(), $this->blog->getId(), true ); 945 946 } 947 948 949 function testMTSupportedTextFilters() 950 { 951 // make the method call 952 $c = new IXR_Client( $this->url ); 953 $res = $c->query( "mt.supportedTextFilters"); 954 955 // see that the call was successful 956 $this->assertTrue( $res, "Unable to query ".$this->url." with method mt.supportedTextFilters" ); 957 958 // make sure that the call returned ok 959 // there should be no filters 960 $response = $c->getResponse(); 961 $this->assertFalse( $response, "mt.supportedTextFilters return an unexpected response" ); 962 963 } 964 965 function testMTGetPostCategories() 966 { 967 // create a new post first 968 $article = new Article( 969 "topic", 970 "text", 971 Array( $this->cat->getId()), 972 $this->owner->getId(), 973 $this->blog->getId(), 974 POST_STATUS_PUBLISHED, 975 0 976 ); 977 $articles = new Articles(); 978 $this->assertTrue( $articles->addArticle( $article ), "Unable to add a new test article" ); 979 980 // make the method call 981 $c = new IXR_Client( $this->url ); 982 $res = $c->query( "mt.getPostCategories", 983 $article->getId(), 984 $this->owner->getUsername(), 985 "password" ); 986 987 // see that the call was successful 988 $this->assertTrue( $res, "Unable to query ".$this->url." with method mt.getPostCategories" ); 989 990 // make sure that the call returned ok 991 $response = $c->getResponse(); 992 $this->assertTrue( $response, "mt.getPostCategories did not return a valid response" ); 993 994 995 // There should only be one category 996 $this->assertEquals( 1, count($response), "The number of categories returned by mt.getPostCategories is not correct" ); 997 998 // and now compare that the returned values match with what we expected 999 $this->assertEquals( $this->cat->getName(), $response[0]["categoryName"], "The category name did not match" ); 1000 $this->assertEquals( $this->cat->getId(), $response[0]["categoryId"], "The category description did not match" ); 1001 1002 $this->assertTrue( $articles->deleteArticle( $article->getId(), $this->owner->getId(), $this->blog->getId(), true ), 1003 "Error deleting article" ); 1004 1005 // get the response and see that it has the right encoding 1006 $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog ), 1007 "The blog encoding and the response of the XMLRPC request did not match!" ); 1008 } 1009 1010 1011 function testMTSetPostCategories() 1012 { 1013 // create a new post first, with no category 1014 $article = new Article( 1015 "topic", 1016 "text", 1017 Array( $this->cat->getId()), 1018 $this->owner->getId(), 1019 $this->blog->getId(), 1020 POST_STATUS_PUBLISHED, 1021 0 1022 ); 1023 $articles = new Articles(); 1024 $this->assertTrue( $articles->addArticle( $article ), "Unable to add a new test article" ); 1025 1026 // another category 1027 $cat2 = new ArticleCategory( "General2", 1028 "Description for category General2", 1029 $this->blog->getId(), 1030 true ); 1031 $cats = new ArticleCategories(); 1032 if( !$cats->addArticleCategory( $cat2 )) { 1033 throw( new Exception( "Error adding test category!" )); 1034 die(); 1035 } 1036 1037 // Construct the Category Struct 1038 $categories = Array(); 1039 $theCategory = Array(); 1040 $theCategory["categoryName"] = $cat2->getName(); 1041 $theCategory["categoryId"] = $cat2->getId(); 1042 $categories[] = $theCategory; 1043 1044 // make the method call 1045 $c = new IXR_Client( $this->url ); 1046 $res = $c->query( "mt.setPostCategories", 1047 $article->getId(), 1048 $this->owner->getUsername(), 1049 "password", 1050 $categories 1051 ); 1052 1053 // see that the call was successful 1054 $this->assertTrue( $res, "Unable to query ".$this->url." with method mt.setPostCategories" ); 1055 1056 // make sure that the call returned ok 1057 $response = $c->getResponse(); 1058 $this->assertTrue( $response, "mt.setPostCategories did not return a valid response" ); 1059 1060 // check that the post was successfully updated 1061 $updatedArticle = $articles->getArticle( $article->getId()); 1062 $this->assertEquals( $cat2->getId(), $updatedArticle->_categoryIds[0]); 1063 1064 $cats->deleteCategory( $cat2->getId(), $this->blog->getId()); 1065 1066 // get the response and see that it has the right encoding 1067 $this->assertTrue( $this->checkResponseEncoding( $c->message->rawmessage, $this->blog ), 1068 "The blog encoding and the response of the XMLRPC request did not match!" ); 1069 } 1070 1071 1072 1073 /** 1074 * @private 1075 */ 1076 function checkResponseEncoding( $response, $blog ) 1077 { 1078 // check the character encoding in the response 1079 $numMatches = preg_match( "/<\\?xml.*version=\"1.0\".*encoding=\"(.*)\".*\?>.*/i", 1080 $response, 1081 $matches ); 1082 if( $numMatches != 1 ) 1083 return false; 1084 1085 $encoding = $matches[1]; 1086 1087 // check that the blog encoding and what we got in the response is the same 1088 $locale = $this->blog->getLocale(); 1089 $blogEncoding = $locale->getCharSet(); 1090 1091 return( $locale->getCharset() == $encoding ); 1092 } 1093 } 1094 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Mon Nov 26 21:04:15 2007 | par Balluche grâce à PHPXref 0.7 |
|