|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\UpwardConnector\Test\Unit\Magento\Framework\App; |
| 9 | + |
| 10 | +use Magento\Framework\App\Config\ScopeConfigInterface; |
| 11 | +use Magento\UpwardConnector\Plugin\Magento\Framework\App\AreaList as AreaListPlugin; |
| 12 | + |
| 13 | +class AreaListTest extends \PHPUnit\Framework\TestCase |
| 14 | +{ |
| 15 | + /** |
| 16 | + * @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject |
| 17 | + */ |
| 18 | + private $scopeConfig; |
| 19 | + |
| 20 | + /** |
| 21 | + * \Magento\Framework\App\AreaList|\PHPUnit_Framework_MockObject_MockObject |
| 22 | + */ |
| 23 | + private $areaListMock; |
| 24 | + |
| 25 | + /** |
| 26 | + * @var AreaListPlugin |
| 27 | + */ |
| 28 | + private $areaListPlugin; |
| 29 | + |
| 30 | + protected function setUp() |
| 31 | + { |
| 32 | + $this->scopeConfig = $this->createMock(ScopeConfigInterface::class); |
| 33 | + $this->areaListMock = $this->createMock(\Magento\Framework\App\AreaList::class); |
| 34 | + |
| 35 | + $this->scopeConfig->expects($this->any())->method('getValue')->willReturn( |
| 36 | + "foo\r\nbar" |
| 37 | + ); |
| 38 | + |
| 39 | + $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); |
| 40 | + $this->areaListPlugin = $objectManagerHelper->getObject( |
| 41 | + AreaListPlugin::class, |
| 42 | + ['scopeConfig' => $this->scopeConfig] |
| 43 | + ); |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * @param string $resultParam |
| 48 | + * @param string $frontNameParam |
| 49 | + * @param string $expected |
| 50 | + * |
| 51 | + * @dataProvider afterGetCodeByFrontNameDataProvider |
| 52 | + */ |
| 53 | + public function testAfterGetCodeByFrontName(string $resultParam, string $frontNameParam, string $expected) |
| 54 | + { |
| 55 | + $result = $this->areaListPlugin->afterGetCodeByFrontName( |
| 56 | + $this->areaListMock, |
| 57 | + $resultParam, |
| 58 | + $frontNameParam |
| 59 | + ); |
| 60 | + |
| 61 | + $this->assertEquals($expected, $result); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * @return [] |
| 66 | + */ |
| 67 | + public function afterGetCodeByFrontNameDataProvider() |
| 68 | + { |
| 69 | + return [ |
| 70 | + 'Adminhtml area passes through' => ['adminhtml', '', 'adminhtml'], |
| 71 | + 'Frontend area w/o frontname goes to UPWARD' => ['frontend', '', 'pwa'], |
| 72 | + 'Frontend area w/o frontname in whitelist goes to UPWARD' => ['frontend', 'baz', 'pwa'], |
| 73 | + 'Frontend area with frontname in whitelist passes through' => ['frontend', 'foo', 'frontend'] |
| 74 | + ]; |
| 75 | + } |
| 76 | +} |
0 commit comments