QueryTest.php 5.4 KB

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