1: <?php
2: namespace Azalea\Selenium\EHR;
3:
4: use \Azalea\Util\Config;
5:
6: /**
7: * Page object which serves as a base to all applications.
8: */
9: class Application extends \Azalea\Selenium\Core\Page
10: {
11: const APPLICATION_CONTAINER_ID = "main_view";
12:
13: /** @var string $heading To be set by child class */
14: protected $heading = "";
15:
16: /** @var \Azalea\Selenium\Core\User $user The active user */
17: protected $user = null;
18:
19: /** @var int $timeout Timeout for verifying page contents */
20: protected $timeout = 60;
21:
22: /**
23: * Logs into the application with the given credentials.
24: * @param \Azalea\Test\TestCase\BaseTestCase $driver
25: * @param string $email
26: * @param string $password
27: * @throws \InvalidArgumentException
28: * @return \Azalea\Test\Core\Page
29: */
30: public static function login($driver, $email, $password)
31: {
32: if (!$driver) {
33: throw new \InvalidArgumentException(get_class($this).": driver not defined");
34: }
35:
36: $login = \Azalea\Selenium\Login\LoginPage::get($driver);
37: $login->login($email, $password);
38:
39: if (isset($_ENV['selenium_debug']) && $_ENV['selenium_debug'] == "1") {
40: // run the application in debug mode
41: $driver->url($driver->url()."&".$_ENV['selenium_debug_param']);
42: }
43:
44: // create the application object
45: $classname = get_called_class();
46: $app = new $classname($driver);
47:
48: // save this user
49: $app->setUser(new \Azalea\Selenium\Core\User($email, $password));
50:
51: return $app;
52: }
53:
54: /**
55: * Logs into the application with the given User.
56: * @param \Azalea\Test\TestCase\BaseTestCase $driver
57: * @param \Azalea\Test\Util\User $user
58: * @throws \InvalidArgumentException
59: * @return \Azalea\Test\Core\Page
60: */
61: public static function loginAs($driver, $user)
62: {
63: return static::login($driver, $user->getEmail(), $user->getPassword());
64: }
65:
66: /**
67: * Locks the application screen.
68: * @return \Azalea\Selenium\EHR\UI\LockScreen
69: */
70: public function lockScreen()
71: {
72: $this->uiUserAcctMenu->clickLockScreen();
73: return new UI\LockScreen($this);
74: }
75:
76: /**
77: * Logs out of the application by completing the log out user
78: * interaction sequence.
79: * @return \Azalea\Selenium\Login\LoginPage
80: */
81: public function logout()
82: {
83: // click the logout link
84: $this->uiUserAcctMenu->clickLogout();
85: return new \Azalea\Selenium\Login\LoginPage($this);
86: }
87:
88: /**
89: * Returns the application's main menu instance.
90: * @return \Azalea\Selenium\EHR\UI\MainMenu
91: */
92: public function getMainMenu()
93: {
94: return $this->uiMainMenu;
95: }
96:
97: /**
98: * Returns the application's main search instance.
99: * @return \Azalea\Selenium\EHR\UI\MainSearch
100: */
101: public function getMainSearch()
102: {
103: return $this->uiMainSearch;
104: }
105:
106: /**
107: * Returns the application's notifications instance.
108: * @return \Azalea\Selenium\EHR\UI\Notifications
109: */
110: public function getNotifications()
111: {
112: return $this->uiNotifications;
113: }
114:
115: /**
116: * Returns the session's active user.
117: * @return \Azalea\Selenium\Core\User
118: */
119: public function getUser()
120: {
121: return $this->user;
122: }
123:
124: /**
125: * Sets the session's active user.
126: * @param \Azalea\Selenium\Core\User $user
127: */
128: public function setUser($user)
129: {
130: $this->user = $user;
131: }
132:
133: /**
134: * Returns true if there is an error popup displayed
135: * on the screen.
136: * Optionally, if $text is supplied, it will compare the
137: * popup's text with $text and return true only if they
138: * are a match
139: * @param string $text
140: * @return boolean
141: */
142: public function isErrorPopup($text = null)
143: {
144: $popupError = new UI\PopupError($this);
145: if (!is_string($text)) {
146: return $popupError->isVisible();
147: }
148: return ($popupError->isVisible() && $popupError->getText() == $text);
149: }
150:
151: /**
152: * Closes all popups that are visible on the screen, if any.
153: */
154: public function closeAllPopups()
155: {
156: UI\Popup::closeAll($this->driver);
157: }
158:
159: /**
160: * Returns true if the haze screen is visible on the page.
161: * @return boolean
162: */
163: public function isHazeScreenVisible()
164: {
165: return $this->displayedById("haze_screen_overlay");
166: }
167:
168: /**
169: * Returns true if the haze screen is NOT visible on the page.
170: * @return boolean
171: */
172: public function isHazeScreenNotVisible()
173: {
174: return (!$this->displayedById("haze_screen_overlay"));
175: }
176:
177: /**
178: * Reruns the application's verification and returns true if it passes.
179: * @throws \RuntimeException
180: * @return boolean
181: */
182: public function reVerify()
183: {
184: try {
185: if (!$this->verify()) {
186: return false;
187: }
188: } catch(\Exception $e) {
189: return false;
190: }
191: return true;
192: }
193:
194: /**
195: * Extracts the ahis session key from the browser's url and saves it on
196: * the application object.
197: * @param \Azalea\Test\TestCase\BaseTestCase $driver
198: * @return void
199: */
200: public function getSessionKey()
201: {
202: $urlInfo = parse_url($this->driver->url());
203: $params = explode("&", $urlInfo['query']);
204: foreach($params as $param) {
205: $parts = explode("=", $param);
206: if ($parts[0] == "ahis") {
207: return $parts[1];
208: }
209: }
210: return "";
211: }
212:
213: /**
214: * Called by the Page class to verify that we are on the
215: * correct page.
216: */
217: protected function verify()
218: {
219: // verify main_view container
220: $this->byId(Application::APPLICATION_CONTAINER_ID);
221:
222: // main application menu
223: $this->uiMainMenu = new UI\MainMenu($this);
224:
225: // main application search
226: $this->uiMainSearch = new UI\MainSearch($this);
227:
228: // user account menu
229: $this->uiUserAcctMenu = new UI\UserAccountMenu($this);
230:
231: // application heading
232: $this->uiHeading = new UI\Heading($this);
233:
234: // notifications
235: $this->uiNotifications = new UI\Notifications($this);
236:
237: return $this->uiHeading->matches($this->heading);
238: }
239: }
240: ?>