CategoryTest.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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_App
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2006 Zend Technologies USA Inc. (http://www.zend.com);
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. require_once 'Zend/Gdata/App/Extension/Category.php';
  22. require_once 'Zend/Gdata/App.php';
  23. /**
  24. * @package Zend_Gdata_App
  25. * @subpackage UnitTests
  26. */
  27. class Zend_Gdata_App_CategoryTest extends PHPUnit_Framework_TestCase
  28. {
  29. public function setUp() {
  30. $this->categoryText = file_get_contents(
  31. 'Zend/Gdata/App/_files/CategoryElementSample1.xml',
  32. true);
  33. $this->category = new Zend_Gdata_App_Extension_Category();
  34. }
  35. public function testEmptyCategoryShouldHaveEmptyExtensionsList() {
  36. $this->assertTrue(is_array($this->category->extensionElements));
  37. $this->assertTrue(count($this->category->extensionElements) == 0);
  38. }
  39. public function testNormalCategoryShouldHaveNoExtensionElements() {
  40. $this->category->scheme = 'http://schemas.google.com/g/2005#kind';
  41. $this->assertEquals($this->category->scheme, 'http://schemas.google.com/g/2005#kind');
  42. $this->assertEquals(count($this->category->extensionElements), 0);
  43. $newCategory = new Zend_Gdata_App_Extension_Category();
  44. $newCategory->transferFromXML($this->category->saveXML());
  45. $this->assertEquals(0, count($newCategory->extensionElements));
  46. $newCategory->extensionElements = array(
  47. new Zend_Gdata_App_Extension_Element('foo', 'atom', null, 'bar'));
  48. $this->assertEquals(count($newCategory->extensionElements), 1);
  49. $this->assertEquals($newCategory->scheme, 'http://schemas.google.com/g/2005#kind');
  50. /* try constructing using magic factory */
  51. $app = new Zend_Gdata_App();
  52. $newCategory2 = $app->newCategory();
  53. $newCategory2->transferFromXML($newCategory->saveXML());
  54. $this->assertEquals(count($newCategory2->extensionElements), 1);
  55. $this->assertEquals($newCategory2->scheme, 'http://schemas.google.com/g/2005#kind');
  56. }
  57. public function testEmptyCategoryToAndFromStringShouldMatch() {
  58. $categoryXml = $this->category->saveXML();
  59. $newCategory = new Zend_Gdata_App_Extension_Category();
  60. $newCategory->transferFromXML($categoryXml);
  61. $newCategoryXml = $newCategory->saveXML();
  62. $this->assertTrue($categoryXml == $newCategoryXml);
  63. }
  64. public function testCategoryWithSchemeAndTermToAndFromStringShouldMatch() {
  65. $this->category->scheme = 'http://schemas.google.com/g/2005#kind';
  66. $this->category->term = 'http://schemas.google.com/g/2005#event';
  67. $this->category->label = 'event kind';
  68. $categoryXml = $this->category->saveXML();
  69. $newCategory = new Zend_Gdata_App_Extension_Category();
  70. $newCategory->transferFromXML($categoryXml);
  71. $newCategoryXml = $newCategory->saveXML();
  72. $this->assertTrue($categoryXml == $newCategoryXml);
  73. $this->assertEquals('http://schemas.google.com/g/2005#kind', $newCategory->scheme);
  74. $this->assertEquals('http://schemas.google.com/g/2005#event', $newCategory->term);
  75. $this->assertEquals('event kind', $newCategory->label);
  76. }
  77. public function testExtensionAttributes() {
  78. $extensionAttributes = $this->category->extensionAttributes;
  79. $extensionAttributes['foo1'] = array('name'=>'foo1', 'value'=>'bar');
  80. $extensionAttributes['foo2'] = array('name'=>'foo2', 'value'=>'rab');
  81. $this->category->extensionAttributes = $extensionAttributes;
  82. $this->assertEquals('bar', $this->category->extensionAttributes['foo1']['value']);
  83. $this->assertEquals('rab', $this->category->extensionAttributes['foo2']['value']);
  84. $categoryXml = $this->category->saveXML();
  85. $newCategory = new Zend_Gdata_App_Extension_Category();
  86. $newCategory->transferFromXML($categoryXml);
  87. $this->assertEquals('bar', $newCategory->extensionAttributes['foo1']['value']);
  88. $this->assertEquals('rab', $newCategory->extensionAttributes['foo2']['value']);
  89. }
  90. public function testConvertFullCategoryToAndFromString() {
  91. $this->category->transferFromXML($this->categoryText);
  92. $this->assertEquals('http://schemas.google.com/g/2005#kind', $this->category->scheme);
  93. $this->assertEquals('http://schemas.google.com/g/2005#event', $this->category->term);
  94. $this->assertEquals('event kind', $this->category->label);
  95. }
  96. }