2
0

ResultSetTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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_ResultSet
  28. */
  29. require_once 'Zend/Service/Technorati/ResultSet.php';
  30. /**
  31. * @see Zend_Service_Technorati_SearchResultSet
  32. */
  33. require_once 'Zend/Service/Technorati/SearchResultSet.php';
  34. /**
  35. * @category Zend
  36. * @package Zend_Service_Technorati
  37. * @subpackage UnitTests
  38. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  39. * @license http://framework.zend.com/license/new-bsd New BSD License
  40. */
  41. class Zend_Service_Technorati_ResultSetTest extends Zend_Service_Technorati_TestCase
  42. {
  43. /**
  44. * Even if Zend_Service_Technorati_ResultSet is an abstract class
  45. * it's useful to check whether it correctly implements
  46. * SeekableIterator interface as requested.
  47. *
  48. * Any *ResultSet class should be a child of ResultSet
  49. * thus it's safe to test basic methods on such child class.
  50. */
  51. public function setUp()
  52. {
  53. $this->ref = new ReflectionClass('Zend_Service_Technorati_ResultSet');
  54. $this->dom = self::getTestFileContentAsDom('TestSearchResultSet.xml');
  55. $this->object = new Zend_Service_Technorati_SearchResultSet($this->dom);
  56. $this->objectRef = new ReflectionObject($this->object);
  57. }
  58. public function testResultSetIsAbstract()
  59. {
  60. $this->assertTrue($this->ref->isAbstract());
  61. }
  62. public function testResultSetImplementsSeekableIteratorInterface()
  63. {
  64. $this->assertTrue($this->ref->isIterateable());
  65. }
  66. /**
  67. * Security check
  68. */
  69. public function testResultSetIsParentOfThisObjectClass()
  70. {
  71. $this->assertTrue($this->objectRef->isSubclassOf($this->ref));
  72. }
  73. public function testResultSetSeek()
  74. {
  75. $this->assertEquals(0, $this->object->key());
  76. $this->object->seek(2);
  77. $this->assertEquals(2, $this->object->key());
  78. }
  79. public function testResultSetSeekThrowsOutOfBoundsExceptionWithInvalidIndex()
  80. {
  81. try {
  82. $this->object->seek(1000);
  83. $this->fail('Expected OutOfBoundsException not thrown');
  84. } catch (OutOfBoundsException $e) {
  85. $this->assertContains('Illegal index', $e->getMessage());
  86. }
  87. }
  88. public function testResultSetKey()
  89. {
  90. $this->assertEquals(0, $this->object->key());
  91. $this->object->seek(2);
  92. $this->assertEquals(2, $this->object->key());
  93. // don't move forward
  94. $this->assertEquals(2, $this->object->key());
  95. }
  96. public function testResultSetNext()
  97. {
  98. $this->assertEquals(0, $this->object->key());
  99. $this->object->next();
  100. $this->assertEquals(1, $this->object->key());
  101. }
  102. public function testResultSetRewind()
  103. {
  104. $this->assertEquals(0, $this->object->key());
  105. $this->object->seek(2);
  106. $this->assertTrue($this->object->rewind());
  107. $this->assertEquals(0, $this->object->key());
  108. }
  109. public function testResultSetSerialization()
  110. {
  111. $this->_testResultSetSerialization($this->object);
  112. }
  113. }