2
0

ProfileFeedTest.php 4.7 KB

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