Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "swag/swag-extension-store",
"version": "4.0.4",
"version": "4.0.5",
"description": "SWAG Extension Store",
"type": "shopware-platform-plugin",
"license": "MIT",
Expand Down
6 changes: 5 additions & 1 deletion src/Controller/InAppPurchasesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ public function getInAppPurchaseDetails(string $technicalName, Context $context)

$extension = $this->extensionDataProvider
->getInstalledExtensions($context, false, $criteria)
->first();
->get($technicalName);

if (!$extension) {
throw ExtensionStoreException::unknownExtension($technicalName);
}

return new JsonResponse($extension);
}
Expand Down
10 changes: 10 additions & 0 deletions src/Exception/ExtensionStoreException.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,14 @@ public static function invalidInAppPurchase(): self
'The extension provider disallowed your purchase. Please contact the extension provider.',
);
}

public static function unknownExtension(string $technicalName): self
{
return new self(
Response::HTTP_NOT_FOUND,
'FRAMEWORK__UNKNOWN_EXTENSION',
'The extension with technical name "{{ technicalName }}" is not known.',
['technicalName' => $technicalName],
);
}
}
31 changes: 30 additions & 1 deletion tests/Controller/InAppPurchasesControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@ public function testGetInAppFeature(): void
{
$extension = new ExtensionStruct();
$extension->setName('testExtension');
$otherExtension = new ExtensionStruct();
$otherExtension->setName('otherExtension');
$service = $this->createMock(InAppPurchasesService::class);
$dataProvider = $this->createMock(AbstractExtensionDataProvider::class);
$dataProvider->expects(static::once())
->method('getInstalledExtensions')
->willReturn(new ExtensionCollection([$extension]));
->willReturn(new ExtensionCollection([
'otherExtension' => $otherExtension,
'testExtension' => $extension,
]));

$controller = new InAppPurchasesController(
$service,
Expand All @@ -54,6 +59,30 @@ public function testGetInAppFeature(): void
static::assertSame('testExtension', $content['name']);
}

public function testGetInAppFeatureWithUnknownExtension(): void
{
$extension = new ExtensionStruct();
$extension->setName('testExtension');
$service = $this->createMock(InAppPurchasesService::class);
$dataProvider = $this->createMock(AbstractExtensionDataProvider::class);
$dataProvider->expects(static::once())
->method('getInstalledExtensions')
->willReturn(new ExtensionCollection(['testExtension' => $extension]));

$controller = new InAppPurchasesController(
$service,
$this->createMock(InAppPurchaseUpdater::class),
$dataProvider,
$this->createMock(InAppPurchasesGateway::class),
$this->createMock(EntityRepository::class),
);

$this->expectException(ExtensionStoreException::class);
$this->expectExceptionMessage('The extension with technical name "otherExtension" is not known.');

$controller->getInAppPurchaseDetails('otherExtension', Context::createDefaultContext());
}

public function testCreateCart(): void
{
$cartStruct = $this->getInAppPurchaseCartStruct();
Expand Down
Loading