QueryTest.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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_Gdata_Health
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id $
  21. */
  22. require_once 'Zend/Gdata/Health.php';
  23. require_once 'Zend/Gdata/Health/Query.php';
  24. require_once 'Zend/Http/Client.php';
  25. /**
  26. * @category Zend
  27. * @package Zend_Gdata_Health
  28. * @subpackage UnitTests
  29. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. * @group Zend_Gdata
  32. * @group Zend_Gdata_Health
  33. */
  34. class Zend_Gdata_Health_QueryTest extends PHPUnit_Framework_TestCase
  35. {
  36. public function setUp()
  37. {
  38. $this->query = new Zend_Gdata_Health_Query();
  39. }
  40. public function testDigest()
  41. {
  42. $this->query->resetParameters();
  43. $this->assertEquals(null, $this->query->getDigest());
  44. $this->query->setDigest('true');
  45. $this->assertEquals('true', $this->query->getDigest());
  46. $this->assertContains('digest=true', $this->query->getQueryUrl());
  47. }
  48. public function testCategory()
  49. {
  50. $this->query->resetParameters();
  51. $this->query->setCategory('medication');
  52. $this->assertEquals($this->query->getCategory(), 'medication');
  53. $this->query->setCategory('medication', 'Lipitor');
  54. $this->assertEquals($this->query->getCategory(), 'medication/%7Bhttp%3A%2F%2Fschemas.google.com%2Fhealth%2Fitem%7DLipitor');
  55. $this->query->setCategory('condition', 'Malaria');
  56. $this->assertEquals($this->query->getCategory(), 'condition/%7Bhttp%3A%2F%2Fschemas.google.com%2Fhealth%2Fitem%7DMalaria');
  57. }
  58. public function testGrouped()
  59. {
  60. $this->query->resetParameters();
  61. $this->query->setGrouped('true');
  62. $this->assertEquals('true', $this->query->getGrouped());
  63. $this->assertContains('grouped=true', $this->query->getQueryUrl());
  64. }
  65. public function testMaxResultsGroup()
  66. {
  67. $this->query->resetParameters();
  68. try {
  69. $this->query->setMaxResultsGroup(1);
  70. $this->fail('Expecting to catch Zend_Gdata_App_InvalidArgumentException');
  71. } catch (Exception $e) {
  72. $this->assertThat($e, $this->isInstanceOf('Zend_Gdata_App_InvalidArgumentException'),
  73. 'Expecting Zend_Gdata_App_InvalidArgumentException, got '.get_class($e));
  74. }
  75. $this->assertEquals(null, $this->query->getMaxResultsGroup());
  76. $this->query->setGrouped('true');
  77. $this->query->setMaxResultsGroup(1);
  78. $this->assertEquals(1, $this->query->getMaxResultsGroup());
  79. $this->assertContains('max-results-group=1', $this->query->getQueryUrl());
  80. }
  81. public function testMaxResultsInGroup()
  82. {
  83. $this->query->resetParameters();
  84. try {
  85. $this->query->setMaxResultsInGroup(2);
  86. $this->fail('Expecting to catch Zend_Gdata_App_InvalidArgumentException');
  87. } catch (Exception $e) {
  88. $this->assertThat($e, $this->isInstanceOf('Zend_Gdata_App_InvalidArgumentException'),
  89. 'Expecting Zend_Gdata_App_InvalidArgumentException, got '.get_class($e));
  90. }
  91. $this->query->setGrouped('true');
  92. $this->assertEquals(null, $this->query->getMaxResultsInGroup());
  93. $this->query->setMaxResultsInGroup(2);
  94. $this->assertEquals(2, $this->query->getMaxResultsInGroup());
  95. $this->assertContains('max-results-in-group=2', $this->query->getQueryUrl());
  96. }
  97. public function testStartIndexGroup()
  98. {
  99. $this->query->resetParameters();
  100. $this->assertEquals(null, $this->query->getStartIndexGroup());
  101. try {
  102. $this->query->setStartIndexGroup(3);
  103. $this->fail('Expecting to catch Zend_Gdata_App_InvalidArgumentException');
  104. } catch (Exception $e) {
  105. $this->assertThat($e, $this->isInstanceOf('Zend_Gdata_App_InvalidArgumentException'),
  106. 'Expecting Zend_Gdata_App_InvalidArgumentException, got '.get_class($e));
  107. }
  108. $this->query->setGrouped('true');
  109. $this->query->setStartIndexGroup(3);
  110. $this->assertEquals(3, $this->query->getStartIndexGroup());
  111. $this->assertContains('start-index-group=3', $this->query->getQueryUrl());
  112. }
  113. public function testStartIndexInGroup()
  114. {
  115. $this->query->resetParameters();
  116. $this->assertEquals(null, $this->query->getStartIndexInGroup());
  117. try {
  118. $this->query->setStartIndexInGroup(4);
  119. $this->fail('Expecting to catch Zend_Gdata_App_InvalidArgumentException');
  120. } catch (Exception $e) {
  121. $this->assertThat($e, $this->isInstanceOf('Zend_Gdata_App_InvalidArgumentException'),
  122. 'Expecting Zend_Gdata_App_InvalidArgumentException, got '.get_class($e));
  123. }
  124. $this->query->setGrouped('true');
  125. $this->query->setStartIndexInGroup(4);
  126. $this->assertEquals(4, $this->query->getStartIndexInGroup());
  127. $this->assertContains('start-index-in-group=4', $this->query->getQueryUrl());
  128. }
  129. }