6
6
7
7
namespace Magento \Backend \Model \Search ;
8
8
9
+ use Magento \Backend \App \Area \FrontNameResolver ;
10
+ use Magento \Framework \App \Area ;
11
+ use Magento \Framework \App \AreaList ;
12
+ use Magento \Framework \App \Cache \State ;
13
+ use Magento \Framework \App \Config \FileResolver ;
14
+ use Magento \Framework \Config \FileIteratorFactory ;
15
+ use Magento \Framework \Config \ScopeInterface ;
9
16
use Magento \TestFramework \Helper \Bootstrap ;
10
17
11
18
/**
@@ -15,13 +22,12 @@ class ConfigTest extends \PHPUnit\Framework\TestCase
15
22
{
16
23
/**
17
24
* @dataProvider loadDataProvider
25
+ * @magentoConfigFixture current_store general/store_information/name Foo
18
26
*/
19
27
public function testLoad ($ query , $ expectedResult )
20
28
{
21
- /** Preconditions */
22
- $ objectManager = Bootstrap::getObjectManager ();
23
29
/** @var \Magento\Backend\Model\Search\Config $configSearch */
24
- $ configSearch = $ objectManager -> create (\ Magento \ Backend \ Model \ Search \Config::class );
30
+ $ configSearch = $ this -> getConfigSearchInstance ( );
25
31
$ configSearch ->setQuery ($ query );
26
32
$ configSearch ->load ();
27
33
@@ -46,62 +52,93 @@ public function testLoad($query, $expectedResult)
46
52
}
47
53
}
48
54
55
+ /**
56
+ * @return \Magento\Backend\Model\Search\Config
57
+ */
58
+ private function getConfigSearchInstance ()
59
+ {
60
+ Bootstrap::getInstance ()->reinitialize ([
61
+ State::PARAM_BAN_CACHE => true ,
62
+ ]);
63
+ Bootstrap::getObjectManager ()
64
+ ->get (ScopeInterface::class)
65
+ ->setCurrentScope (FrontNameResolver::AREA_CODE );
66
+ Bootstrap::getObjectManager ()->get (AreaList::class)
67
+ ->getArea (FrontNameResolver::AREA_CODE )
68
+ ->load (Area::PART_CONFIG );
69
+
70
+ $ fileResolverMock = $ this ->getMockBuilder (FileResolver::class)->disableOriginalConstructor ()->getMock ();
71
+ $ fileIteratorFactory = Bootstrap::getObjectManager ()->get (FileIteratorFactory::class);
72
+ $ fileIterator = $ fileIteratorFactory ->create (
73
+ [__DIR__ . '/_files/test_config.xml ' ]
74
+ );
75
+ $ fileResolverMock ->expects ($ this ->any ())->method ('get ' )->will ($ this ->returnValue ($ fileIterator ));
76
+
77
+ $ objectManager = Bootstrap::getObjectManager ();
78
+ /** @var \Magento\Config\Model\Config\Structure\Reader $structureReader */
79
+ $ structureReader = $ objectManager ->create (
80
+ \Magento \Config \Model \Config \Structure \Reader::class,
81
+ ['fileResolver ' => $ fileResolverMock ]
82
+ );
83
+ /** @var \Magento\Config\Model\Config\Structure\Data $structureData */
84
+ $ structureData = $ objectManager ->create (
85
+ \Magento \Config \Model \Config \Structure \Data::class,
86
+ ['reader ' => $ structureReader ]
87
+ );
88
+ /** @var \Magento\Config\Model\Config\Structure $structure */
89
+ $ structure = $ objectManager ->create (
90
+ \Magento \Config \Model \Config \Structure::class,
91
+ ['structureData ' => $ structureData ]
92
+ );
93
+
94
+ return $ objectManager ->create (
95
+ \Magento \Backend \Model \Search \Config::class,
96
+ ['configStructure ' => $ structure ]
97
+ );
98
+ }
99
+
100
+ /**
101
+ * @return array
102
+ */
49
103
public static function loadDataProvider ()
50
104
{
51
105
return [
52
106
'Search by field name ' => [
53
- 'Store Name ' ,
54
- [
55
- [
56
- 'id ' => 'general/store_information/name ' ,
57
- 'type ' => null ,
58
- 'name ' => 'Store Name ' ,
59
- 'description ' => '/ General / General / Store Information ' ,
60
- ],
61
- ],
62
- ],
63
- 'Search by field name, multiple items result ' => [
64
- 'Secure Base URL ' ,
107
+ 'Test Field ' ,
65
108
[
66
109
[
67
- 'id ' => 'web/secure/base_url ' ,
68
- 'type ' => null ,
69
- 'name ' => 'Secure Base URL ' ,
70
- 'description ' => '/ General / Web / Base URLs (Secure) ' ,
71
- ],
72
- [
73
- 'id ' => 'web/secure/base_static_url ' ,
110
+ 'id ' => 'test_section/test_group/test_field_1 ' ,
74
111
'type ' => null ,
75
- 'name ' => 'Secure Base URL for Static View Files ' ,
76
- 'description ' => '/ General / Web / Base URLs (Secure) ' ,
112
+ 'name ' => 'Test Field ' ,
113
+ 'description ' => '/ Test Tab / Test Section / Test Group ' ,
77
114
],
78
115
[
79
- 'id ' => 'web/secure/base_media_url ' ,
116
+ 'id ' => 'test_section/test_group/test_field_2 ' ,
80
117
'type ' => null ,
81
- 'name ' => 'Secure Base URL for User Media Files ' ,
82
- 'description ' => '/ General / Web / Base URLs (Secure) ' ,
118
+ 'name ' => 'Test Field ' ,
119
+ 'description ' => '/ Test Tab / Test Section / Test Group ' ,
83
120
],
84
121
],
85
122
],
86
123
'Search by group name ' => [
87
- 'Country Options ' ,
124
+ 'Test Group ' ,
88
125
[
89
126
[
90
- 'id ' => 'general/country ' ,
127
+ 'id ' => 'test_section/test_group ' ,
91
128
'type ' => null ,
92
- 'name ' => 'Country Options ' ,
93
- 'description ' => '/ General / General ' ,
129
+ 'name ' => 'Test Group ' ,
130
+ 'description ' => '/ Test Tab / Test Section ' ,
94
131
],
95
132
],
96
133
],
97
134
'Search by section name ' => [
98
- 'Currency Setup ' ,
135
+ 'Test Section ' ,
99
136
[
100
137
[
101
- 'id ' => '/currency ' ,
138
+ 'id ' => '/test_section ' ,
102
139
'type ' => null ,
103
- 'name ' => 'Currency Setup ' ,
104
- 'description ' => '/ General ' ,
140
+ 'name ' => 'Test Section ' ,
141
+ 'description ' => '/ Test Tab ' ,
105
142
],
106
143
],
107
144
],
0 commit comments