Skip to content

Commit 0afddc2

Browse files
committed
Unit Test with data provider
1 parent 035bfaf commit 0afddc2

File tree

1 file changed

+81
-68
lines changed

1 file changed

+81
-68
lines changed

app/code/Magento/Persistent/Test/Unit/Helper/SessionTest.php

Lines changed: 81 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -90,98 +90,111 @@ protected function setUp()
9090
->getMock();
9191
}
9292

93-
/***
94-
* Test isPersistent() when the session has id and enable persistent
95-
*/
96-
public function testIsPersistentWhenSessionId()
97-
{
98-
$this->session->expects($this->any())->method('getId')
99-
->willReturn(1);
100-
$this->helper->expects($this->any())->method('getSession')
101-
->willReturn($this->session);
102-
$this->dataHelper->expects($this->any())->method('isEnabled')
103-
->willReturn(true);
104-
105-
$this->assertEquals(true, $this->helper->isPersistent());
106-
}
107-
108-
/***
109-
* Test isPersistent() when the no session id and enable persistent
93+
/**
94+
* Test isPersistent() function
95+
*
96+
* @param int|null $id
97+
* @param boolean $isEnabled
98+
* @param boolean $expected
99+
* @dataProvider isPersistentDataProvider
110100
*/
111-
public function testIsPersistentWhenNoSessionId()
101+
public function testIsPersistent($id, $isEnabled, $expected)
112102
{
113103
$this->session->expects($this->any())->method('getId')
114-
->willReturn(null);
104+
->willReturn($id);
115105
$this->helper->expects($this->any())->method('getSession')
116106
->willReturn($this->session);
117107
$this->dataHelper->expects($this->any())->method('isEnabled')
118-
->willReturn(true);
108+
->willReturn($isEnabled);
119109

120-
$this->assertEquals(false, $this->helper->isPersistent());
110+
$this->assertEquals($expected, $this->helper->isPersistent());
121111
}
122112

123113
/**
124-
* Test isRememberMeChecked() when enable all config
114+
* Data Provider for test isPersistent()
115+
*
116+
* @return array
125117
*/
126-
public function testIsRememberMeCheckedWhenEnabledAll()
118+
public function isPersistentDataProvider()
127119
{
128-
$testCase = [
129-
'dataset' => [
130-
'enabled' => true,
131-
'remember_me_enabled' => true,
132-
'remember_me_checked_default' => true
120+
return [
121+
'session_id_and_enable_persistent' => [
122+
1,
123+
true,
124+
true
133125
],
134-
'expected' => true
126+
'no_session_id_and_enable_persistent' => [
127+
null,
128+
true,
129+
false
130+
]
135131
];
136-
$this->executeTestIsRememberMeChecked($testCase);
137132
}
138133

139134
/**
140-
* Test isRememberMeChecked() when config persistent is disabled
135+
* Test isRememberMeChecked() function
136+
*
137+
* @param boolean|null $checked
138+
* @param boolean $isEnabled
139+
* @param boolean $isRememberMeEnabled
140+
* @param boolean $isRememberMeCheckedDefault
141+
* @param boolean $expected
142+
* @dataProvider isRememberMeCheckedProvider
141143
*/
142-
public function testIsRememberMeCheckedWhenAtLeastOnceDisabled()
143-
{
144-
$testCase = [
145-
'dataset' => [
146-
'enabled' => false,
147-
'remember_me_enabled' => true,
148-
'remember_me_checked_default' => true
149-
],
150-
'expected' => false
151-
];
152-
$this->executeTestIsRememberMeChecked($testCase);
153-
}
144+
public function testIsRememberMeChecked(
145+
$checked,
146+
$isEnabled,
147+
$isRememberMeEnabled,
148+
$isRememberMeCheckedDefault,
149+
$expected
150+
) {
151+
$this->helper->setRememberMeChecked($checked);
152+
$this->dataHelper->expects($this->any())->method('isEnabled')
153+
->willReturn($isEnabled);
154+
$this->dataHelper->expects($this->any())->method('isRememberMeEnabled')
155+
->willReturn($isRememberMeEnabled);
156+
$this->dataHelper->expects($this->any())->method('isRememberMeCheckedDefault')
157+
->willReturn($isRememberMeCheckedDefault);
154158

155-
/**
156-
* Test isRememberMeChecked() when setRememberMeChecked(false)
157-
*/
158-
public function testIsRememberMeCheckedWhenSetValue()
159-
{
160-
$testCase = [
161-
'dataset' => [
162-
'enabled' => true,
163-
'remember_me_enabled' => true,
164-
'remember_me_checked_default' => true
165-
],
166-
'expected' => false
167-
];
168-
$this->helper->setRememberMeChecked(false);
169-
$this->executeTestIsRememberMeChecked($testCase);
159+
$this->assertEquals($expected, $this->helper->isRememberMeChecked());
170160
}
171161

172162
/**
173-
* Execute test isRememberMeChecked() function
163+
* Data Provider for test isRememberMeChecked()
174164
*
175-
* @param array $testCase
165+
* @return array
176166
*/
177-
public function executeTestIsRememberMeChecked($testCase)
167+
public function isRememberMeCheckedProvider()
178168
{
179-
$this->dataHelper->expects($this->any())->method('isEnabled')
180-
->willReturn($testCase['dataset']['enabled']);
181-
$this->dataHelper->expects($this->any())->method('isRememberMeEnabled')
182-
->willReturn($testCase['dataset']['remember_me_enabled']);
183-
$this->dataHelper->expects($this->any())->method('isRememberMeCheckedDefault')
184-
->willReturn($testCase['dataset']['remember_me_checked_default']);
185-
$this->assertEquals($testCase['expected'], $this->helper->isRememberMeChecked());
169+
return [
170+
'enable_all_config' => [
171+
null,
172+
true,
173+
true,
174+
true,
175+
true
176+
],
177+
'at_least_once_disabled' => [
178+
null,
179+
false,
180+
true,
181+
true,
182+
false
183+
],
184+
'set_remember_me_checked_false' => [
185+
false,
186+
true,
187+
true,
188+
true,
189+
false
190+
],
191+
'set_remember_me_checked_true' => [
192+
true,
193+
false,
194+
true,
195+
true,
196+
true
197+
]
198+
];
186199
}
187200
}

0 commit comments

Comments
 (0)