Skip to content

Commit 3f84bd1

Browse files
committed
added integration test
1 parent 05de33c commit 3f84bd1

File tree

3 files changed

+111
-7
lines changed

3 files changed

+111
-7
lines changed

app/code/Magento/Backend/Model/Search/Config/Result/Builder.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
*/
1515
class Builder
1616
{
17-
const STRUCTURE_ELEMENT_TYPE_SECTION = 'section';
18-
const STRUCTURE_ELEMENT_TYPE_GROUP = 'group';
19-
const STRUCTURE_ELEMENT_TYPE_FIELD = 'field';
20-
2117
/**
2218
* @var array
2319
*/
@@ -71,9 +67,9 @@ public function add(ElementNewInterface $structureElement, $elementPathLabel)
7167
}
7268

7369
$this->results[] = [
74-
'id' => md5($structureElement->getPath()),
70+
'id' => $structureElement->getPath(),
7571
'type' => null,
76-
'name' => $structureElement->getLabel(),
72+
'name' => (string)$structureElement->getLabel(),
7773
'description' => $elementPathLabel,
7874
'url' => $this->urlBuilder->getUrl('*/system_config/edit', $urlParams),
7975
];

app/code/Magento/Backend/Test/Unit/Model/Search/Config/Result/BuilderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function testAddWithSupportedStructureElements()
6060

6161
$expectedSearchResult = [
6262
[
63-
'id' => md5($structureElementPath),
63+
'id' => $structureElementPath,
6464
'type' => null,
6565
'name' => 'Section Label',
6666
'description' => 'Section Label',
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Backend\Model\Search;
8+
9+
use Magento\TestFramework\Helper\Bootstrap;
10+
11+
/**
12+
* @magentoAppArea adminhtml
13+
*/
14+
class ConfigTest extends \PHPUnit\Framework\TestCase
15+
{
16+
/**
17+
* @dataProvider loadDataProvider
18+
*/
19+
public function testLoad($query, $expectedResult)
20+
{
21+
/** Preconditions */
22+
$objectManager = Bootstrap::getObjectManager();
23+
/** @var \Magento\Backend\Model\Search\Config $configSearch */
24+
$configSearch = $objectManager->create(\Magento\Backend\Model\Search\Config::class);
25+
$configSearch->setQuery($query);
26+
$configSearch->load();
27+
28+
/** SUT Execution */
29+
$searchResults = $configSearch->getResults();
30+
31+
/** Ensure that search results are correct */
32+
$this->assertCount(count($expectedResult), $searchResults, 'Quantity of search result items is invalid.');
33+
foreach ($expectedResult as $itemIndex => $expectedItem) {
34+
/** Validate URL to item */
35+
$elementPathParts = explode('/', $expectedItem['id']);
36+
array_filter($elementPathParts, function($value) { return $value !== ''; });
37+
foreach ($elementPathParts as $elementPathPart) {
38+
$this->assertContains($elementPathPart, $searchResults[$itemIndex]['url'], 'Item URL is invalid.');
39+
}
40+
unset($searchResults[$itemIndex]['url']);
41+
42+
/** Validate other item data */
43+
$this->assertEquals($expectedItem, $searchResults[$itemIndex], "Data of item #$itemIndex is invalid.");
44+
}
45+
}
46+
47+
public static function loadDataProvider()
48+
{
49+
return [
50+
'Search by field name' => [
51+
'Store Name',
52+
[
53+
[
54+
'id' => 'general/store_information/name',
55+
'type' => null,
56+
'name' => 'Store Name',
57+
'description' => '/ General / General / Store Information',
58+
],
59+
],
60+
],
61+
'Search by field name, multiple items result' => [
62+
'Secure Base URL',
63+
[
64+
[
65+
'id' => 'web/secure/base_url',
66+
'type' => null,
67+
'name' => 'Secure Base URL',
68+
'description' => '/ General / Web / Base URLs (Secure)',
69+
],
70+
[
71+
'id' => 'web/secure/base_static_url',
72+
'type' => null,
73+
'name' => 'Secure Base URL for Static View Files',
74+
'description' => '/ General / Web / Base URLs (Secure)',
75+
],
76+
[
77+
'id' => 'web/secure/base_media_url',
78+
'type' => null,
79+
'name' => 'Secure Base URL for User Media Files',
80+
'description' => '/ General / Web / Base URLs (Secure)',
81+
],
82+
],
83+
],
84+
'Search by group name' => [
85+
'Country Options',
86+
[
87+
[
88+
'id' => 'general/country',
89+
'type' => null,
90+
'name' => 'Country Options',
91+
'description' => '/ General / General',
92+
],
93+
],
94+
],
95+
'Search by section name' => [
96+
'Currency Setup',
97+
[
98+
[
99+
'id' => '/currency',
100+
'type' => null,
101+
'name' => 'Currency Setup',
102+
'description' => '/ General',
103+
],
104+
],
105+
],
106+
];
107+
}
108+
}

0 commit comments

Comments
 (0)