TableEntityQueryTest.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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: BlobStorageTest.php 14561 2009-05-07 08:05:12Z unknown $
  19. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  20. * @license http://framework.zend.com/license/new-bsd New BSD License
  21. */
  22. require_once dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . 'TestHelper.php';
  23. if (!defined('PHPUnit_MAIN_METHOD')) {
  24. define('PHPUnit_MAIN_METHOD', 'Zend_Service_WindowsAzure_TableEntityQueryTest::main');
  25. }
  26. require_once 'Zend/Service/WindowsAzure/Storage/TableEntityQuery.php';
  27. /**
  28. * @category Zend
  29. * @package Zend_Service_WindowsAzure
  30. * @subpackage UnitTests
  31. * @group Zend_Service
  32. * @group Zend_Service_WindowsAzure
  33. * @version $Id: BlobStorageTest.php 14561 2009-05-07 08:05:12Z unknown $
  34. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. */
  37. class Zend_Service_WindowsAzure_TableEntityQueryTest extends PHPUnit_Framework_TestCase
  38. {
  39. public static function main()
  40. {
  41. $suite = new PHPUnit_Framework_TestSuite("Zend_Service_WindowsAzure_TableEntityQueryTest");
  42. $result = PHPUnit_TextUI_TestRunner::run($suite);
  43. }
  44. /**
  45. * Test all records query
  46. */
  47. public function testAllRecordsQuery()
  48. {
  49. $target = new Zend_Service_WindowsAzure_Storage_TableEntityQuery();
  50. $target->select()
  51. ->from('MyTable');
  52. $this->assertEquals('MyTable()', $target->__toString());
  53. }
  54. /**
  55. * Test partition key query
  56. */
  57. public function testPartitionKeyQuery()
  58. {
  59. $target = new Zend_Service_WindowsAzure_Storage_TableEntityQuery();
  60. $target->select()
  61. ->from('MyTable')
  62. ->wherePartitionKey('test');
  63. $this->assertEquals('MyTable(PartitionKey=\'test\')', $target->__toString());
  64. }
  65. /**
  66. * Test row key query
  67. */
  68. public function testRowKeyQuery()
  69. {
  70. $target = new Zend_Service_WindowsAzure_Storage_TableEntityQuery();
  71. $target->select()
  72. ->from('MyTable')
  73. ->whereRowKey('test');
  74. $this->assertEquals('MyTable(RowKey=\'test\')', $target->__toString());
  75. }
  76. /**
  77. * Test identifier query
  78. */
  79. public function testIdentifierQuery()
  80. {
  81. $target = new Zend_Service_WindowsAzure_Storage_TableEntityQuery();
  82. $target->select()
  83. ->from('MyTable')
  84. ->wherePartitionKey('test')
  85. ->whereRowKey('123');
  86. $this->assertEquals('MyTable(PartitionKey=\'test\', RowKey=\'123\')', $target->__toString());
  87. }
  88. /**
  89. * Test top records query
  90. */
  91. public function testTopQuery()
  92. {
  93. $target = new Zend_Service_WindowsAzure_Storage_TableEntityQuery();
  94. $target->select()
  95. ->from('MyTable')
  96. ->top(10);
  97. $this->assertEquals('MyTable()?$top=10', $target->__toString());
  98. }
  99. /**
  100. * Test order by query
  101. */
  102. public function testOrderByQuery()
  103. {
  104. $target = new Zend_Service_WindowsAzure_Storage_TableEntityQuery();
  105. $target->select()
  106. ->from('MyTable')
  107. ->orderBy('Name', 'asc');
  108. $this->assertEquals('MyTable()?$orderby=Name asc', $target->__toString());
  109. }
  110. /**
  111. * Test order by multiple query
  112. */
  113. public function testOrderByMultipleQuery()
  114. {
  115. $target = new Zend_Service_WindowsAzure_Storage_TableEntityQuery();
  116. $target->select()
  117. ->from('MyTable')
  118. ->orderBy('Name', 'asc')
  119. ->orderBy('Visible', 'desc');
  120. $this->assertEquals('MyTable()?$orderby=Name asc,Visible desc', $target->__toString());
  121. }
  122. /**
  123. * Test where query
  124. */
  125. public function testWhereQuery()
  126. {
  127. $target = new Zend_Service_WindowsAzure_Storage_TableEntityQuery();
  128. $target->select()
  129. ->from('MyTable')
  130. ->where('Name eq ?', 'Maarten');
  131. $this->assertEquals('MyTable()?$filter=Name eq \'Maarten\'', $target->__toString());
  132. }
  133. /**
  134. * Test where array query
  135. */
  136. public function testWhereArrayQuery()
  137. {
  138. $target = new Zend_Service_WindowsAzure_Storage_TableEntityQuery();
  139. $target->select()
  140. ->from('MyTable')
  141. ->where('Name eq ? or Name eq ?', array('Maarten', 'Vijay'));
  142. $this->assertEquals('MyTable()?$filter=Name eq \'Maarten\' or Name eq \'Vijay\'', $target->__toString());
  143. }
  144. /**
  145. * Test where multiple query
  146. */
  147. public function testWhereMultipleQuery()
  148. {
  149. $target = new Zend_Service_WindowsAzure_Storage_TableEntityQuery();
  150. $target->select()
  151. ->from('MyTable')
  152. ->where('Name eq ?', 'Maarten')
  153. ->andWhere('Visible eq true');
  154. $this->assertEquals('MyTable()?$filter=Name eq \'Maarten\' and Visible eq true', $target->__toString());
  155. }
  156. }
  157. // Call Zend_Service_WindowsAzure_TableEntityQueryTest::main() if this source file is executed directly.
  158. if (PHPUnit_MAIN_METHOD == "Zend_Service_WindowsAzure_TableEntityQueryTest::main") {
  159. Zend_Service_WindowsAzure_TableEntityQueryTest::main();
  160. }