ProfileFeedTest.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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/ProfileFeed.php';
  24. require_once 'Zend/Gdata/Health/ProfileEntry.php';
  25. /**
  26. * @package Zend_Gdata
  27. * @subpackage UnitTests
  28. */
  29. class Zend_Gdata_Health_ProfileFeedTest extends PHPUnit_Framework_TestCase
  30. {
  31. public function setUp()
  32. {
  33. $this->profileFeed = new Zend_Gdata_Health_ProfileFeed();
  34. $this->feedText = file_get_contents(
  35. 'Zend/Gdata/Health/_files/TestDataHealthProfileFeedSample.xml', true);
  36. }
  37. private function verifyAllSamplePropertiesAreCorrect($profileFeed) {
  38. $this->assertEquals('https://www.google.com/health/feeds/profile/default', $profileFeed->id->text);
  39. $this->assertEquals('2008-09-30T01:07:17.888Z', $profileFeed->updated->text);
  40. $this->assertEquals('http://schemas.google.com/g/2005#kind', $profileFeed->category[0]->scheme);
  41. $this->assertEquals('http://schemas.google.com/health/kinds#profile', $profileFeed->category[0]->term);
  42. $this->assertEquals('text', $profileFeed->title->type);
  43. $this->assertEquals('Profile Feed', $profileFeed->title->text);
  44. $this->assertEquals('self', $profileFeed->getLink('self')->rel);
  45. $this->assertEquals('application/atom+xml', $profileFeed->getLink('self')->type);
  46. $this->assertEquals('https://www.google.com/health/feeds/profile/default?digest=false',
  47. $profileFeed->getLink('self')->href);
  48. $this->assertEquals(1, $profileFeed->startIndex->text);
  49. }
  50. public function testAllSamplePropertiesAreCorrect() {
  51. $this->profileFeed->transferFromXML($this->feedText);
  52. $this->verifyAllSamplePropertiesAreCorrect($this->profileFeed);
  53. }
  54. public function testToAndFromXMLString()
  55. {
  56. $this->assertEquals(0, count($this->profileFeed->entry));
  57. $this->profileFeed->transferFromXML($this->feedText);
  58. $this->assertEquals(15, count($this->profileFeed->entry));
  59. foreach($this->profileFeed->entry as $entry)
  60. {
  61. $this->assertTrue($entry instanceof Zend_Gdata_Health_ProfileEntry);
  62. }
  63. $newProfileFeed = new Zend_Gdata_Health_ProfileFeed();
  64. $doc = new DOMDocument();
  65. $doc->loadXML($this->profileFeed->saveXML());
  66. $newProfileFeed->transferFromDom($doc->documentElement);
  67. $this->assertEquals(15, count($newProfileFeed->entry));
  68. foreach($newProfileFeed->entry as $entry)
  69. {
  70. $this->assertTrue($entry instanceof Zend_Gdata_Health_ProfileEntry);
  71. }
  72. }
  73. public function testGetEntries()
  74. {
  75. $this->profileFeed->transferFromXML($this->feedText);
  76. $entries = $this->profileFeed->getEntries();
  77. $this->assertTrue(is_array($entries));
  78. $this->assertEquals(15, count($entries));
  79. }
  80. public function testGetAllCcrFromProfileEntries()
  81. {
  82. $newProfileFeed = new Zend_Gdata_Health_ProfileFeed();
  83. $newProfileFeed->transferFromXML($this->feedText);
  84. foreach($newProfileFeed->entry as $entry)
  85. {
  86. $ccr = $entry->getCcr();
  87. $this->assertTrue($ccr instanceof Zend_Gdata_Health_Extension_Ccr);
  88. }
  89. }
  90. public function testGetFirstEntrysCcrMedication()
  91. {
  92. $this->profileFeed->transferFromXML($this->feedText);
  93. $medications = $this->profileFeed->entry[0]->getCcr()->getMedications();
  94. $this->assertType('DOMNodeList', $medications);
  95. $this->assertEquals(1, count($medications));
  96. foreach ($medications as $med) {
  97. $xmlStr = $med->ownerDocument->saveXML($med);
  98. $this->assertXmlStringEqualsXmlString(file_get_contents(
  99. 'Zend/Gdata/Health/_files/TestDataHealthProfileEntrySample_medications3.xml', true),
  100. $xmlStr);
  101. }
  102. }
  103. }