|
| 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