1
1
<?php
2
2
3
+ /**
4
+ * CheckMainMenuLinksTest class
5
+ *
6
+ * @package OpenEMR
7
+ * @link https://www.open-emr.org
8
+ * @author Brady Miller <brady.g.miller@gmail.com>
9
+ * @copyright Copyright (c) 2024 Brady Miller <brady.g.miller@gmail.com>
10
+ * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
11
+ */
12
+
3
13
declare (strict_types=1 );
4
14
5
15
namespace OpenEMR \Tests \E2e ;
6
16
17
+ use OpenEMR \Tests \E2e \Base \BaseTrait ;
18
+ use OpenEMR \Tests \E2e \Login \LoginTrait ;
7
19
use Symfony \Component \Panther \PantherTestCase ;
8
20
use Symfony \Component \Panther \Client ;
9
21
10
22
class CheckMainMenuLinksTest extends PantherTestCase
11
23
{
12
- /**
13
- * The base url used for e2e (end to end) browser testing.
14
- */
15
- private $ e2eBaseUrl ;
24
+ use BaseTrait;
25
+ use LoginTrait;
16
26
17
- private $ client ;
18
- private $ crawler ;
19
-
20
- protected function setUp (): void
21
- {
22
- $ this ->e2eBaseUrl = getenv ("OPENEMR_BASE_URL_E2E " , true ) ?: "http://localhost " ;
23
- }
24
-
25
- public function testLogin (): void
26
- {
27
- $ openEmrPage = $ this ->e2eBaseUrl ;
28
- $ this ->client = static ::createPantherClient (['external_base_uri ' => $ openEmrPage ]);
29
- $ this ->client ->manage ()->window ()->maximize ();
30
- try {
31
- $ this ->login ('admin ' , 'pass ' );
32
- } catch (\Throwable $ e ) {
33
- // Close client
34
- $ this ->client ->quit ();
35
- // re-throw the exception
36
- throw $ e ;
37
- }
38
- // Close client
39
- $ this ->client ->quit ();
40
- }
27
+ protected $ client ;
28
+ protected $ crawler ;
41
29
42
30
/**
43
31
* @dataProvider menuLinkProvider
44
- * @depends testLogin
32
+ * @depends testLoginAuthorized
45
33
*/
46
34
public function testCheckMenuLink (string $ menuLink , string $ expectedTabTitle ): void
47
35
{
@@ -50,9 +38,7 @@ public function testCheckMenuLink(string $menuLink, string $expectedTabTitle): v
50
38
// a high enough version of nodejs)
51
39
$ this ->markTestSkipped ('Test skipped because this environment does not support high enough nodejs version. ' );
52
40
}
53
- $ openEmrPage = $ this ->e2eBaseUrl ;
54
- $ this ->client = static ::createPantherClient (['external_base_uri ' => $ openEmrPage ]);
55
- $ this ->client ->manage ()->window ()->maximize ();
41
+ $ this ->base ();
56
42
try {
57
43
$ this ->login ('admin ' , 'pass ' );
58
44
// check if the menu cog is showing. if so, then click it.
@@ -89,9 +75,7 @@ public function testCheckMenuLink(string $menuLink, string $expectedTabTitle): v
89
75
$ counter ++;
90
76
}
91
77
// wait for the tab title to be shown
92
- $ this ->client ->waitForElementToContain ("//div[@id='tabs_div']/div/div[not(contains(concat(' ',normalize-space(@class),' '),' tabsNoHover '))] " , $ expectedTabTitle );
93
- // Perform the final assertion
94
- $ this ->assertSame ($ expectedTabTitle , $ this ->crawler ->filterXPath ("//div[@id='tabs_div']/div/div[not(contains(concat(' ',normalize-space(@class),' '),' tabsNoHover '))] " )->text (), 'Page load FAILED ' );
78
+ $ this ->assertActiveTab ($ expectedTabTitle );
95
79
} catch (\Throwable $ e ) {
96
80
// Close client
97
81
$ this ->client ->quit ();
@@ -200,16 +184,4 @@ public static function menuLinkProvider()
200
184
'Miscellaneous -> New Documents menu link ' => ['Miscellaneous||New Documents ' , 'Documents ' ]
201
185
];
202
186
}
203
-
204
- private function login (string $ name , string $ password ): void
205
- {
206
- // login
207
- $ this ->crawler = $ this ->client ->request ('GET ' , '/interface/login/login.php?site=default ' );
208
- $ form = $ this ->crawler ->filter ('#login_form ' )->form ();
209
- $ form ['authUser ' ] = $ name ;
210
- $ form ['clearPass ' ] = $ password ;
211
- $ this ->crawler = $ this ->client ->submit ($ form );
212
- $ title = $ this ->client ->getTitle ();
213
- $ this ->assertSame ('OpenEMR ' , $ title , 'Login FAILED ' );
214
- }
215
187
}
0 commit comments