1: <?php
2: namespace Azalea\Selenium\App;
3:
4: use Azalea\Selenium\Toolkit\Page;
5: use Azalea\Selenium\App\Components\Popup;
6: use Azalea\Selenium\App\Login\LoginPage;
7:
8: class ApplicationTestCase extends \Azalea\Selenium\Toolkit\TestCase
9: {
10: public function setUpPage()
11: {
12: parent::setUpPage();
13:
14:
15: date_default_timezone_set("America/New_York");
16:
17:
18: $this->faker = \Faker\Factory::create();
19: }
20:
21: 22: 23: 24: 25: 26: 27:
28: public function supportsCustomer($cus_id)
29: {
30: return true;
31: }
32:
33: 34: 35: 36: 37:
38: public function getCustomerId()
39: {
40: return getenv("selenium_customer_id");
41: }
42:
43: 44: 45:
46: public function skip()
47: {
48: $this->markTestSkipped("Test case marked as skipped.");
49: }
50:
51: 52: 53: 54: 55:
56: public function login($email, $password)
57: {
58:
59:
60:
61:
62: $customerId = getenv("selenium_customer_id");
63: if ($customerId) {
64:
65: if (!$this->supportsCustomer($customerId)) {
66: $this->markTestSkipped(get_called_class()." is not applicable to customer #$customerId");
67: return;
68: }
69:
70: $parts = explode("@", $email);
71: $email = $parts[0].$customerId."@".$parts[1];
72: }
73:
74: $app = $this->getView("app.json");
75: $app->login->navigate()->login($email, $password);
76:
77: if (isset($_ENV['selenium_debug']) && $_ENV['selenium_debug'] == "1") {
78:
79: $this->url($this->url()."&".$_ENV['selenium_debug_param']);
80: }
81:
82: $this->app = $app;
83: $app->verifyAndWait();
84:
85:
86: $this->clearLocalStorage();
87: return $app;
88: }
89:
90: 91: 92: 93: 94:
95: public function getApp()
96: {
97: return $this->app;
98: }
99:
100: 101: 102: 103:
104: public function waitForAjax()
105: {
106: $self = $this;
107: $this->spinWait(function() use ($self) {
108: return $self->hasElement("#status_light.go_light16");
109: });
110: }
111:
112: 113: 114: 115: 116:
117: public function waitForHaze($visible = true)
118: {
119: $this->spinWait(function ($driver) use ($visible) {
120: return ($driver->hasElement("#haze_screen_overlay") == $visible);
121: });
122:
123: return $this;
124: }
125:
126: 127: 128: 129: 130:
131: public function clearLocalStorage()
132: {
133: $this->javascript('window.localStorage.clear();');
134: return $this;
135: }
136:
137: 138: 139:
140:
141: 142: 143: 144: 145: 146: 147:
148: public function assertView($path, $args = array(), $timeout = 30)
149: {
150: $view = $this->getView($path, $args);
151: $view->verifyAndWait($timeout);
152: $this->assertTrue(true);
153: return $view;
154: }
155:
156: 157: 158: 159: 160: 161: 162:
163: public function assertNoErrorPopups($wait = 0)
164: {
165: if ($wait > 0) {
166: $this->wait($wait);
167: }
168: $this->assertFalse($this->hasElement(".awa-mvc-PopupView.error"));
169: return $this;
170: }
171:
172: 173: 174: 175: 176: 177: 178:
179: public function assertErrorPopup($errorText = null, $wait = 0)
180: {
181: if ($wait > 0) {
182: $this->wait($wait);
183: }
184: $this->assertTrue($this->hasElement(".awa-mvc-PopupView.error"));
185: if ($errorText) {
186: $this->filter(".awa-mvc-PopupView.error")->assertCanSee($errorText);
187: }
188: return $this;
189: }
190:
191: 192: 193: 194: 195: 196: 197:
198: public function assertPatientRecord($pat_id)
199: {
200: $this->assertView("patients/patient.json", array("pat_id" => $pat_id));
201: return $this;
202: }
203:
204: 205: 206:
207:
208:
209:
210: 211: 212:
213:
214: 215: 216: 217: 218: 219: 220:
221: public function getChartEncounterIdFromHash($timeout = 30)
222: {
223:
224: $matches = null;
225: $regex = "/#\/charts\/c\/(\d+)[\/\w+]*/";
226: $this->waitForHash($regex);
227: preg_match($regex, $this->getCurrentHash(), $matches);
228: $enc_id = $matches[1];
229: return $enc_id;
230: }
231:
232:
233: 234: 235:
236:
237: 238: 239: 240: 241: 242: 243:
244: public function getEncounterIdFromHash($timeout = 30)
245: {
246:
247: $matches = null;
248: $regex = "/#\/encounters\/e\/(\d+)[\/\w+]*/";
249: $this->waitForHash($regex);
250: preg_match($regex, $this->getCurrentHash(), $matches);
251: $enc_id = $matches[1];
252: return $enc_id;
253: }
254: }
255:
256: ?>