TableEntityQueryTest.php 5.8 KB

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