1111use Magento\Catalog\Model\Product;
1212use Magento\Catalog\Model\Product\Url;
1313use Magento\Catalog\Model\Product\Url as ProductUrl;
14+ use Magento\Framework\App\Config\ScopeConfigInterface;
1415use Magento\Framework\Filter\FilterManager;
1516use Magento\Framework\Session\SidResolverInterface;
1617use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
2122use PHPUnit\Framework\MockObject\MockObject;
2223use PHPUnit\Framework\TestCase;
2324
25+ /**
26+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
27+ */
2428class UrlTest extends TestCase
2529{
2630 /**
@@ -53,6 +57,11 @@ class UrlTest extends TestCase
5357 */
5458 protected $sidResolver;
5559
60+ /**
61+ * @var ScopeConfigInterface
62+ */
63+ private ScopeConfigInterface $scopeConfig;
64+
5665 protected function setUp(): void
5766 {
5867 $this->filter = $this->getMockBuilder(
@@ -86,6 +95,8 @@ protected function setUp(): void
8695 $urlFactory->method('create')
8796 ->willReturn($this->url);
8897
98+ $this->scopeConfig = $this->createMock(ScopeConfigInterface::class);
99+
89100 $objectManager = new ObjectManager($this);
90101 $this->model = $objectManager->getObject(
91102 ProductUrl::class,
@@ -95,11 +106,15 @@ protected function setUp(): void
95106 'storeManager' => $storeManager,
96107 'urlFactory' => $urlFactory,
97108 'sidResolver' => $this->sidResolver,
109+ 'scopeConfig' => $this->scopeConfig
98110 ]
99111 );
100112 }
101113
102- public function testFormatUrlKey()
114+ /**
115+ * @return void
116+ */
117+ public function testFormatUrlKey(): void
103118 {
104119 $strIn = 'Some string';
105120 $resultString = 'some';
@@ -114,6 +129,29 @@ public function testFormatUrlKey()
114129 $resultString
115130 );
116131
132+ $this->scopeConfig->expects($this->once())
133+ ->method('getValue')
134+ ->with(
135+ \Magento\Catalog\Helper\Product::XML_PATH_APPLY_TRANSLITERATION_TO_URL,
136+ \Magento\Store\Model\ScopeInterface::SCOPE_STORE
137+ )->willReturn(true);
138+ $this->assertEquals($resultString, $this->model->formatUrlKey($strIn));
139+ }
140+
141+ /**
142+ * @return void
143+ */
144+ public function testFormatUrlKeyWithoutTransliteration(): void
145+ {
146+ $strIn = 'Some string ';
147+ $resultString = 'some-string';
148+
149+ $this->scopeConfig->expects($this->once())
150+ ->method('getValue')
151+ ->with(
152+ \Magento\Catalog\Helper\Product::XML_PATH_APPLY_TRANSLITERATION_TO_URL,
153+ \Magento\Store\Model\ScopeInterface::SCOPE_STORE
154+ )->willReturn(false);
117155 $this->assertEquals($resultString, $this->model->formatUrlKey($strIn));
118156 }
119157
0 commit comments