2
0

ProfileFeedTest.php 4.6 KB

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