ProfileEntryTest.php 5.3 KB

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