|
17 | 17 | use Magento\Framework\Registry;
|
18 | 18 | use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
|
19 | 19 | use Magento\Framework\View\Asset\MergeService;
|
| 20 | +use Magento\Framework\Validator\Url as UrlValidator; |
| 21 | +use Magento\Framework\App\ObjectManager as AppObjectManager; |
| 22 | +use Magento\Framework\ObjectManagerInterface; |
20 | 23 | use Magento\Store\Model\Store;
|
21 | 24 | use PHPUnit\Framework\TestCase;
|
22 | 25 |
|
| 26 | +/** |
| 27 | + * Test Class BaseurlTest |
| 28 | + * |
| 29 | + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
| 30 | + */ |
23 | 31 | class BaseurlTest extends TestCase
|
24 | 32 | {
|
25 | 33 | public function testSaveMergedJsCssMustBeCleaned()
|
@@ -61,4 +69,51 @@ public function testSaveMergedJsCssMustBeCleaned()
|
61 | 69 | $model->setValue('http://example.com/')->setPath(Store::XML_PATH_UNSECURE_BASE_URL);
|
62 | 70 | $model->afterSave();
|
63 | 71 | }
|
| 72 | + |
| 73 | + /** |
| 74 | + * Test beforeSave method to ensure URL is converted to lower case. |
| 75 | + * |
| 76 | + * @dataProvider beforeSaveDataProvider |
| 77 | + * @param string $value |
| 78 | + * @param string $expectedValue |
| 79 | + * @return void |
| 80 | + */ |
| 81 | + public function testBeforeSaveConvertLowerCase(string $value, string $expectedValue): void |
| 82 | + { |
| 83 | + $model = (new ObjectManager($this))->getObject(Baseurl::class); |
| 84 | + |
| 85 | + $urlValidatorMock = $this->getMockBuilder(UrlValidator::class) |
| 86 | + ->disableOriginalConstructor() |
| 87 | + ->getMock(); |
| 88 | + |
| 89 | + $objectManagerInterface = $this->createMock(ObjectManagerInterface::class); |
| 90 | + $objectManagerInterface->expects($this->exactly(1)) |
| 91 | + ->method('get') |
| 92 | + ->with(UrlValidator::class) |
| 93 | + ->willReturn($urlValidatorMock); |
| 94 | + AppObjectManager::setInstance($objectManagerInterface); |
| 95 | + |
| 96 | + $urlValidatorMock->expects($this->once()) |
| 97 | + ->method('isValid') |
| 98 | + ->with($expectedValue, ['http', 'https']) |
| 99 | + ->willReturn(true); |
| 100 | + |
| 101 | + $model->setValue($value); |
| 102 | + $model->beforeSave(); |
| 103 | + $this->assertEquals($expectedValue, $model->getValue()); |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * Data provider for testBeforeSaveConvertLowerCase. |
| 108 | + * |
| 109 | + * @return array |
| 110 | + */ |
| 111 | + public static function beforeSaveDataProvider(): array |
| 112 | + { |
| 113 | + return [ |
| 114 | + ['https://Example1.com/', 'https://example1.com/'], |
| 115 | + ['https://EXAMPLE2.COM/', 'https://example2.com/'], |
| 116 | + ['HTtpS://ExamPLe3.COM/', 'https://example3.com/'], |
| 117 | + ]; |
| 118 | + } |
64 | 119 | }
|
0 commit comments