From 15305937bb1ed62c0588163680864eea6f496540 Mon Sep 17 00:00:00 2001 From: Brady Miller Date: Thu, 10 Oct 2024 23:16:36 -0700 Subject: [PATCH] interim --- tests/Tests/E2e/Base/BaseTrait.php | 11 +++ tests/Tests/E2e/CheckUserMenuLinksTest.php | 8 +- tests/Tests/E2e/CreatePatientTest.php | 1 - tests/Tests/E2e/Login/LoginTrait.php | 8 +- tests/Tests/E2e/OpenPatientTest.php | 31 +++++++ tests/Tests/E2e/Patient/PatientAddTrait.php | 14 +--- tests/Tests/E2e/Patient/PatientOpenTrait.php | 80 +++++++++++++++++++ tests/Tests/E2e/Xpaths/XpathsConstants.php | 10 ++- .../XpathsConstantsPatientOpenTrait.php | 27 +++++++ 9 files changed, 164 insertions(+), 26 deletions(-) create mode 100644 tests/Tests/E2e/OpenPatientTest.php create mode 100644 tests/Tests/E2e/Patient/PatientOpenTrait.php create mode 100644 tests/Tests/E2e/Xpaths/XpathsConstantsPatientOpenTrait.php diff --git a/tests/Tests/E2e/Base/BaseTrait.php b/tests/Tests/E2e/Base/BaseTrait.php index 9481dbde517..1de66f2d2fa 100644 --- a/tests/Tests/E2e/Base/BaseTrait.php +++ b/tests/Tests/E2e/Base/BaseTrait.php @@ -94,4 +94,15 @@ protected function goToUserMenuLink(string $menuTreeIcon): void $this->crawler = $this->client->refreshCrawler(); $this->crawler->filterXPath($menuLink2)->click(); } + + protected function isPatientExist(string $firstname, string $lastname, string $dob, string $sex): bool + { + $patientDatabase = sqlQuery("SELECT `fname` FROM `patient_data` WHERE `fname` = ? AND `lname` = ? AND `DOB` = ? AND `sex` = ?", [$firstname, $lastname, $dob, $sex]); + if (!empty($patientDatabase['fname']) && ($patientDatabase['fname'] == $firstname)) { + return true; + } else { + return false; + } + + } } diff --git a/tests/Tests/E2e/CheckUserMenuLinksTest.php b/tests/Tests/E2e/CheckUserMenuLinksTest.php index 4ad97ebac0e..df49acb12b9 100644 --- a/tests/Tests/E2e/CheckUserMenuLinksTest.php +++ b/tests/Tests/E2e/CheckUserMenuLinksTest.php @@ -3,11 +3,11 @@ /** * CheckUserMenuLinksTest class * - * @package OpenEMR - * @link https://www.open-emr.org - * @author Brady Miller + * @package OpenEMR + * @link https://www.open-emr.org + * @author Brady Miller * @copyright Copyright (c) 2024 Brady Miller - * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 + * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 */ declare(strict_types=1); diff --git a/tests/Tests/E2e/CreatePatientTest.php b/tests/Tests/E2e/CreatePatientTest.php index a9777127c4f..11a650bd10e 100644 --- a/tests/Tests/E2e/CreatePatientTest.php +++ b/tests/Tests/E2e/CreatePatientTest.php @@ -28,5 +28,4 @@ class CreatePatientTest extends PantherTestCase protected $client; protected $crawler; - } diff --git a/tests/Tests/E2e/Login/LoginTrait.php b/tests/Tests/E2e/Login/LoginTrait.php index 6919cbc973a..84da4e96592 100644 --- a/tests/Tests/E2e/Login/LoginTrait.php +++ b/tests/Tests/E2e/Login/LoginTrait.php @@ -3,11 +3,11 @@ /** * LoginTrait trait * - * @package OpenEMR - * @link https://www.open-emr.org - * @author Brady Miller + * @package OpenEMR + * @link https://www.open-emr.org + * @author Brady Miller * @copyright Copyright (c) 2024 Brady Miller - * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 + * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 */ declare(strict_types=1); diff --git a/tests/Tests/E2e/OpenPatientTest.php b/tests/Tests/E2e/OpenPatientTest.php new file mode 100644 index 00000000000..4aeb63a41d4 --- /dev/null +++ b/tests/Tests/E2e/OpenPatientTest.php @@ -0,0 +1,31 @@ + + * @copyright Copyright (c) 2024 Brady Miller + * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 + */ + +declare(strict_types=1); + +namespace OpenEMR\Tests\E2e; + +use OpenEMR\Tests\E2e\Base\BaseTrait; +use OpenEMR\Tests\E2e\Login\LoginTrait; +use OpenEMR\Tests\E2e\Patient\PatientOpenTrait; +use Symfony\Component\Panther\PantherTestCase; +use Symfony\Component\Panther\Client; + +class OpenPatientTest extends PantherTestCase +{ + use BaseTrait; + use LoginTrait; + use PatientOpenTrait; + + protected $client; + protected $crawler; +} diff --git a/tests/Tests/E2e/Patient/PatientAddTrait.php b/tests/Tests/E2e/Patient/PatientAddTrait.php index 7c62bb33530..7e153c2186a 100644 --- a/tests/Tests/E2e/Patient/PatientAddTrait.php +++ b/tests/Tests/E2e/Patient/PatientAddTrait.php @@ -31,7 +31,7 @@ public function testPatientAdd(): void { $this->base(); try { - $this->patientAddIfNotExist('Addtestf', 'Addtestl', '1968-06-01', 'Male'); + $this->patientAddIfNotExist('Ftest', 'Ltest', '1968-06-01', 'Male'); } catch (\Throwable $e) { // Close client $this->client->quit(); @@ -90,22 +90,10 @@ protected function PatientAddIfNotExist(string $firstname, string $lastname, str $this->client->switchTo()->defaultContent(); $this->client->waitFor(XpathsConstants::PATIENT_IFRAME); $this->switchToIFrame(XpathsConstants::PATIENT_IFRAME); - //$this->client->takeScreenshot('/pics/2.png'); // below line will timeout if did not go to the patient summary screen for the new patient $this->client->waitFor('//*[text()="Medical Record Dashboard - ' . $firstname . " " . $lastname . '"]'); // ensure the patient was added $this->assertTrue($this->isPatientExist($firstname, $lastname, $dob, $sex), 'New patient is not in database, so FAILED'); } - - protected function isPatientExist(string $firstname, string $lastname, string $dob, string $sex): bool - { - $patientDatabase = sqlQuery("SELECT `fname` FROM `patient_data` WHERE `fname` = ? AND `lname` = ? AND `DOB` = ? AND `sex` = ?", [$firstname, $lastname, $dob, $sex]); - if (!empty($patientDatabase['fname']) && ($patientDatabase['fname'] == $firstname)) { - return true; - } else { - return false; - } - - } } diff --git a/tests/Tests/E2e/Patient/PatientOpenTrait.php b/tests/Tests/E2e/Patient/PatientOpenTrait.php new file mode 100644 index 00000000000..1e4ecb21a23 --- /dev/null +++ b/tests/Tests/E2e/Patient/PatientOpenTrait.php @@ -0,0 +1,80 @@ + + * @copyright Copyright (c) 2024 Brady Miller + * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 + */ + +declare(strict_types=1); + +namespace OpenEMR\Tests\E2e\Patient; + +use OpenEMR\Tests\E2e\Base\BaseTrait; +use OpenEMR\Tests\E2e\Login\LoginTrait; +use OpenEMR\Tests\E2e\Patient\PatientAddTrait; +use OpenEMR\Tests\E2e\Xpaths\XpathsConstants; +use OpenEMR\Tests\E2e\Xpaths\XpathsConstantsPatientOpenTrait; + +trait PatientOpenTrait +{ + use BaseTrait; + use LoginTrait; + use PatientAddTrait; + + /** + * @depends testLoginAuthorized + */ + public function testPatientOpen(): void + { + $this->base(); + try { + $this->patientOpenIfExist('Ftest', 'Ltest', '1968-06-01', 'Male'); + } catch (\Throwable $e) { + // Close client + $this->client->quit(); + // re-throw the exception + throw $e; + } + // Close client + $this->client->quit(); + } + + protected function PatientOpenIfExist(string $firstname, string $lastname, string $dob, string $sex): void + { + // if patient does not already exists, then fail + if (!$this->isPatientExist($firstname, $lastname, $dob, $sex)) { + $this->fail('Patient does not exist so FAIL'); + } + + // login + $this->login('admin', 'pass'); + + // search for last name via anySearchBox + $this->client->waitFor(XpathsConstantsPatientOpenTrait::ANYSEARCHBOX_FORM_PATIENTOPEN_TRAIT); + $this->crawler = $this->client->refreshCrawler(); + $searchForm = $this->crawler->filterXPath(XpathsConstantsPatientOpenTrait::ANYSEARCHBOX_FORM_PATIENTOPEN_TRAIT)->form(); + $searchForm['anySearchBox'] = $lastname; + $this->client->waitFor(XpathsConstantsPatientOpenTrait::ANYSEARCHBOX_CLICK_PATIENTOPEN_TRAIT); + $this->crawler = $this->client->refreshCrawler(); + $this->crawler->filterXPath(XpathsConstantsPatientOpenTrait::ANYSEARCHBOX_CLICK_PATIENTOPEN_TRAIT)->click(); + + // click on the name in the patient list + $this->client->waitFor(XpathsConstants::PATIENT_FINDER_IFRAME); + $this->switchToIFrame(XpathsConstants::PATIENT_FINDER_IFRAME); + $this->client->waitFor('//a[text()="' . $lastname . ", " . $firstname . '"]'); + $this->crawler = $this->client->refreshCrawler(); + $this->crawler->filterXPath('//a[text()="' . $lastname . ", " . $firstname . '"]')->click(); + + // ensure the patient summary screen is shown + $this->client->switchTo()->defaultContent(); + $this->client->waitFor(XpathsConstants::PATIENT_IFRAME); + $this->switchToIFrame(XpathsConstants::PATIENT_IFRAME); + // below line will timeout if did not go to the patient summary screen for the opened patient + $this->client->waitFor('//*[text()="Medical Record Dashboard - ' . $firstname . " " . $lastname . '"]'); + } +} diff --git a/tests/Tests/E2e/Xpaths/XpathsConstants.php b/tests/Tests/E2e/Xpaths/XpathsConstants.php index d7d66ef26ff..d8d971dae31 100644 --- a/tests/Tests/E2e/Xpaths/XpathsConstants.php +++ b/tests/Tests/E2e/Xpaths/XpathsConstants.php @@ -3,11 +3,11 @@ /** * XpathsConstants class * - * @package OpenEMR - * @link https://www.open-emr.org - * @author Brady Miller + * @package OpenEMR + * @link https://www.open-emr.org + * @author Brady Miller * @copyright Copyright (c) 2024 Brady Miller - * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 + * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 */ declare(strict_types=1); @@ -25,4 +25,6 @@ class XpathsConstants public const ADMIN_IFRAME = "//*[@id='framesDisplay']//iframe[@name='adm']"; public const PATIENT_IFRAME = "//*[@id='framesDisplay']//iframe[@name='pat']"; + + public const PATIENT_FINDER_IFRAME = "//*[@id='framesDisplay']//iframe[@name='fin']"; } diff --git a/tests/Tests/E2e/Xpaths/XpathsConstantsPatientOpenTrait.php b/tests/Tests/E2e/Xpaths/XpathsConstantsPatientOpenTrait.php new file mode 100644 index 00000000000..01a240a4733 --- /dev/null +++ b/tests/Tests/E2e/Xpaths/XpathsConstantsPatientOpenTrait.php @@ -0,0 +1,27 @@ + + * @copyright Copyright (c) 2024 Brady Miller + * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 + */ + +declare(strict_types=1); + +namespace OpenEMR\Tests\E2e\Xpaths; + +class XpathsConstantsPatientOpenTrait +{ + public const ANYSEARCHBOX_FORM_PATIENTOPEN_TRAIT = "//form[@name='frm_search_globals']"; + + public const ANYSEARCHBOX_CLICK_PATIENTOPEN_TRAIT = "//button[@id='search_globals']"; +}