TableEntityQueryTest.php 4.9 KB

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