ProfileEntryTest.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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/ProfileEntry.php';
  24. /**
  25. * @category Zend
  26. * @package Zend_Gdata_Health
  27. * @subpackage UnitTests
  28. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. * @group Zend_Gdata
  31. * @group Zend_Gdata_Health
  32. */
  33. class Zend_Gdata_Health_ProfileEntryTest extends PHPUnit_Framework_TestCase
  34. {
  35. public function setUp()
  36. {
  37. $this->entry = new Zend_Gdata_Health_ProfileEntry();
  38. $this->entryText = file_get_contents(
  39. 'Zend/Gdata/Health/_files/TestDataHealthProfileEntrySample.xml',
  40. true);
  41. }
  42. public function testEmptyProfileEntry()
  43. {
  44. $this->assertTrue(is_array($this->entry->extensionElements));
  45. $this->assertTrue(count($this->entry->extensionElements) == 0);
  46. $this->assertTrue($this->entry->getCcr() === null);
  47. }
  48. public function testEmptyProfileEntryToAndFromStringShouldMatch() {
  49. $this->entry->transferFromXML($this->entryText);
  50. $entryXml = $this->entry->saveXML();
  51. $newProfileEntry = new Zend_Gdata_Health_ProfileEntry();
  52. $newProfileEntry->transferFromXML($entryXml);
  53. $newProfileEntryXML = $newProfileEntry->saveXML();
  54. $this->assertTrue($entryXml == $newProfileEntryXML);
  55. }
  56. public function testGetAllCcrFromProfileEntry()
  57. {
  58. $this->entry->transferFromXML($this->entryText);
  59. $ccr = $this->entry->getCcr();
  60. $this->assertTrue($ccr instanceof Zend_Gdata_Health_Extension_Ccr);
  61. $this->assertXmlStringEqualsXmlString(file_get_contents(
  62. 'Zend/Gdata/Health/_files/TestDataHealthProfileEntrySample_just_ccr.xml', true), $ccr->getXML());
  63. }
  64. public function testSetCcrInProfileEntry()
  65. {
  66. $this->entry->transferFromXML($this->entryText);
  67. $ccrXML = file_get_contents(
  68. 'Zend/Gdata/Health/_files/TestDataHealthProfileEntrySample_just_ccr.xml', true);
  69. $ccrElement = $this->entry->setCcr($ccrXML);
  70. $this->assertTrue($ccrElement instanceof Zend_Gdata_Health_Extension_Ccr);
  71. $this->assertXmlStringEqualsXmlString(file_get_contents(
  72. 'Zend/Gdata/Health/_files/TestDataHealthProfileEntrySample_just_ccr.xml', true), $this->entry->getCcr()->getXML());
  73. }
  74. /*
  75. * These functions test the magic _call method within Zend_Gdata_Health_Extension_Ccr
  76. */
  77. public function testGetCcrMedicationsFromProfileEntry()
  78. {
  79. $this->entry->transferFromXML($this->entryText);
  80. $medications = $this->entry->getCcr()->getMedications();
  81. $this->assertEquals(1, count($medications));
  82. foreach ($medications as $med) {
  83. $this->assertXmlStringEqualsXmlString(file_get_contents(
  84. "Zend/Gdata/Health/_files/TestDataHealthProfileEntrySample_medications_all.xml", true),
  85. $med->ownerDocument->saveXML($med));
  86. }
  87. }
  88. public function testGetCcrConditionsFromProfileEntry()
  89. {
  90. $this->entry->transferFromXML($this->entryText);
  91. $problems = $this->entry->getCcr()->getProblems();
  92. $conditions = $this->entry->getCcr()->getConditions();
  93. $this->assertEquals($problems, $conditions);
  94. $this->assertEquals(1, count($conditions));
  95. foreach ($conditions as $index => $condition) {
  96. $this->assertXmlStringEqualsXmlString(file_get_contents(
  97. "Zend/Gdata/Health/_files/TestDataHealthProfileEntrySample_condition_all.xml", true),
  98. $condition->ownerDocument->saveXML($condition));
  99. }
  100. }
  101. public function testGetCcrAllerigiesFromProfileEntry()
  102. {
  103. $this->entry->transferFromXML($this->entryText);
  104. $allergies = $this->entry->getCcr()->getAllergies();
  105. $alerts = $this->entry->getCcr()->getAlerts();
  106. $this->assertEquals($allergies, $alerts);
  107. $this->assertEquals(1, count($alerts));
  108. foreach ($alerts as $index => $alert) {
  109. $this->assertXmlStringEqualsXmlString(file_get_contents(
  110. "Zend/Gdata/Health/_files/TestDataHealthProfileEntrySample_allergy_all.xml", true),
  111. $alert->ownerDocument->saveXML($alert));
  112. }
  113. }
  114. public function testGetCcrLabResultsFromProfileEntry()
  115. {
  116. $this->entry->transferFromXML($this->entryText);
  117. $labresults = $this->entry->getCcr()->getLabResults();
  118. $results = $this->entry->getCcr()->getResults();
  119. $this->assertEquals($labresults, $results);
  120. $this->assertEquals(1, count($results));
  121. foreach ($results as $index => $result) {
  122. $this->assertXmlStringEqualsXmlString(file_get_contents(
  123. "Zend/Gdata/Health/_files/TestDataHealthProfileEntrySample_results0.xml", true),
  124. $result->ownerDocument->saveXML($result));
  125. }
  126. }
  127. }