TableEntityTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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_Service_WindowsAzure
  17. * @subpackage UnitTests
  18. * @version $Id$
  19. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  20. * @license http://framework.zend.com/license/new-bsd New BSD License
  21. */
  22. /**
  23. * Test helpers
  24. */
  25. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  26. /** Zend_Service_WindowsAzure_Storage_TableEntity */
  27. require_once 'Zend/Service/WindowsAzure/Storage/TableEntity.php';
  28. /**
  29. * @category Zend
  30. * @package Zend_Service_WindowsAzure
  31. * @subpackage UnitTests
  32. * @version $Id$
  33. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. */
  36. class Zend_Service_WindowsAzure_TableEntityTest extends PHPUnit_Framework_TestCase
  37. {
  38. /**
  39. * Test constructor
  40. */
  41. public function testConstructor()
  42. {
  43. $target = new TSETTest_TestEntity('partition1', '000001');
  44. $this->assertEquals('partition1', $target->getPartitionKey());
  45. $this->assertEquals('000001', $target->getRowKey());
  46. }
  47. /**
  48. * Test get Azure values
  49. */
  50. public function testGetAzureValues()
  51. {
  52. $target = new TSETTest_TestEntity('partition1', '000001');
  53. $result = $target->getAzureValues();
  54. $this->assertEquals('Name', $result[0]->Name);
  55. $this->assertEquals(null, $result[0]->Value);
  56. $this->assertEquals('Age', $result[1]->Name);
  57. $this->assertEquals('Edm.Int64', $result[1]->Type);
  58. $this->assertEquals('Visible', $result[2]->Name);
  59. $this->assertEquals(false, $result[2]->Value);
  60. $this->assertEquals('partition1', $result[3]->Value);
  61. $this->assertEquals('000001', $result[4]->Value);
  62. }
  63. /**
  64. * Test set Azure values
  65. */
  66. public function testSetAzureValuesSuccess()
  67. {
  68. $values = array(
  69. 'PartitionKey' => 'partition1',
  70. 'RowKey' => '000001',
  71. 'Name' => 'Maarten',
  72. 'Age' => 25,
  73. 'Visible' => true
  74. );
  75. $target = new TSETTest_TestEntity();
  76. $target->setAzureValues($values);
  77. $this->assertEquals('partition1', $target->getPartitionKey());
  78. $this->assertEquals('000001', $target->getRowKey());
  79. $this->assertEquals('Maarten', $target->FullName);
  80. $this->assertEquals(25, $target->Age);
  81. $this->assertEquals(true, $target->Visible);
  82. }
  83. /**
  84. * Test set Azure values
  85. */
  86. public function testSetAzureValuesFailure()
  87. {
  88. $values = array(
  89. 'PartitionKey' => 'partition1',
  90. 'RowKey' => '000001'
  91. );
  92. $exceptionRaised = false;
  93. $target = new TSETTest_TestEntity();
  94. try
  95. {
  96. $target->setAzureValues($values, true);
  97. }
  98. catch (Exception $ex) {
  99. $exceptionRaised = true;
  100. }
  101. $this->assertTrue($exceptionRaised);
  102. }
  103. }
  104. /**
  105. * Test entity
  106. */
  107. class TSETTest_TestEntity extends Zend_Service_WindowsAzure_Storage_TableEntity
  108. {
  109. /**
  110. * @azure Name
  111. */
  112. public $FullName;
  113. /**
  114. * @azure Age Edm.Int64
  115. */
  116. public $Age;
  117. /**
  118. * @azure Visible Edm.Boolean
  119. */
  120. public $Visible = false;
  121. }