2
0

QueryTest.php 5.6 KB

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