AuthorTest.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Service_Technorati
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * Test helper
  24. */
  25. require_once dirname(__FILE__) . DIRECTORY_SEPARATOR .'TestCase.php';
  26. /**
  27. * @see Zend_Service_Technorati_Author
  28. */
  29. require_once 'Zend/Service/Technorati/Author.php';
  30. /**
  31. * @category Zend
  32. * @package Zend_Service_Technorati
  33. * @subpackage UnitTests
  34. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. */
  37. class Zend_Service_Technorati_AuthorTest extends Zend_Service_Technorati_TestCase
  38. {
  39. public function setUp()
  40. {
  41. $this->domElement = self::getTestFileElementAsDom('TestAuthor.xml', '//author');
  42. }
  43. public function testConstruct()
  44. {
  45. $this->_testConstruct('Zend_Service_Technorati_Author', array($this->domElement));
  46. }
  47. public function testConstructThrowsExceptionWithInvalidDom()
  48. {
  49. $this->_testConstructThrowsExceptionWithInvalidDom('Zend_Service_Technorati_Author', 'DOMElement');
  50. }
  51. public function testAuthor()
  52. {
  53. $author = new Zend_Service_Technorati_Author($this->domElement);
  54. $this->assertType('string', $author->getFirstName());
  55. $this->assertEquals('Cesare', $author->getFirstName());
  56. $this->assertType('string', $author->getLastName());
  57. $this->assertEquals('Lamanna', $author->getLastName());
  58. $this->assertType('string', $author->getUsername());
  59. $this->assertEquals('cesarehtml', $author->getUsername());
  60. $this->assertType('string', $author->getDescription());
  61. $this->assertEquals('This is a description.', $author->getDescription());
  62. $this->assertType('string', $author->getFirstName());
  63. $this->assertEquals('This is a bio.', $author->getBio());
  64. $this->assertType('Zend_Uri_Http', $author->getThumbnailPicture());
  65. $this->assertEquals(Zend_Uri::factory('http://static.technorati.com/progimages/photo.jpg?uid=117217'), $author->getThumbnailPicture());
  66. }
  67. public function testSetGet()
  68. {
  69. $author = new Zend_Service_Technorati_Author($this->domElement);
  70. // check first name
  71. $set = 'first';
  72. $get = $author->setFirstName($set)->getFirstName();
  73. $this->assertType('string', $get);
  74. $this->assertEquals($set, $get);
  75. // check last name
  76. $set = 'last';
  77. $get = $author->setLastName($set)->getLastName();
  78. $this->assertType('string', $get);
  79. $this->assertEquals($set, $get);
  80. // check username
  81. $set = 'user';
  82. $get = $author->setUsername($set)->getUsername();
  83. $this->assertType('string', $get);
  84. $this->assertEquals($set, $get);
  85. // check description
  86. $set = 'desc';
  87. $get = $author->setUsername($set)->getUsername();
  88. $this->assertType('string', $get);
  89. $this->assertEquals($set, $get);
  90. // check bio
  91. $set = 'biography';
  92. $get = $author->setBio($set)->getBio();
  93. $this->assertType('string', $get);
  94. $this->assertEquals($set, $get);
  95. // check thubmnail picture
  96. $set = Zend_Uri::factory('http://www.simonecarletti.com/');
  97. $get = $author->setThumbnailPicture($set)->getThumbnailPicture();
  98. $this->assertType('Zend_Uri_Http', $get);
  99. $this->assertEquals($set, $get);
  100. $set = 'http://www.simonecarletti.com/';
  101. $get = $author->setThumbnailPicture($set)->getThumbnailPicture();
  102. $this->assertType('Zend_Uri_Http', $get);
  103. $this->assertEquals(Zend_Uri::factory($set), $get);
  104. $set = 'http:::/foo';
  105. try {
  106. $author->setThumbnailPicture($set);
  107. $this->fail('Expected Zend_Service_Technorati_Exception not thrown');
  108. } catch(Zend_Service_Technorati_Exception $e) {
  109. $this->assertContains("Invalid URI", $e->getMessage());
  110. }
  111. }
  112. }