Skip to content

Commit

Permalink
Merge pull request #35 from shopware/strip-slash-install
Browse files Browse the repository at this point in the history
fix: strip slash on sales channel url
  • Loading branch information
shyim authored Dec 11, 2024
2 parents 9cdcb79 + 72e3d10 commit a3b3c84
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Services/InstallationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function run(RunConfiguration $configuration, OutputInterface $output): v
$adminUser = EnvironmentHelper::getVariable('INSTALL_ADMIN_USERNAME', 'admin');
$adminPassword = EnvironmentHelper::getVariable('INSTALL_ADMIN_PASSWORD', 'shopware');
$appUrl = EnvironmentHelper::getVariable('APP_URL');
$salesChannelUrl = EnvironmentHelper::getVariable('SALES_CHANNEL_URL', $appUrl);
$salesChannelUrl = UrlHelper::normalizeSalesChannelUrl(EnvironmentHelper::getVariable('SALES_CHANNEL_URL', $appUrl) ?? '');

$additionalInstallParameters = [];

Expand Down
2 changes: 1 addition & 1 deletion src/Services/UpgradeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function run(RunConfiguration $configuration, OutputInterface $output): v
$salesChannelUrl = EnvironmentHelper::getVariable('SALES_CHANNEL_URL');

if ($salesChannelUrl !== null && $this->state->isStorefrontInstalled() && !$this->state->isSalesChannelExisting($salesChannelUrl)) {
$this->processHelper->console(['sales-channel:create:storefront', '--name=Storefront', '--url=' . $salesChannelUrl]);
$this->processHelper->console(['sales-channel:create:storefront', '--name=Storefront', '--url=' . UrlHelper::normalizeSalesChannelUrl($salesChannelUrl)]);
}

$this->processHelper->console(['plugin:refresh']);
Expand Down
19 changes: 19 additions & 0 deletions src/Services/UrlHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Shopware\Deployment\Services;

class UrlHelper
{
public static function normalizeSalesChannelUrl(string $url): string
{
$path = parse_url($url, \PHP_URL_PATH);

if ($path === '/') {
return rtrim($url, '/');
}

return $url;
}
}
2 changes: 2 additions & 0 deletions tests/Services/InstallationManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
use Shopware\Deployment\Services\ShopwareState;
use Shopware\Deployment\Struct\RunConfiguration;
use Symfony\Component\Console\Output\OutputInterface;
use Zalas\PHPUnit\Globals\Attribute\Env;

#[CoversClass(InstallationManager::class)]
#[Env('APP_URL', 'http://localhost')]
class InstallationManagerTest extends TestCase
{
public function testRun(): void
Expand Down
30 changes: 30 additions & 0 deletions tests/Services/UrlHelperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace Shopware\Deployment\Tests\Services;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Shopware\Deployment\Services\UrlHelper;

/**
* @internal
*/
#[CoversClass(UrlHelper::class)]
class UrlHelperTest extends TestCase
{
#[DataProvider('normalizeCases')]
public function testNormalizeUrls(string $input, string $expected): void
{
static::assertSame($expected, UrlHelper::normalizeSalesChannelUrl($input));
}

public static function normalizeCases(): \Generator
{
yield ['http://localhost', 'http://localhost'];
yield ['http://localhost/', 'http://localhost'];
yield ['http://localhost/foo', 'http://localhost/foo'];
}
}

0 comments on commit a3b3c84

Please sign in to comment.