Skip to content

Commit b2a7430

Browse files
author
Joan He
committed
MAGETWO-47952: Added expire admin session functional test.
1 parent 01141f4 commit b2a7430

File tree

5 files changed

+199
-1
lines changed

5 files changed

+199
-1
lines changed

dev/tests/functional/tests/app/Magento/Backend/Test/Block/System/Config/Form/Group.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,45 @@ public function setValue($tabName, $groupName, $fieldName, $value)
7676
$element->setValue($value);
7777
}
7878

79+
/**
80+
* Set store configuration value by element data-ui-id.
81+
*
82+
* @param string $tabName
83+
* @param string $groupName
84+
* @param string $fieldName
85+
* @return array/string
86+
*/
87+
public function getValue($tabName, $groupName, $fieldName)
88+
{
89+
$input = null;
90+
$attribute = $this->_rootElement->find(
91+
sprintf($this->field, $tabName, $groupName, $fieldName),
92+
Locator::SELECTOR_CSS
93+
)->getAttribute('data-ui-id');
94+
95+
$parts = explode('-', $attribute, 2);
96+
if (in_array($parts[0], ['select', 'text', 'checkbox'])) {
97+
$input = $parts[0];
98+
}
99+
100+
$element = $this->_rootElement->find(
101+
sprintf($this->field, $tabName, $groupName, $fieldName),
102+
Locator::SELECTOR_CSS,
103+
$input
104+
);
105+
106+
if ($element->isDisabled()) {
107+
$checkbox = $this->_rootElement->find(
108+
sprintf($this->defaultCheckbox, $tabName, $groupName, $fieldName),
109+
Locator::SELECTOR_CSS,
110+
'checkbox'
111+
);
112+
$checkbox->setValue('No');
113+
}
114+
115+
return $element->getValue();
116+
}
117+
79118
/**
80119
* Check if a field is visible in a given group.
81120
*
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Backend\Test\Constraint;
8+
9+
use Magento\Mtf\Constraint\AbstractConstraint;
10+
use Magento\Backend\Test\Page\AdminAuthLogin;
11+
12+
/**
13+
* Assert that AdminAuthLogin page is present as the result of an expired admin session.
14+
*/
15+
class AssertAdminLoginPageIsAvailable extends AbstractConstraint
16+
{
17+
/**
18+
* Assert that AdminAuthLogin page is present as the result of an expired admin session.
19+
*
20+
* @param AdminAuthLogin $adminAuthLogin
21+
* @return void
22+
*/
23+
public function processAssert(AdminAuthLogin $adminAuthLogin)
24+
{
25+
\PHPUnit_Framework_Assert::assertTrue(
26+
$adminAuthLogin->getLoginBlock()->isVisible(),
27+
'Admin session does not expire properly.'
28+
);
29+
}
30+
31+
/**
32+
* Returns a string representation of the object.
33+
*
34+
* @return string
35+
*/
36+
public function toString()
37+
{
38+
return 'Admin session expires properly.';
39+
}
40+
}

dev/tests/functional/tests/app/Magento/Backend/Test/Repository/ConfigData.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<!--
33
/**
4-
* Copyright © 2015 Magento. All rights reserved.
4+
* Copyright © 2016 Magento. All rights reserved.
55
* See COPYING.txt for license details.
66
*/
77
-->
@@ -123,6 +123,14 @@
123123
<item name="value" xsi:type="number">3600</item>
124124
</field>
125125
</dataset>
126+
<dataset name="admin_session_lifetime_60_seconds">
127+
<field name="admin/security/session_lifetime" xsi:type="array">
128+
<item name="scope" xsi:type="string">default</item>
129+
<item name="scope_id" xsi:type="number">0</item>
130+
<item name="label" xsi:type="number">60</item>
131+
<item name="value" xsi:type="number">60</item>
132+
</field>
133+
</dataset>
126134

127135
<dataset name="secret_key_disable">
128136
<field name="admin/security/use_form_key" xsi:type="array">
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Backend\Test\TestCase;
8+
9+
use Magento\Backend\Test\Page\Adminhtml\SystemConfigEdit;
10+
use Magento\Config\Test\Fixture\ConfigData;
11+
use Magento\Mtf\TestCase\Injectable;
12+
13+
/**
14+
* Steps:
15+
*
16+
* 1. Login to backend.
17+
* 2. Go to Stores -> Configuration -> Advanced -> Admin.
18+
* 3. Open "Security" group.
19+
* 4. Save old session lifetime value for "Admin Session Lifetime (seconds)".
20+
* 5. Set new session lifetime value for "Admin Session Lifetime (seconds)".
21+
* 6. Wait for session to expire.
22+
* 7. Go to Stores -> Configuration.
23+
* 8. Perform asserts.
24+
* 9. Restore old session lifetime value after test is done.
25+
*
26+
* @ZephyrId MAGETWO-47723
27+
*/
28+
class ExpireAdminSessionTest extends Injectable
29+
{
30+
/* tags */
31+
const MVP = 'no';
32+
const DOMAIN = 'PS';
33+
/* end tags */
34+
35+
protected $systemConfigEdit;
36+
37+
protected $sessionLifetimeConfig;
38+
39+
protected $oldValue;
40+
41+
/**
42+
* Open backend system config.
43+
* Save default configuration value.
44+
* Set new configuration value.
45+
* Reopen backend system config.
46+
*
47+
* @param SystemConfigEdit $systemConfigEdit
48+
* @param ConfigData $sessionLifetimeConfig
49+
* @return void
50+
*/
51+
public function test(SystemConfigEdit $systemConfigEdit, ConfigData $sessionLifetimeConfig)
52+
{
53+
$this->systemConfigEdit = $systemConfigEdit;
54+
$this->sessionLifetimeConfig = $sessionLifetimeConfig;
55+
$this->systemConfigEdit->open();
56+
$section = $sessionLifetimeConfig->getSection();
57+
$keys = array_keys($section);
58+
$parts = explode('/', $keys[0], 3);
59+
$tabName = $parts[0];
60+
$groupName = $parts[1];
61+
$fieldName = $parts[2];
62+
$this->oldValue = $this->systemConfigEdit->getForm()->getGroup($tabName, $groupName)
63+
->getValue($tabName, $groupName, $fieldName);
64+
$this->systemConfigEdit->getForm()->getGroup($tabName, $groupName)
65+
->setValue($tabName, $groupName, $fieldName, $section[$keys[0]]['label']);
66+
$this->systemConfigEdit->getPageActions()->save();
67+
$this->systemConfigEdit->getMessagesBlock()->waitSuccessMessage();
68+
69+
/**
70+
* Wait admin session to expire.
71+
*/
72+
sleep($section[$keys[0]]['label']);
73+
74+
$this->systemConfigEdit->open();
75+
}
76+
77+
/**
78+
* Tear down after tests.
79+
*
80+
* @return void
81+
*/
82+
public function tearDown()
83+
{
84+
$this->systemConfigEdit->open();
85+
$section = $this->sessionLifetimeConfig->getSection();
86+
$keys = array_keys($section);
87+
$parts = explode('/', $keys[0], 3);
88+
$tabName = $parts[0];
89+
$groupName = $parts[1];
90+
$fieldName = $parts[2];
91+
$this->systemConfigEdit->getForm()->getGroup($tabName, $groupName)
92+
->setValue($tabName, $groupName, $fieldName, $this->oldValue);
93+
$this->systemConfigEdit->getPageActions()->save();
94+
$this->systemConfigEdit->getMessagesBlock()->waitSuccessMessage();
95+
}
96+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
/**
4+
* Copyright © 2015 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd">
9+
<testCase name="Magento\Backend\Test\TestCase\ExpireAdminSessionTest" summary="Admin Session Expire" ticketId="MAGETWO-47723">
10+
<variation name="ExpireAdminSession" summary="Expire Admin Session" ticketId="MAGETWO-47723">
11+
<data name="sessionLifetimeConfig/dataset" xsi:type="string">admin_session_lifetime_60_seconds</data>
12+
<constraint name="Magento\Backend\Test\Constraint\AssertAdminLoginPageIsAvailable"/>
13+
</variation>
14+
</testCase>
15+
</config>

0 commit comments

Comments
 (0)