Skip to content

Commit

Permalink
Merge pull request #141 from magento-qmt/mavericks
Browse files Browse the repository at this point in the history
[Mavericks] Navigation menu test and test maintenance
  • Loading branch information
Aponasenko, Dmytro(daponasenko) committed Mar 15, 2015
2 parents 2e67ccb + 919b5e1 commit e673fcf
Show file tree
Hide file tree
Showing 250 changed files with 7,803 additions and 4,088 deletions.
62 changes: 62 additions & 0 deletions dev/tests/functional/lib/Magento/Mtf/Fixture/DataSource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Mtf\Fixture;

use Magento\Mtf\Fixture\FixtureInterface;

/**
* Parent fixture data source class.
*/
class DataSource implements FixtureInterface
{
/**
* Data set configuration settings.
*
* @var array
*/
protected $params;

/**
* Value data.
*
* @var array
*/
protected $data;

/**
* Persist entity.
*
* @return void
*/
public function persist()
{
//
}

/**
* Return prepared data set.
*
* @param string $key [optional]
* @return mixed
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function getData($key = null)
{
return $this->data;
}

/**
* Return data set configuration settings.
*
* @return array
*/
public function getDataConfig()
{
return $this->params;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd">
<testCase name="Magento\Backend\Test\TestCase\NavigateMenuTest">
<variation name="NavigateMenuTest1">
<data name="menuItem" xsi:type="string">System > Notifications</data>
<data name="pageTitle" xsi:type="string">Notifications</data>
<constraint name="Magento\Backend\Test\Constraint\AssertBackendPageIsAvailable"/>
</variation>
</testCase>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,37 @@
use Magento\Mtf\Client\Locator;

/**
* Class Login
* Login form for backend user
*
* Login form for backend user.
*/
class Login extends Form
{
/**
* 'Log in' button
* 'Log in' button.
*
* @var string
*/
protected $submit = '.action-login';

/**
* Submit login form
* Submit login form.
*/
public function submit()
{
$this->_rootElement->find($this->submit, Locator::SELECTOR_CSS)->click();
}

/**
* Wait for Login form is not visible in the page.
*
* @return void
*/
public function waitFormNotVisible()
{
$form = $this->_rootElement;
$this->browser->waitUntil(
function () use ($form) {
return $form->isVisible() ? null : true;
}
);
}
}
73 changes: 68 additions & 5 deletions dev/tests/functional/tests/app/Magento/Backend/Test/Block/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,43 @@
namespace Magento\Backend\Test\Block;

use Magento\Mtf\Block\Block;
use Magento\Mtf\Client\Locator;

/**
* Class Menu
* Class top menu navigation block
* Top menu navigation block.
*/
class Menu extends Block
{
/**
* Returns array of parent menu items present on dashboard menu
* Main menu selector.
*
* @var string
*/
protected $mainMenu = './/li/a[span="%s"]';

/**
* Submenu selector.
*
* @var string
*/
protected $subMenu = './/li[a[span="%s"]]/div[@class="submenu" and @style="display: block;"]';

/**
* Submenu item selector.
*
* @var string
*/
protected $subMenuItem = './/a[span="%s"]';

/**
* Parent menu item.
*
* @var string
*/
protected $parentMenuLevel = 'li.parent.level-0:nth-of-type(%s)';

/**
* Returns array of parent menu items present on dashboard menu.
*
* @return array
*/
Expand All @@ -24,14 +52,49 @@ public function getTopMenuItems()
$menuItems = [];
$counter = 1;
$textSelector = 'a span';
while ($navigationMenu->find('li.parent.level-0:nth-of-type(' . $counter . ')')->isVisible()) {
while ($navigationMenu->find(sprintf($this->parentMenuLevel, $counter))->isVisible()) {
$menuItems[] = strtolower(
$navigationMenu->find('li.parent.level-0:nth-of-type(' . $counter . ')')
$navigationMenu->find(sprintf($this->parentMenuLevel, $counter))
->find($textSelector)
->getText()
);
$counter++;
}
return $menuItems;
}

/**
* Open backend page via menu.
*
* @param string $menuItem
* @return void
* @throws \Exception
*/
public function navigate($menuItem)
{
$menuChain = array_map('trim', explode('>', $menuItem));
$mainMenu = $menuChain[0];
$subMenu = isset($menuChain[1]) ? $menuChain[1] : null;

// Click on element in main menu
$mainMenuElement = $this->_rootElement->find(sprintf($this->mainMenu, $mainMenu), Locator::SELECTOR_XPATH);
if (!$mainMenuElement->isVisible()) {
throw new \Exception('Main menu item "' . $mainMenu . '" is not visible.');
}
$mainMenuElement->click();

// Click on element in submenu
if ($subMenu === null) {
return;
}
$subMenuSelector = sprintf($this->subMenu, $mainMenu);
$this->waitForElementVisible($subMenuSelector, Locator::SELECTOR_XPATH);
$subMenuItem = $this->_rootElement->find($subMenuSelector, Locator::SELECTOR_XPATH)
->find(sprintf($this->subMenuItem, $subMenu), Locator::SELECTOR_XPATH);
if (!$subMenuItem->isVisible()) {
throw new \Exception('Submenu item "' . $subMenu . '" is not visible in "' . $mainMenu . '"');
}
$subMenuItem->click();
$this->waitForElementNotVisible($subMenuSelector, Locator::SELECTOR_XPATH);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Backend\Test\Block\Page;

use Magento\Mtf\Block\Block;

/**
* 404 error backend block.
*/
class Error extends Block
{
/**
* Get block text content.
*
* @return string
*/
public function getContent()
{
return $this->_rootElement->getText();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Magento\Mtf\Block\Block;

/**
* Main block.
* Main dashboard block.
*/
class Main extends Block
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Backend\Test\Constraint;

use Magento\Backend\Test\Fixture\GlobalSearch;
use Magento\Backend\Test\Page\Adminhtml\Dashboard;
use Magento\Mtf\Constraint\AbstractConstraint;

/**
* Assert backend page title and it's availability.
*/
class AssertBackendPageIsAvailable extends AbstractConstraint
{
const ERROR_TEXT = '404 Error';

/**
* Assert that backend page has correct title and 404 Error is absent on the page.
*
* @param Dashboard $dashboard
* @param string $pageTitle
* @return void
*/
public function processAssert(Dashboard $dashboard, $pageTitle)
{
\PHPUnit_Framework_Assert::assertEquals(
$pageTitle,
$dashboard->getTitleBlock()->getTitle(),
'Invalid page title is displayed.'
);
\PHPUnit_Framework_Assert::assertNotContains(
self::ERROR_TEXT,
$dashboard->getErrorBlock()->getContent(),
"404 Error is displayed on '$pageTitle' page."
);
}

/**
* Returns a string representation of the object.
*
* @return string
*/
public function toString()
{
return 'Backend has correct title and 404 page content is absent.';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Backend\Test\Constraint;

use Magento\Store\Test\Fixture\Store;
use Magento\Mtf\Constraint\AbstractConstraint;
use Magento\Backend\Test\Page\Adminhtml\SystemConfig;
use Magento\Cms\Test\Page\CmsIndex;

/**
* Assert that store can be localized.
*/
class AssertStoreCanBeLocalized extends AbstractConstraint
{
/**
* Assert that locale options can be changed and checks new text on index page.
*
* @param SystemConfig $systemConfig
* @param Store $store
* @param CmsIndex $cmsIndex
* @param string $locale
* @param string $welcomeText
* @return void
*/
public function processAssert(SystemConfig $systemConfig, Store $store, CmsIndex $cmsIndex, $locale, $welcomeText)
{
// Set locale options
$systemConfig->open();
$systemConfig->getPageActions()->selectStore($store->getGroupId() . "/" . $store->getName());
$configGroup = $systemConfig->getForm()->getGroup('Locale Options');
$configGroup->open();
$configGroup->setValue('select-groups-locale-fields-code-value', $locale);
$systemConfig->getPageActions()->save();
$systemConfig->getMessagesBlock()->waitSuccessMessage();

// Check presents income text on index page
$cmsIndex->open();
$cmsIndex->getStoreSwitcherBlock()->selectStoreView($store->getName());

\PHPUnit_Framework_Assert::assertTrue(
$cmsIndex->getSearchBlock()->isPlaceholderContains($welcomeText),
"Locale not applied."
);
}

/**
* Returns a string representation of the object.
*
* @return string
*/
public function toString()
{
return 'Store locale has changed successfully.';
}
}
Loading

0 comments on commit e673fcf

Please sign in to comment.