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