QuotaTest.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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) 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/Gapps/Extension/Quota.php';
  22. require_once 'Zend/Gdata.php';
  23. /**
  24. * @package Zend_Gdata
  25. * @subpackage UnitTests
  26. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  27. * @license http://framework.zend.com/license/new-bsd New BSD License
  28. */
  29. class Zend_Gdata_Gapps_QuotaTest extends PHPUnit_Framework_TestCase
  30. {
  31. public function setUp() {
  32. $this->quotaText = file_get_contents(
  33. 'Zend/Gdata/Gapps/_files/QuotaElementSample1.xml',
  34. true);
  35. $this->quota = new Zend_Gdata_Gapps_Extension_Quota();
  36. }
  37. public function testEmptyQuotaShouldHaveNoExtensionElements() {
  38. $this->assertTrue(is_array($this->quota->extensionElements));
  39. $this->assertTrue(count($this->quota->extensionElements) == 0);
  40. }
  41. public function testEmptyQuotaShouldHaveNoExtensionAttributes() {
  42. $this->assertTrue(is_array($this->quota->extensionAttributes));
  43. $this->assertTrue(count($this->quota->extensionAttributes) == 0);
  44. }
  45. public function testSampleQuotaShouldHaveNoExtensionElements() {
  46. $this->quota->transferFromXML($this->quotaText);
  47. $this->assertTrue(is_array($this->quota->extensionElements));
  48. $this->assertTrue(count($this->quota->extensionElements) == 0);
  49. }
  50. public function testSampleQuotaShouldHaveNoExtensionAttributes() {
  51. $this->quota->transferFromXML($this->quotaText);
  52. $this->assertTrue(is_array($this->quota->extensionAttributes));
  53. $this->assertTrue(count($this->quota->extensionAttributes) == 0);
  54. }
  55. public function testNormalQuotaShouldHaveNoExtensionElements() {
  56. $this->quota->limit = "123456789";
  57. $this->assertEquals("123456789", $this->quota->limit);
  58. $this->assertEquals(0, count($this->quota->extensionElements));
  59. $newQuota = new Zend_Gdata_Gapps_Extension_Quota();
  60. $newQuota->transferFromXML($this->quota->saveXML());
  61. $this->assertEquals(0, count($newQuota->extensionElements));
  62. $newQuota->extensionElements = array(
  63. new Zend_Gdata_App_Extension_Element('foo', 'atom', null, 'bar'));
  64. $this->assertEquals(1, count($newQuota->extensionElements));
  65. $this->assertEquals("123456789", $newQuota->limit);
  66. /* try constructing using magic factory */
  67. $gdata = new Zend_Gdata_Gapps();
  68. $newQuota2 = $gdata->newQuota();
  69. $newQuota2->transferFromXML($newQuota->saveXML());
  70. $this->assertEquals(1, count($newQuota2->extensionElements));
  71. $this->assertEquals("123456789", $newQuota2->limit);
  72. }
  73. public function testEmptyQuotaToAndFromStringShouldMatch() {
  74. $quotaXml = $this->quota->saveXML();
  75. $newQuota = new Zend_Gdata_Gapps_Extension_Quota();
  76. $newQuota->transferFromXML($quotaXml);
  77. $newQuotaXml = $newQuota->saveXML();
  78. $this->assertTrue($quotaXml == $newQuotaXml);
  79. }
  80. public function testQuotaWithValueToAndFromStringShouldMatch() {
  81. $this->quota->limit = "123456789";
  82. $quotaXml = $this->quota->saveXML();
  83. $newQuota = new Zend_Gdata_Gapps_Extension_Quota();
  84. $newQuota->transferFromXML($quotaXml);
  85. $newQuotaXml = $newQuota->saveXML();
  86. $this->assertTrue($quotaXml == $newQuotaXml);
  87. $this->assertEquals("123456789", $this->quota->limit);
  88. }
  89. public function testExtensionAttributes() {
  90. $extensionAttributes = $this->quota->extensionAttributes;
  91. $extensionAttributes['foo1'] = array('name'=>'foo1', 'value'=>'bar');
  92. $extensionAttributes['foo2'] = array('name'=>'foo2', 'value'=>'rab');
  93. $this->quota->extensionAttributes = $extensionAttributes;
  94. $this->assertEquals('bar', $this->quota->extensionAttributes['foo1']['value']);
  95. $this->assertEquals('rab', $this->quota->extensionAttributes['foo2']['value']);
  96. $quotaXml = $this->quota->saveXML();
  97. $newQuota = new Zend_Gdata_Gapps_Extension_Quota();
  98. $newQuota->transferFromXML($quotaXml);
  99. $this->assertEquals('bar', $newQuota->extensionAttributes['foo1']['value']);
  100. $this->assertEquals('rab', $newQuota->extensionAttributes['foo2']['value']);
  101. }
  102. public function testConvertFullQuotaToAndFromString() {
  103. $this->quota->transferFromXML($this->quotaText);
  104. $this->assertEquals("2048", $this->quota->limit);
  105. }
  106. }