1: <?php
2: namespace Azalea\Selenium\PHR;
3:
4: /**
5: * Page object which serves as a base to all applications.
6: */
7: class Application extends \Azalea\Selenium\Core\Page
8: {
9: const APPLICATION_CONTAINER_ID = "main_view";
10:
11: /** @var string $heading To be set by child class */
12: protected $heading = "";
13:
14: /**
15: * Logs into the application with the given credentials.
16: * @param \Azalea\Test\TestCase\BaseTestCase $driver
17: * @param string $email
18: * @param string $password
19: * @throws \InvalidArgumentException
20: * @return \Azalea\Test\Core\Page
21: */
22: public static function login($driver, $email, $password)
23: {
24: if (!$driver) {
25: throw new \InvalidArgumentException(get_class($this).": driver not defined");
26: }
27:
28: $login = \Azalea\Selenium\Login\LoginPage::get($driver);
29: $login->login($email, $password);
30:
31: $classname = get_called_class();
32: return new $classname($driver);
33: }
34:
35: /**
36: * Logs into the application with the given User.
37: * @param \Azalea\Test\TestCase\BaseTestCase $driver
38: * @param \Azalea\Test\Util\User $user
39: * @throws \InvalidArgumentException
40: * @return \Azalea\Test\Core\Page
41: */
42: public static function loginAs($driver, $user)
43: {
44: return static::login($driver, $user->getEmail(), $user->getPassword());
45: }
46:
47: /**
48: * Logs out of the application by completing the log out user
49: * interaction sequence.
50: * @return \Azalea\Test\Page\LoginPage
51: */
52: public function logout()
53: {
54: // click the user name drop down menu link
55: $this->clickAndWait($this->byId("ui_user_info"));
56:
57: // click the logout link
58: $this->clickAndWait($this->byCss("#logout > a"));
59:
60: return new \Azalea\Selenium\Login\LoginPage($this->driver);
61: }
62:
63: /**
64: * Returns true if there is an error popup displayed
65: * on the screen.
66: * Optionally, if $text is supplied, it will compare the
67: * popup's text with $text and return true only if they
68: * are a match
69: * @param string $text
70: * @return boolean
71: */
72: public function isErrorPopup($text = null)
73: {
74: $popupError = new UI\PopupError($this);
75: if (!is_string($text)) {
76: return $popupError->isVisible();
77: }
78: return ($popupError->isVisible() && $popupError->getText() == $text);
79: }
80:
81: /**
82: * Called by the Page class to verify that we are on the
83: * correct page.
84: */
85: protected function verify()
86: {
87: // verify main_view container
88: $this->byId(Application::APPLICATION_CONTAINER_ID);
89:
90: // heading should be present
91: return $this->isTextPresent($this->heading, $this->byCss("#title_menu .heading"));
92: }
93: }
94: ?>