TableEntityQueryTest.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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_TableEntityQuery */
  27. require_once 'Zend/Service/WindowsAzure/Storage/TableEntityQuery.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_TableEntityQueryTest extends PHPUnit_Framework_TestCase
  37. {
  38. /**
  39. * Test all records query
  40. */
  41. public function testAllRecordsQuery()
  42. {
  43. $target = new Zend_Service_WindowsAzure_Storage_TableEntityQuery();
  44. $target->select()
  45. ->from('MyTable');
  46. $this->assertEquals('MyTable()', $target->__toString());
  47. }
  48. /**
  49. * Test partition key query
  50. */
  51. public function testPartitionKeyQuery()
  52. {
  53. $target = new Zend_Service_WindowsAzure_Storage_TableEntityQuery();
  54. $target->select()
  55. ->from('MyTable')
  56. ->wherePartitionKey('test');
  57. $this->assertEquals('MyTable(PartitionKey=\'test\')', $target->__toString());
  58. }
  59. /**
  60. * Test row key query
  61. */
  62. public function testRowKeyQuery()
  63. {
  64. $target = new Zend_Service_WindowsAzure_Storage_TableEntityQuery();
  65. $target->select()
  66. ->from('MyTable')
  67. ->whereRowKey('test');
  68. $this->assertEquals('MyTable(RowKey=\'test\')', $target->__toString());
  69. }
  70. /**
  71. * Test identifier query
  72. */
  73. public function testIdentifierQuery()
  74. {
  75. $target = new Zend_Service_WindowsAzure_Storage_TableEntityQuery();
  76. $target->select()
  77. ->from('MyTable')
  78. ->wherePartitionKey('test')
  79. ->whereRowKey('123');
  80. $this->assertEquals('MyTable(PartitionKey=\'test\', RowKey=\'123\')', $target->__toString());
  81. }
  82. /**
  83. * Test top records query
  84. */
  85. public function testTopQuery()
  86. {
  87. $target = new Zend_Service_WindowsAzure_Storage_TableEntityQuery();
  88. $target->select()
  89. ->from('MyTable')
  90. ->top(10);
  91. $this->assertEquals('MyTable()?$top=10', $target->__toString());
  92. }
  93. /**
  94. * Test order by query
  95. */
  96. public function testOrderByQuery()
  97. {
  98. $target = new Zend_Service_WindowsAzure_Storage_TableEntityQuery();
  99. $target->select()
  100. ->from('MyTable')
  101. ->orderBy('Name', 'asc');
  102. $this->assertEquals('MyTable()?$orderby=Name asc', $target->__toString());
  103. }
  104. /**
  105. * Test order by multiple query
  106. */
  107. public function testOrderByMultipleQuery()
  108. {
  109. $target = new Zend_Service_WindowsAzure_Storage_TableEntityQuery();
  110. $target->select()
  111. ->from('MyTable')
  112. ->orderBy('Name', 'asc')
  113. ->orderBy('Visible', 'desc');
  114. $this->assertEquals('MyTable()?$orderby=Name asc,Visible desc', $target->__toString());
  115. }
  116. /**
  117. * Test where query
  118. */
  119. public function testWhereQuery()
  120. {
  121. $target = new Zend_Service_WindowsAzure_Storage_TableEntityQuery();
  122. $target->select()
  123. ->from('MyTable')
  124. ->where('Name eq ?', 'Maarten');
  125. $this->assertEquals('MyTable()?$filter=Name eq \'Maarten\'', $target->__toString());
  126. }
  127. /**
  128. * Test where array query
  129. */
  130. public function testWhereArrayQuery()
  131. {
  132. $target = new Zend_Service_WindowsAzure_Storage_TableEntityQuery();
  133. $target->select()
  134. ->from('MyTable')
  135. ->where('Name eq ? or Name eq ?', array('Maarten', 'Vijay'));
  136. $this->assertEquals('MyTable()?$filter=Name eq \'Maarten\' or Name eq \'Vijay\'', $target->__toString());
  137. }
  138. /**
  139. * Test where multiple query
  140. */
  141. public function testWhereMultipleQuery()
  142. {
  143. $target = new Zend_Service_WindowsAzure_Storage_TableEntityQuery();
  144. $target->select()
  145. ->from('MyTable')
  146. ->where('Name eq ?', 'Maarten')
  147. ->andWhere('Visible eq true');
  148. $this->assertEquals('MyTable()?$filter=Name eq \'Maarten\' and Visible eq true', $target->__toString());
  149. }
  150. }