AuthorTest.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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-2015 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-2015 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. * @group Zend_Service
  37. * @group Zend_Service_Technorati
  38. */
  39. class Zend_Service_Technorati_AuthorTest extends Zend_Service_Technorati_TestCase
  40. {
  41. public function setUp()
  42. {
  43. $this->domElement = self::getTestFileElementAsDom('TestAuthor.xml', '//author');
  44. }
  45. public function testConstruct()
  46. {
  47. $this->_testConstruct('Zend_Service_Technorati_Author', array($this->domElement));
  48. }
  49. public function testConstructThrowsExceptionWithInvalidDom()
  50. {
  51. $this->_testConstructThrowsExceptionWithInvalidDom('Zend_Service_Technorati_Author', 'DOMElement');
  52. }
  53. public function testAuthor()
  54. {
  55. $author = new Zend_Service_Technorati_Author($this->domElement);
  56. $this->assertTrue(is_string($author->getFirstName()));
  57. $this->assertEquals('Cesare', $author->getFirstName());
  58. $this->assertTrue(is_string($author->getLastName()));
  59. $this->assertEquals('Lamanna', $author->getLastName());
  60. $this->assertTrue(is_string($author->getUsername()));
  61. $this->assertEquals('cesarehtml', $author->getUsername());
  62. $this->assertTrue(is_string($author->getDescription()));
  63. $this->assertEquals('This is a description.', $author->getDescription());
  64. $this->assertTrue(is_string($author->getFirstName()));
  65. $this->assertEquals('This is a bio.', $author->getBio());
  66. $this->assertTrue($author->getThumbnailPicture() instanceof Zend_Uri_Http);
  67. $this->assertEquals(Zend_Uri::factory('http://static.technorati.com/progimages/photo.jpg?uid=117217'), $author->getThumbnailPicture());
  68. }
  69. public function testSetGet()
  70. {
  71. $author = new Zend_Service_Technorati_Author($this->domElement);
  72. // check first name
  73. $set = 'first';
  74. $get = $author->setFirstName($set)->getFirstName();
  75. $this->assertTrue(is_string($get));
  76. $this->assertEquals($set, $get);
  77. // check last name
  78. $set = 'last';
  79. $get = $author->setLastName($set)->getLastName();
  80. $this->assertTrue(is_string($get));
  81. $this->assertEquals($set, $get);
  82. // check username
  83. $set = 'user';
  84. $get = $author->setUsername($set)->getUsername();
  85. $this->assertTrue(is_string($get));
  86. $this->assertEquals($set, $get);
  87. // check description
  88. $set = 'desc';
  89. $get = $author->setUsername($set)->getUsername();
  90. $this->assertTrue(is_string($get));
  91. $this->assertEquals($set, $get);
  92. // check bio
  93. $set = 'biography';
  94. $get = $author->setBio($set)->getBio();
  95. $this->assertTrue(is_string($get));
  96. $this->assertEquals($set, $get);
  97. // check thubmnail picture
  98. $set = Zend_Uri::factory('http://www.simonecarletti.com/');
  99. $get = $author->setThumbnailPicture($set)->getThumbnailPicture();
  100. $this->assertTrue($get instanceof Zend_Uri_Http);
  101. $this->assertEquals($set, $get);
  102. $set = 'http://www.simonecarletti.com/';
  103. $get = $author->setThumbnailPicture($set)->getThumbnailPicture();
  104. $this->assertTrue($get instanceof Zend_Uri_Http);
  105. $this->assertEquals(Zend_Uri::factory($set), $get);
  106. $set = 'http:::/foo';
  107. try {
  108. $author->setThumbnailPicture($set);
  109. $this->fail('Expected Zend_Service_Technorati_Exception not thrown');
  110. } catch(Zend_Service_Technorati_Exception $e) {
  111. $this->assertContains("Invalid URI", $e->getMessage());
  112. }
  113. }
  114. }