1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the ONGR package. |
5
|
|
|
* |
6
|
|
|
* (c) NFQ Technologies UAB <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace ONGR\SettingsBundle\Tests\Functional\Twig; |
13
|
|
|
|
14
|
|
|
use ONGR\ElasticsearchBundle\Test\AbstractElasticsearchTestCase; |
15
|
|
|
use ONGR\SettingsBundle\Exception\SettingNotFoundException; |
16
|
|
|
use ONGR\SettingsBundle\Twig\GeneralSettingsWidgetExtension; |
17
|
|
|
use ONGR\SettingsBundle\Tests\Fixtures\Security\LoginTestHelper; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class used to test GeneralSettingsExtension. |
21
|
|
|
*/ |
22
|
|
|
class GeneralSettingsWidgetExtensionTest extends AbstractElasticsearchTestCase |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var Client |
26
|
|
|
*/ |
27
|
|
|
private $client; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* {@inheritdoc} |
31
|
|
|
*/ |
32
|
|
|
protected function setUp() |
33
|
|
|
{ |
34
|
|
|
parent::setUp(); |
35
|
|
|
$this->client = new LoginTestHelper(static::createClient()); |
|
|
|
|
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Tests if extension is loaded correctly. |
40
|
|
|
*/ |
41
|
|
|
public function testGetExtension() |
42
|
|
|
{ |
43
|
|
|
$container = $this->getContainer(); |
44
|
|
|
/** @var GeneralSettingsWidgetExtension $extension */ |
45
|
|
|
$extension = $container->get('ongr_settings.twig.personal_settings_extension'); |
46
|
|
|
$this->assertInstanceOf( |
47
|
|
|
'ONGR\SettingsBundle\Twig\PersonalSettingWidgetExtension', |
48
|
|
|
$extension, |
49
|
|
|
'extension has wrong instance.' |
50
|
|
|
); |
51
|
|
|
$this->assertNotEmpty($extension->getFunctions(), 'extension does not have functions defined.'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Data provider for testShowSetting. |
56
|
|
|
* |
57
|
|
|
* @return array[] |
58
|
|
|
*/ |
59
|
|
|
public function showSettingData() |
60
|
|
|
{ |
61
|
|
|
// Case #0 not authenticated. |
62
|
|
|
$expectedOutput = '<div></div>'; |
63
|
|
|
$out[] = [$expectedOutput, 'test_count_per_page', false]; |
|
|
|
|
64
|
|
|
|
65
|
|
|
// Case #1 default type (string). |
66
|
|
|
$expectedOutput = '<a href="http://localhost/settings/setting/count_per_page/edit/test" '; |
67
|
|
|
$out[] = [$expectedOutput, 'test_count_per_page', true]; |
68
|
|
|
|
69
|
|
|
return $out; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Test getPriceList(). |
74
|
|
|
* |
75
|
|
|
* @param string $expectedOutput |
76
|
|
|
* @param string $settingId |
77
|
|
|
* @param bool $isAuthenticated |
78
|
|
|
* |
79
|
|
|
* @dataProvider showSettingData |
80
|
|
|
*/ |
81
|
|
|
public function testShowSetting($expectedOutput, $settingId, $isAuthenticated) |
|
|
|
|
82
|
|
|
{ |
83
|
|
|
if ($isAuthenticated) { |
84
|
|
|
$client = static::createClient( |
85
|
|
|
[], |
86
|
|
|
[ |
87
|
|
|
'PHP_AUTH_USER' => 'admin', |
88
|
|
|
'PHP_AUTH_PW' => 'admin', |
89
|
|
|
] |
90
|
|
|
); |
91
|
|
|
} else { |
92
|
|
|
$client = static::createClient(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
$settingTicUrl = 'settings/setting/change/'.base64_encode('ongr_settings_live_settings'); |
96
|
|
|
// Tic the setting |
97
|
|
|
$client->request('GET', $settingTicUrl); |
98
|
|
|
$this->assertTrue($client->getResponse()->isOk()); |
99
|
|
|
|
100
|
|
|
// Call controller with params to generate twig. |
101
|
|
|
$client->request('GET', '/test/twiggeneral'); |
102
|
|
|
|
103
|
|
|
$this->assertContains($expectedOutput, $client->getResponse()->getContent()); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Test for getPersonalSetting() from general settings container. |
108
|
|
|
*/ |
109
|
|
|
public function testGetPersonalSetting() |
110
|
|
|
{ |
111
|
|
|
$expectedValue = 'foo-bar'; |
112
|
|
|
|
113
|
|
|
$settingContainer = $this->getMock('ONGR\SettingsBundle\Settings\General\SettingsContainerInterface'); |
114
|
|
|
$settingContainer->expects($this->once())->method('get')->with('test')->willReturn($expectedValue); |
115
|
|
|
|
116
|
|
|
$extension = new GeneralSettingsWidgetExtension(null); |
|
|
|
|
117
|
|
|
$extension->setSettingsContainer($settingContainer); |
118
|
|
|
|
119
|
|
|
$this->assertEquals($expectedValue, $extension->getPersonalSetting('test')); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Test for getPersonalSetting() from general settings container in case setting was not found. |
124
|
|
|
*/ |
125
|
|
|
public function testGetPersonalSettingException() |
126
|
|
|
{ |
127
|
|
|
$settingContainer = $this->getMock('ONGR\SettingsBundle\Settings\General\SettingsContainerInterface'); |
128
|
|
|
$settingContainer |
129
|
|
|
->expects($this->once()) |
130
|
|
|
->method('get') |
131
|
|
|
->with('test') |
132
|
|
|
->willThrowException(new SettingNotFoundException()); |
133
|
|
|
|
134
|
|
|
$extension = new GeneralSettingsWidgetExtension(null); |
|
|
|
|
135
|
|
|
$extension->setSettingsContainer($settingContainer); |
136
|
|
|
|
137
|
|
|
$this->assertNull($extension->getPersonalSetting('test')); |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..