OpenSearchStartIndexTest.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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_Gdata_OpenSearch
  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. require_once 'Zend/Gdata/Extension/OpenSearchStartIndex.php';
  23. require_once 'Zend/Gdata.php';
  24. /**
  25. * @category Zend
  26. * @package Zend_Gdata_OpenSearch
  27. * @subpackage UnitTests
  28. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. * @group Zend_Gdata
  31. * @group Zend_Gdata_OpenSearch
  32. */
  33. class Zend_Gdata_OpenSearchStartIndexTest extends PHPUnit_Framework_TestCase
  34. {
  35. public function setUp() {
  36. $this->openSearchStartIndexText = file_get_contents(
  37. 'Zend/Gdata/_files/OpenSearchStartIndexElementSample1.xml',
  38. true);
  39. $this->openSearchStartIndex = new Zend_Gdata_Extension_OpenSearchStartIndex();
  40. }
  41. public function testEmptyOpenSearchStartIndexShouldHaveNoExtensionElements() {
  42. $this->assertTrue(is_array($this->openSearchStartIndex->extensionElements));
  43. $this->assertTrue(count($this->openSearchStartIndex->extensionElements) == 0);
  44. }
  45. public function testEmptyOpenSearchStartIndexShouldHaveNoExtensionAttributes() {
  46. $this->assertTrue(is_array($this->openSearchStartIndex->extensionAttributes));
  47. $this->assertTrue(count($this->openSearchStartIndex->extensionAttributes) == 0);
  48. }
  49. public function testSampleOpenSearchStartIndexShouldHaveNoExtensionElements() {
  50. $this->openSearchStartIndex->transferFromXML($this->openSearchStartIndexText);
  51. $this->assertTrue(is_array($this->openSearchStartIndex->extensionElements));
  52. $this->assertTrue(count($this->openSearchStartIndex->extensionElements) == 0);
  53. }
  54. public function testSampleOpenSearchStartIndexShouldHaveNoExtensionAttributes() {
  55. $this->openSearchStartIndex->transferFromXML($this->openSearchStartIndexText);
  56. $this->assertTrue(is_array($this->openSearchStartIndex->extensionAttributes));
  57. $this->assertTrue(count($this->openSearchStartIndex->extensionAttributes) == 0);
  58. }
  59. public function testNormalOpenSearchStartIndexShouldHaveNoExtensionElements() {
  60. $this->openSearchStartIndex->text = "20";
  61. $this->assertEquals("20", $this->openSearchStartIndex->text);
  62. $this->assertEquals(0, count($this->openSearchStartIndex->extensionElements));
  63. $newOpenSearchStartIndex = new Zend_Gdata_Extension_OpenSearchStartIndex();
  64. $newOpenSearchStartIndex->transferFromXML($this->openSearchStartIndex->saveXML());
  65. $this->assertEquals(0, count($newOpenSearchStartIndex->extensionElements));
  66. $newOpenSearchStartIndex->extensionElements = array(
  67. new Zend_Gdata_App_Extension_Element('foo', 'atom', null, 'bar'));
  68. $this->assertEquals(1, count($newOpenSearchStartIndex->extensionElements));
  69. $this->assertEquals("20", $newOpenSearchStartIndex->text);
  70. /* try constructing using magic factory */
  71. $gdata = new Zend_Gdata();
  72. $newOpenSearchStartIndex2 = $gdata->newOpenSearchStartIndex();
  73. $newOpenSearchStartIndex2->transferFromXML($newOpenSearchStartIndex->saveXML());
  74. $this->assertEquals(1, count($newOpenSearchStartIndex2->extensionElements));
  75. $this->assertEquals("20", $newOpenSearchStartIndex2->text);
  76. }
  77. public function testEmptyOpenSearchStartIndexToAndFromStringShouldMatch() {
  78. $openSearchStartIndexXml = $this->openSearchStartIndex->saveXML();
  79. $newOpenSearchStartIndex = new Zend_Gdata_Extension_OpenSearchStartIndex();
  80. $newOpenSearchStartIndex->transferFromXML($openSearchStartIndexXml);
  81. $newOpenSearchStartIndexXml = $newOpenSearchStartIndex->saveXML();
  82. $this->assertTrue($openSearchStartIndexXml == $newOpenSearchStartIndexXml);
  83. }
  84. public function testOpenSearchStartIndexWithValueToAndFromStringShouldMatch() {
  85. $this->openSearchStartIndex->text = "20";
  86. $openSearchStartIndexXml = $this->openSearchStartIndex->saveXML();
  87. $newOpenSearchStartIndex = new Zend_Gdata_Extension_OpenSearchStartIndex();
  88. $newOpenSearchStartIndex->transferFromXML($openSearchStartIndexXml);
  89. $newOpenSearchStartIndexXml = $newOpenSearchStartIndex->saveXML();
  90. $this->assertTrue($openSearchStartIndexXml == $newOpenSearchStartIndexXml);
  91. $this->assertEquals("20", $this->openSearchStartIndex->text);
  92. }
  93. public function testExtensionAttributes() {
  94. $extensionAttributes = $this->openSearchStartIndex->extensionAttributes;
  95. $extensionAttributes['foo1'] = array('name'=>'foo1', 'value'=>'bar');
  96. $extensionAttributes['foo2'] = array('name'=>'foo2', 'value'=>'rab');
  97. $this->openSearchStartIndex->extensionAttributes = $extensionAttributes;
  98. $this->assertEquals('bar', $this->openSearchStartIndex->extensionAttributes['foo1']['value']);
  99. $this->assertEquals('rab', $this->openSearchStartIndex->extensionAttributes['foo2']['value']);
  100. $openSearchStartIndexXml = $this->openSearchStartIndex->saveXML();
  101. $newOpenSearchStartIndex = new Zend_Gdata_Extension_OpenSearchStartIndex();
  102. $newOpenSearchStartIndex->transferFromXML($openSearchStartIndexXml);
  103. $this->assertEquals('bar', $newOpenSearchStartIndex->extensionAttributes['foo1']['value']);
  104. $this->assertEquals('rab', $newOpenSearchStartIndex->extensionAttributes['foo2']['value']);
  105. }
  106. public function testConvertFullOpenSearchStartIndexToAndFromString() {
  107. $this->openSearchStartIndex->transferFromXML($this->openSearchStartIndexText);
  108. $this->assertEquals("5", $this->openSearchStartIndex->text);
  109. }
  110. }