diff --git a/app/code/Magento/CatalogUrlRewriteGraphQl/Model/Resolver/CategoryUrlSuffix.php b/app/code/Magento/CatalogUrlRewriteGraphQl/Model/Resolver/CategoryUrlSuffix.php index 59708d90c23b7..a6aa4bdfa5d32 100644 --- a/app/code/Magento/CatalogUrlRewriteGraphQl/Model/Resolver/CategoryUrlSuffix.php +++ b/app/code/Magento/CatalogUrlRewriteGraphQl/Model/Resolver/CategoryUrlSuffix.php @@ -75,7 +75,7 @@ private function getCategoryUrlSuffix(int $storeId): string self::$xml_path_category_url_suffix, ScopeInterface::SCOPE_STORE, $storeId - ); + ) ?? ''; } return $this->categoryUrlSuffix[$storeId]; } diff --git a/app/code/Magento/CatalogUrlRewriteGraphQl/Model/Resolver/ProductUrlSuffix.php b/app/code/Magento/CatalogUrlRewriteGraphQl/Model/Resolver/ProductUrlSuffix.php index 9a0193ba36367..ac4c48b0ed5b7 100644 --- a/app/code/Magento/CatalogUrlRewriteGraphQl/Model/Resolver/ProductUrlSuffix.php +++ b/app/code/Magento/CatalogUrlRewriteGraphQl/Model/Resolver/ProductUrlSuffix.php @@ -75,7 +75,7 @@ private function getProductUrlSuffix(int $storeId): string self::$xml_path_product_url_suffix, ScopeInterface::SCOPE_STORE, $storeId - ); + ) ?? ''; } return $this->productUrlSuffix[$storeId]; } diff --git a/app/code/Magento/CatalogUrlRewriteGraphQl/Test/Unit/Model/Resolver/CategoryUrlSuffixTest.php b/app/code/Magento/CatalogUrlRewriteGraphQl/Test/Unit/Model/Resolver/CategoryUrlSuffixTest.php new file mode 100644 index 0000000000000..1d8cb6a391064 --- /dev/null +++ b/app/code/Magento/CatalogUrlRewriteGraphQl/Test/Unit/Model/Resolver/CategoryUrlSuffixTest.php @@ -0,0 +1,173 @@ +contextMock = $this->getMockBuilder(ContextInterface::class) + ->disableOriginalConstructor() + ->setMethods( + [ + 'getExtensionAttributes' + ] + ) + ->getMockForAbstractClass(); + + $this->contextExtensionMock = $this->getMockBuilder(ContextExtensionInterface::class) + ->setMethods( + [ + 'getStore' + ] + ) + ->getMockForAbstractClass(); + + $this->storeMock = $this->getMockBuilder(StoreInterface::class) + ->setMethods( + [ + 'getId' + ] + ) + ->getMockForAbstractClass(); + + $this->fieldMock = $this->getMockBuilder(Field::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->resolveInfoMock = $this->getMockBuilder(ResolveInfo::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class) + ->getMockForAbstractClass(); + + $this->resolver = new CategoryUrlSuffix( + $this->scopeConfigMock + ); + } + + /** + * Verify that empty string is returned when config value is null + */ + public function testNullValue() + { + $this->scopeConfigMock->expects($this->once()) + ->method('getValue') + ->willReturn(null); + + $this->contextMock + ->expects($this->once()) + ->method('getExtensionAttributes') + ->willReturn($this->contextExtensionMock); + + $this->contextExtensionMock + ->expects($this->once()) + ->method('getStore') + ->willReturn($this->storeMock); + + $this->storeMock + ->expects($this->once()) + ->method('getId') + ->willReturn(1); + + $this->assertEquals( + '', + $this->resolver->resolve( + $this->fieldMock, + $this->contextMock, + $this->resolveInfoMock + ) + ); + } + + /** + * Verify that the configured value is returned + */ + public function testNonNullValue() + { + $value = 'html'; + $this->scopeConfigMock->expects($this->once()) + ->method('getValue') + ->willReturn($value); + + $this->contextMock + ->expects($this->once()) + ->method('getExtensionAttributes') + ->willReturn($this->contextExtensionMock); + + $this->contextExtensionMock + ->expects($this->once()) + ->method('getStore') + ->willReturn($this->storeMock); + + $this->storeMock + ->expects($this->once()) + ->method('getId') + ->willReturn(1); + + $this->assertEquals( + $value, + $this->resolver->resolve( + $this->fieldMock, + $this->contextMock, + $this->resolveInfoMock + ) + ); + } +} diff --git a/app/code/Magento/CatalogUrlRewriteGraphQl/Test/Unit/Model/Resolver/ProductUrlSuffixTest.php b/app/code/Magento/CatalogUrlRewriteGraphQl/Test/Unit/Model/Resolver/ProductUrlSuffixTest.php new file mode 100644 index 0000000000000..e133ff8dc5855 --- /dev/null +++ b/app/code/Magento/CatalogUrlRewriteGraphQl/Test/Unit/Model/Resolver/ProductUrlSuffixTest.php @@ -0,0 +1,173 @@ +contextMock = $this->getMockBuilder(ContextInterface::class) + ->disableOriginalConstructor() + ->setMethods( + [ + 'getExtensionAttributes' + ] + ) + ->getMockForAbstractClass(); + + $this->contextExtensionMock = $this->getMockBuilder(ContextExtensionInterface::class) + ->setMethods( + [ + 'getStore' + ] + ) + ->getMockForAbstractClass(); + + $this->storeMock = $this->getMockBuilder(StoreInterface::class) + ->setMethods( + [ + 'getId' + ] + ) + ->getMockForAbstractClass(); + + $this->fieldMock = $this->getMockBuilder(Field::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->resolveInfoMock = $this->getMockBuilder(ResolveInfo::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class) + ->getMockForAbstractClass(); + + $this->resolver = new ProductUrlSuffix( + $this->scopeConfigMock + ); + } + + /** + * Verify that empty string is returned when config value is null + */ + public function testNullValue() + { + $this->scopeConfigMock->expects($this->once()) + ->method('getValue') + ->willReturn(null); + + $this->contextMock + ->expects($this->once()) + ->method('getExtensionAttributes') + ->willReturn($this->contextExtensionMock); + + $this->contextExtensionMock + ->expects($this->once()) + ->method('getStore') + ->willReturn($this->storeMock); + + $this->storeMock + ->expects($this->once()) + ->method('getId') + ->willReturn(1); + + $this->assertEquals( + '', + $this->resolver->resolve( + $this->fieldMock, + $this->contextMock, + $this->resolveInfoMock + ) + ); + } + + /** + * Verify that the configured value is returned + */ + public function testNonNullValue() + { + $value = 'html'; + $this->scopeConfigMock->expects($this->once()) + ->method('getValue') + ->willReturn($value); + + $this->contextMock + ->expects($this->once()) + ->method('getExtensionAttributes') + ->willReturn($this->contextExtensionMock); + + $this->contextExtensionMock + ->expects($this->once()) + ->method('getStore') + ->willReturn($this->storeMock); + + $this->storeMock + ->expects($this->once()) + ->method('getId') + ->willReturn(1); + + $this->assertEquals( + $value, + $this->resolver->resolve( + $this->fieldMock, + $this->contextMock, + $this->resolveInfoMock + ) + ); + } +}