context = $parameters; } /** * Get Mink session from MinkContext */ public function getSession($name = null) { return $this->getMainContext()->getSession($name); } /** * @Then /^I should see the CMS$/ */ public function iShouldSeeTheCms() { $page = $this->getSession()->getPage(); $cms_element = $page->find('css', '.cms'); assertNotNull($cms_element, 'CMS not found'); } /** * @Then /^I should see a "([^"]*)" notice$/ */ public function iShouldSeeANotice($notice) { $this->getMainContext()->assertElementContains('.notice-wrap', $notice); } /** * @Then /^I should see a "([^"]*)" message$/ */ public function iShouldSeeAMessage($message) { $this->getMainContext()->assertElementContains('.message', $message); } protected function getCmsTabsElement() { $this->getSession()->wait( 5000, "window.jQuery && window.jQuery('.cms-content-header-tabs').size() > 0" ); $page = $this->getSession()->getPage(); $cms_content_header_tabs = $page->find('css', '.cms-content-header-tabs'); assertNotNull($cms_content_header_tabs, 'CMS tabs not found'); return $cms_content_header_tabs; } protected function getCmsContentToolbarElement() { $this->getSession()->wait( 5000, "window.jQuery && window.jQuery('.cms-content-toolbar').size() > 0 " . "&& window.jQuery('.cms-content-toolbar').children().size() > 0" ); $page = $this->getSession()->getPage(); $cms_content_toolbar_element = $page->find('css', '.cms-content-toolbar'); assertNotNull($cms_content_toolbar_element, 'CMS content toolbar not found'); return $cms_content_toolbar_element; } protected function getCmsTreeElement() { $this->getSession()->wait( 5000, "window.jQuery && window.jQuery('.cms-tree').size() > 0" ); $page = $this->getSession()->getPage(); $cms_tree_element = $page->find('css', '.cms-tree'); assertNotNull($cms_tree_element, 'CMS tree not found'); return $cms_tree_element; } /** * @Given /^I should see a "([^"]*)" button in CMS Content Toolbar$/ */ public function iShouldSeeAButtonInCmsContentToolbar($text) { $cms_content_toolbar_element = $this->getCmsContentToolbarElement(); $element = $cms_content_toolbar_element->find('named', array('link_or_button', "'$text'")); assertNotNull($element, sprintf('%s button not found', $text)); } /** * @When /^I should see "([^"]*)" in the tree$/ */ public function stepIShouldSeeInCmsTree($text) { $cms_tree_element = $this->getCmsTreeElement(); $element = $cms_tree_element->find('named', array('content', "'$text'")); assertNotNull($element, sprintf('%s not found', $text)); } /** * @When /^I should not see "([^"]*)" in the tree$/ */ public function stepIShouldNotSeeInCmsTree($text) { $cms_tree_element = $this->getCmsTreeElement(); $element = $cms_tree_element->find('named', array('content', "'$text'")); assertNull($element, sprintf('%s found', $text)); } /** * Applies a specific action to an element * * @param NodeElement $element Element to act on * @param string $action Action, which may be one of 'hover', 'double click', 'right click', or 'left click' * The default 'click' behaves the same as left click */ protected function interactWithElement($element, $action = 'click') { switch($action) { case 'hover': $element->mouseOver(); break; case 'double click': $element->doubleClick(); break; case 'right click': $element->rightClick(); break; case 'left click': case 'click': default: $element->click(); break; } } /** * @When /^I (?P(?:(?:double |right |left |)click)|hover) on "(?P[^"]*)" in the context menu/ */ public function stepIClickOnElementInTheContextMenu($method, $link) { $context = $this->getMainContext(); // Wait until context menu has appeared $this->getSession()->wait( 1000, "window.jQuery && window.jQuery('.jstree-apple-context').size() > 0" ); $regionObj = $context->getRegionObj('.jstree-apple-context'); assertNotNull($regionObj, "Context menu could not be found"); $linkObj = $regionObj->findLink($link); if (empty($linkObj)) { throw new \Exception(sprintf( 'The link "%s" was not found in the context menu on the page %s', $link, $this->getSession()->getCurrentUrl() )); } $this->interactWithElement($linkObj, $method); } /** * @When /^I (?P(?:(?:double |right |left |)click)|hover) on "(?P[^"]*)" in the tree$/ */ public function stepIClickOnElementInTheTree($method, $text) { $treeEl = $this->getCmsTreeElement(); $treeNode = $treeEl->findLink($text); assertNotNull($treeNode, sprintf('%s not found', $text)); $this->interactWithElement($treeNode, $method); } /** * @When /^I expand the "([^"]*)" CMS Panel$/ */ public function iExpandTheCmsPanel() { //Tries to find the first visiable toggle in the page $page = $this->getSession()->getPage(); $toggle_elements = $page->findAll('css', '.toggle-expand'); assertNotNull($toggle_elements, 'Panel toggle not found'); foreach($toggle_elements as $toggle){ if($toggle->isVisible()){ $toggle->click(); } } } /** * @When /^I (expand|collapse) the content filters$/ */ public function iExpandTheContentFilters($action) { $page = $this->getSession()->getPage(); $filterButton = $page->find('css', '#filters-button'); assertNotNull($filterButton, sprintf('Filter button link not found')); $filterButtonCssClass = $filterButton->getAttribute('class'); if($action == 'expand') { if(strpos($filterButtonCssClass, 'active') === false) { $filterButton->click(); } } else { if(strpos($filterButtonCssClass, 'active') !== false) { $filterButton->click(); } } $this->getSession()->wait(2000, 'window.jQuery(".cms-content-filters:animated").length === 0'); } /** * @When /^I (expand|collapse) "([^"]*)" in the tree$/ */ public function iExpandInTheTree($action, $nodeText) { //Tries to find the first visiable matched Node in the page $page = $this->getSession()->getPage(); $treeEl = $this->getCmsTreeElement(); $treeNode = $treeEl->findLink($nodeText); assertNotNull($treeNode, sprintf('%s link not found', $nodeText)); $cssIcon = $treeNode->getParent()->getAttribute("class"); if($action == "expand") { //ensure it is collapsed if(false === strpos($cssIcon, 'jstree-open')) { $nodeIcon = $treeNode->getParent()->find('css', '.jstree-icon'); assertTrue($nodeIcon->isVisible(), "CMS node '$nodeText' not found"); $nodeIcon->click(); } } else { //ensure it is expanded if(false === strpos($cssIcon, 'jstree-closed')) { $nodeIcon = $treeNode->getParent()->find('css', '.jstree-icon'); assertTrue($nodeIcon->isVisible(), "CMS node '$nodeText' not found"); $nodeIcon->click(); } } } /** * @When /^I should (not |)see a "([^"]*)" CMS tab$/ */ public function iShouldSeeACmsTab($negate, $tab) { $this->getSession()->wait( 5000, "window.jQuery && window.jQuery('.ui-tabs-nav').size() > 0" ); $page = $this->getSession()->getPage(); $tabsets = $page->findAll('css', '.ui-tabs-nav'); assertNotNull($tabsets, 'CMS tabs not found'); $tab_element = null; foreach($tabsets as $tabset) { $tab_element = $tabset->find('named', array('link_or_button', "'$tab'")); if($tab_element) break; } if($negate) { assertNull($tab_element, sprintf('%s tab found', $tab)); } else { assertNotNull($tab_element, sprintf('%s tab not found', $tab)); } } /** * @When /^I click the "([^"]*)" CMS tab$/ */ public function iClickTheCmsTab($tab) { $this->getSession()->wait( 5000, "window.jQuery && window.jQuery('.ui-tabs-nav').size() > 0" ); $page = $this->getSession()->getPage(); $tabsets = $page->findAll('css', '.ui-tabs-nav'); assertNotNull($tabsets, 'CMS tabs not found'); $tab_element = null; foreach($tabsets as $tabset) { if($tab_element) continue; $tab_element = $tabset->find('named', array('link_or_button', "'$tab'")); } assertNotNull($tab_element, sprintf('%s tab not found', $tab)); $tab_element->click(); } /** * @Then /^I can see the preview panel$/ */ public function iCanSeeThePreviewPanel() { $this->getMainContext()->assertElementOnPage('.cms-preview'); } /** * @Given /^the preview contains "([^"]*)"$/ */ public function thePreviewContains($content) { $driver = $this->getSession()->getDriver(); // TODO Remove once we have native support in Mink and php-webdriver, // see https://groups.google.com/forum/#!topic/behat/QNhOuGHKEWI $origWindowName = $driver->getWebDriverSession()->window_handle(); $driver->switchToIFrame('cms-preview-iframe'); $this->getMainContext()->assertPageContainsText($content); $driver->switchToWindow($origWindowName); } /** * @Given /^I set the CMS mode to "([^"]*)"$/ */ public function iSetTheCmsToMode($mode) { return array( new Step\When(sprintf('I fill in the "Change view mode" dropdown with "%s"', $mode)), new Step\When('I wait for 1 second') // wait for CMS layout to redraw ); } /** * @Given /^I wait for the preview to load$/ */ public function iWaitForThePreviewToLoad() { $driver = $this->getSession()->getDriver(); // TODO Remove once we have native support in Mink and php-webdriver, // see https://groups.google.com/forum/#!topic/behat/QNhOuGHKEWI $origWindowName = $driver->getWebDriverSession()->window_handle(); $driver->switchToIFrame('cms-preview-iframe'); $this->getSession()->wait( 5000, "window.jQuery && !window.jQuery('iframe[name=cms-preview-iframe]').hasClass('loading')" ); $driver->switchToWindow($origWindowName); } /** * @Given /^I switch the preview to "([^"]*)"$/ */ public function iSwitchThePreviewToMode($mode) { $controls = $this->getSession()->getPage()->find('css', '.cms-preview-controls'); assertNotNull($controls, 'Preview controls not found'); $label = $controls->find('xpath', sprintf( './/label[(@for="%s")]', $mode )); assertNotNull($label, 'Preview mode switch not found'); $label->click(); return new Step\When('I wait for the preview to load'); } /** * @Given /^the preview does not contain "([^"]*)"$/ */ public function thePreviewDoesNotContain($content) { $driver = $this->getSession()->getDriver(); // TODO Remove once we have native support in Mink and php-webdriver, // see https://groups.google.com/forum/#!topic/behat/QNhOuGHKEWI $origWindowName = $driver->getWebDriverSession()->window_handle(); $driver->switchToIFrame('cms-preview-iframe'); $this->getMainContext()->assertPageNotContainsText($content); $driver->switchToWindow($origWindowName); } /** * When I follow "my link" in preview * * @When /^(?:|I )follow "(?P(?:[^"]|\\")*)" in preview$/ */ public function clickLinkInPreview($link) { $driver = $this->getSession()->getDriver(); // TODO Remove once we have native support in Mink and php-webdriver, // see https://groups.google.com/forum/#!topic/behat/QNhOuGHKEWI $origWindowName = $driver->getWebDriverSession()->window_handle(); $driver->switchToIFrame('cms-preview-iframe'); $link = $this->fixStepArgument($link); $this->getSession()->getPage()->clickLink($link); $driver->switchToWindow($origWindowName); } /** * When I press "submit" in preview * * @When /^(?:|I )press "(?P