CategoryTest.php 5.2 KB

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