ProfileEntryTest.php 5.5 KB

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