1: <?php
2: namespace Azalea\Selenium\EHR\UI;
3:
4: class TabContainer extends \Azalea\Selenium\Core\View
5: {
6: protected static $tabs = array();
7:
8: 9: 10: 11: 12: 13:
14: public function openTab($name, $args = array())
15: {
16: if (!isset(static::$tabs[$name])) {
17: throw new \InvalidArgumentException("Invalid tab: ".$name);
18: }
19:
20: $classname = static::$tabs[$name];
21: $tabInstance = $classname::get($this, $args);
22: $this->wait(4);
23: return $tabInstance;
24: }
25:
26: 27: 28: 29: 30: 31: 32:
33: public function getTab($name, $args = array())
34: {
35: if (!isset(static::$tabs[$name])) {
36: throw new \InvalidArgumentException("Invalid tab: ".$name);
37: }
38:
39: $classname = static::$tabs[$name];
40: return new $classname($this);
41: }
42:
43: 44: 45: 46: 47:
48: public function closeTab($tab)
49: {
50: if (is_string($tab)) {
51: $action = $tab;
52: } else {
53: $action = $tab->getSelector();
54: }
55:
56: $action = str_replace("#", "", $action);
57:
58: $this->byCss(static::$selector.' [action="'.$action.'"] .tabClose')->click();
59: }
60:
61: 62: 63:
64: public function closeAllTabs()
65: {
66: $elements = $this->getElementsByCss(static::$selector.' .tabClose');
67: if (count($elements)) {
68: foreach($elements as $element) {
69: if ($element->attribute('title') != "Close all tabs") {
70: $element->click();
71: }
72: }
73: }
74: }
75:
76: 77: 78: 79: 80:
81: public function hasTab($name)
82: {
83: if (!isset(static::$tabs[$name])) {
84: throw new \InvalidArgumentException("Invalid tab: ".$name);
85: }
86:
87: try {
88: $classname = static::$tabs[$name];
89: $tabInstance = $classname::get($this, $args);
90: } catch (\Exception $e) {
91: return false;
92: }
93: return true;
94: }
95: }
96: ?>