Skip to content

Commit 7c9ca2f

Browse files
committed
[Captcha] Cover Model Config by Unit Test
1 parent 36ea828 commit 7c9ca2f

File tree

3 files changed

+299
-0
lines changed

3 files changed

+299
-0
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Captcha\Test\Unit\Model\Config;
10+
use PHPUnit\Framework\TestCase;
11+
use Magento\Captcha\Helper\Data as HelperData;
12+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
13+
use Magento\Captcha\Model\Config\Font;
14+
15+
class FontTest extends TestCase
16+
{
17+
/**
18+
* @var ObjectManagerHelper
19+
*/
20+
private $objectManagerHelper;
21+
22+
/**
23+
* @var Font
24+
*/
25+
private $model;
26+
27+
/**
28+
* @var HelperData|\PHPUnit_Framework_MockObject_MockObject
29+
*/
30+
private $helperDataMock;
31+
32+
/**
33+
* Setup Environment For Testing
34+
*/
35+
protected function setUp()
36+
{
37+
$this->helperDataMock = $this->createMock(HelperData::class);
38+
39+
$this->objectManagerHelper = new ObjectManagerHelper($this);
40+
41+
$this->model = $this->objectManagerHelper->getObject(
42+
Font::class,
43+
[
44+
'captchaData' => $this->helperDataMock
45+
]
46+
);
47+
}
48+
49+
/**
50+
* Test toOptionArray() with data provider below
51+
*
52+
* @param array $fonts
53+
* @param array $expectedResult
54+
* @dataProvider toOptionArrayDataProvider
55+
*/
56+
public function testToOptionArray($fonts, $expectedResult)
57+
{
58+
$this->helperDataMock->expects($this->any())->method('getFonts')
59+
->willReturn($fonts);
60+
61+
$this->assertEquals($expectedResult, $this->model->toOptionArray());
62+
}
63+
64+
/**
65+
* Data Provider for testing toOptionArray()
66+
*
67+
* @return array
68+
*/
69+
public function toOptionArrayDataProvider()
70+
{
71+
return [
72+
'Empty get font' => [
73+
[],
74+
[]
75+
],
76+
'Get font result' => [
77+
[
78+
'arial' => [
79+
'label' => 'Arial',
80+
'path' => '/www/magento/fonts/arial.ttf'
81+
],
82+
'verdana' => [
83+
'label' => 'Verdana',
84+
'path' => '/www/magento/fonts/verdana.ttf'
85+
]
86+
],
87+
[
88+
[
89+
'label' => 'Arial',
90+
'value' => 'arial'
91+
],
92+
[
93+
'label' => 'Verdana',
94+
'value' => 'verdana'
95+
]
96+
]
97+
]
98+
];
99+
}
100+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Captcha\Test\Unit\Model\Config\Form;
10+
11+
use Magento\Captcha\Model\Config\Form\Backend;
12+
use PHPUnit\Framework\TestCase;
13+
use Magento\Framework\App\Config\ScopeConfigInterface;
14+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
15+
16+
class BackendTest extends TestCase
17+
{
18+
/**
19+
* @var ObjectManagerHelper
20+
*/
21+
private $objectManagerHelper;
22+
23+
/**
24+
* @var Backend
25+
*/
26+
private $model;
27+
28+
/**
29+
* @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
30+
*/
31+
private $configMock;
32+
33+
/**
34+
* Setup Environment For Testing
35+
*/
36+
protected function setUp()
37+
{
38+
$this->configMock = $this->createMock(ScopeConfigInterface::class);
39+
40+
$this->objectManagerHelper = new ObjectManagerHelper($this);
41+
42+
$this->model = $this->objectManagerHelper->getObject(
43+
Backend::class,
44+
[
45+
'config' => $this->configMock
46+
]
47+
);
48+
}
49+
50+
/**
51+
* Test toOptionArray() with data provider below
52+
*
53+
* @param string|array $config
54+
* @param array $expectedResult
55+
* @dataProvider toOptionArrayDataProvider
56+
*/
57+
public function testToOptionArray($config, $expectedResult)
58+
{
59+
$this->configMock->expects($this->any())->method('getValue')
60+
->with('captcha/backend/areas', 'default')
61+
->willReturn($config);
62+
63+
$this->assertEquals($expectedResult, $this->model->toOptionArray());
64+
}
65+
66+
/**
67+
* Data Provider for testing toOptionArray()
68+
*
69+
* @return array
70+
*/
71+
public function toOptionArrayDataProvider()
72+
{
73+
return [
74+
'Empty captcha backend areas' => [
75+
'',
76+
[]
77+
],
78+
'With two captcha backend area' => [
79+
[
80+
'backend_login' => [
81+
'label' => 'Admin Login'
82+
],
83+
'backend_forgotpassword' => [
84+
'label' => 'Admin Forgot Password'
85+
]
86+
],
87+
[
88+
[
89+
'label' => 'Admin Login',
90+
'value' => 'backend_login'
91+
],
92+
[
93+
'label' => 'Admin Forgot Password',
94+
'value' => 'backend_forgotpassword'
95+
]
96+
]
97+
]
98+
];
99+
}
100+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Captcha\Test\Unit\Model\Config\Form;
10+
use Magento\Captcha\Model\Config\Form\Frontend;
11+
use PHPUnit\Framework\TestCase;
12+
use Magento\Framework\App\Config\ScopeConfigInterface;
13+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
14+
15+
class FrontendTest extends TestCase
16+
{
17+
/**
18+
* @var ObjectManagerHelper
19+
*/
20+
private $objectManagerHelper;
21+
22+
/**
23+
* @var Frontend
24+
*/
25+
private $model;
26+
27+
/**
28+
* @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
29+
*/
30+
private $configMock;
31+
32+
/**
33+
* Setup Environment For Testing
34+
*/
35+
protected function setUp()
36+
{
37+
$this->configMock = $this->createMock(ScopeConfigInterface::class);
38+
39+
$this->objectManagerHelper = new ObjectManagerHelper($this);
40+
41+
$this->model = $this->objectManagerHelper->getObject(
42+
Frontend::class,
43+
[
44+
'config' => $this->configMock
45+
]
46+
);
47+
}
48+
49+
/**
50+
* Test toOptionArray() with data provider below
51+
*
52+
* @param string|array $config
53+
* @param array $expectedResult
54+
* @dataProvider toOptionArrayDataProvider
55+
*/
56+
public function testToOptionArray($config, $expectedResult)
57+
{
58+
$this->configMock->expects($this->any())->method('getValue')
59+
->with('captcha/frontend/areas', 'default')
60+
->willReturn($config);
61+
62+
$this->assertEquals($expectedResult, $this->model->toOptionArray());
63+
}
64+
65+
/**
66+
* Data Provider for testing toOptionArray()
67+
*
68+
* @return array
69+
*/
70+
public function toOptionArrayDataProvider()
71+
{
72+
return [
73+
'Empty captcha frontend areas' => [
74+
'',
75+
[]
76+
],
77+
'With two captcha frontend area' => [
78+
[
79+
'product_sendtofriend_form' => [
80+
'label' => 'Send To Friend Form'
81+
],
82+
'sales_rule_coupon_request' => [
83+
'label' => 'Applying coupon code'
84+
]
85+
],
86+
[
87+
[
88+
'label' => 'Send To Friend Form',
89+
'value' => 'product_sendtofriend_form'
90+
],
91+
[
92+
'label' => 'Applying coupon code',
93+
'value' => 'sales_rule_coupon_request'
94+
]
95+
]
96+
]
97+
];
98+
}
99+
}

0 commit comments

Comments
 (0)