TableEntityQueryTest.php 5.9 KB

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