/tests/Zend/GData/WhereTest.php

https://github.com/Exercise/zf2 · PHP · 144 lines · 97 code · 15 blank · 32 comment · 6 complexity · 6796d61444c5067623b3c9fe966062cd MD5 · raw file

  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
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2010 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. * @namespace
  24. */
  25. namespace ZendTest\GData;
  26. use Zend\GData\Extension;
  27. /**
  28. * @category Zend
  29. * @package Zend_GData
  30. * @subpackage UnitTests
  31. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  32. * @license http://framework.zend.com/license/new-bsd New BSD License
  33. * @group Zend_GData
  34. */
  35. class WhereTest extends \PHPUnit_Framework_TestCase
  36. {
  37. public function setUp() {
  38. $this->whereText = file_get_contents(
  39. 'Zend/GData/_files/WhereElementSample1.xml',
  40. true);
  41. $this->where = new Extension\Where();
  42. }
  43. public function testEmptyWhereShouldHaveNoExtensionElements() {
  44. $this->assertTrue(is_array($this->where->extensionElements));
  45. $this->assertTrue(count($this->where->extensionElements) == 0);
  46. }
  47. public function testEmptyWhereShouldHaveNoExtensionAttributes() {
  48. $this->assertTrue(is_array($this->where->extensionAttributes));
  49. $this->assertTrue(count($this->where->extensionAttributes) == 0);
  50. }
  51. public function testSampleWhereShouldHaveNoExtensionElements() {
  52. $this->where->transferFromXML($this->whereText);
  53. $this->assertTrue(is_array($this->where->extensionElements));
  54. $this->assertTrue(count($this->where->extensionElements) == 0);
  55. }
  56. public function testSampleWhereShouldHaveNoExtensionAttributes() {
  57. $this->where->transferFromXML($this->whereText);
  58. $this->assertTrue(is_array($this->where->extensionAttributes));
  59. $this->assertTrue(count($this->where->extensionAttributes) == 0);
  60. }
  61. public function testNormalWhereShouldHaveNoExtensionElements() {
  62. $this->where->valueString = "Test Value String";
  63. $this->where->rel = "http://schemas.google.com/g/2005#event.alternate";
  64. $this->where->label = "Test Label";
  65. $this->assertEquals("Test Value String", $this->where->valueString);
  66. $this->assertEquals("http://schemas.google.com/g/2005#event.alternate", $this->where->rel);
  67. $this->assertEquals("Test Label", $this->where->label);
  68. $this->assertEquals(0, count($this->where->extensionElements));
  69. $newWhere = new Extension\Where();
  70. $newWhere->transferFromXML($this->where->saveXML());
  71. $this->assertEquals(0, count($newWhere->extensionElements));
  72. $newWhere->extensionElements = array(
  73. new \Zend\GData\App\Extension\Element('foo', 'atom', null, 'bar'));
  74. $this->assertEquals(1, count($newWhere->extensionElements));
  75. $this->assertEquals("Test Value String", $newWhere->valueString);
  76. $this->assertEquals("http://schemas.google.com/g/2005#event.alternate", $newWhere->rel);
  77. $this->assertEquals("Test Label", $newWhere->label);
  78. /* try constructing using magic factory */
  79. $gdata = new \Zend\GData\GData();
  80. $newWhere2 = $gdata->newWhere();
  81. $newWhere2->transferFromXML($newWhere->saveXML());
  82. $this->assertEquals(1, count($newWhere2->extensionElements));
  83. $this->assertEquals("Test Value String", $newWhere2->valueString);
  84. $this->assertEquals("http://schemas.google.com/g/2005#event.alternate", $newWhere2->rel);
  85. $this->assertEquals("Test Label", $newWhere2->label);
  86. }
  87. public function testEmptyWhereToAndFromStringShouldMatch() {
  88. $whereXml = $this->where->saveXML();
  89. $newWhere = new Extension\Where();
  90. $newWhere->transferFromXML($whereXml);
  91. $newWhereXml = $newWhere->saveXML();
  92. $this->assertTrue($whereXml == $newWhereXml);
  93. }
  94. public function testWhereWithValueToAndFromStringShouldMatch() {
  95. $this->where->valueString = "Test Value String";
  96. $this->where->rel = "http://schemas.google.com/g/2005#event.alternate";
  97. $this->where->label = "Test Label";
  98. $whereXml = $this->where->saveXML();
  99. $newWhere = new Extension\Where();
  100. $newWhere->transferFromXML($whereXml);
  101. $newWhereXml = $newWhere->saveXML();
  102. $this->assertTrue($whereXml == $newWhereXml);
  103. $this->assertEquals("Test Value String", $this->where->valueString);
  104. $this->assertEquals("http://schemas.google.com/g/2005#event.alternate", $this->where->rel);
  105. $this->assertEquals("Test Label", $this->where->label);
  106. }
  107. public function testExtensionAttributes() {
  108. $extensionAttributes = $this->where->extensionAttributes;
  109. $extensionAttributes['foo1'] = array('name'=>'foo1', 'value'=>'bar');
  110. $extensionAttributes['foo2'] = array('name'=>'foo2', 'value'=>'rab');
  111. $this->where->extensionAttributes = $extensionAttributes;
  112. $this->assertEquals('bar', $this->where->extensionAttributes['foo1']['value']);
  113. $this->assertEquals('rab', $this->where->extensionAttributes['foo2']['value']);
  114. $whereXml = $this->where->saveXML();
  115. $newWhere = new Extension\Where();
  116. $newWhere->transferFromXML($whereXml);
  117. $this->assertEquals('bar', $newWhere->extensionAttributes['foo1']['value']);
  118. $this->assertEquals('rab', $newWhere->extensionAttributes['foo2']['value']);
  119. }
  120. public function testConvertFullWhereToAndFromString() {
  121. $this->where->transferFromXML($this->whereText);
  122. $this->assertEquals("Joe's Pub", $this->where->valueString);
  123. $this->assertEquals("http://schemas.google.com/g/2005#event", $this->where->rel);
  124. $this->assertEquals("1234 Anywhere Ln., New York, NY", $this->where->label);
  125. $this->assertTrue($this->where->entryLink instanceof Extension\EntryLink);
  126. $this->assertEquals("http://local.example.com/10018/JoesPub", $this->where->entryLink->href);
  127. }
  128. }