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
4 changes: 4 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ parameters:
paths:
- src
- tests

ignoreErrors:
- # Shopware trunk classifies plugin test namespaces as non-Unit; unit tests here may still carry CoversClass
identifier: shopware.unexpectedTestCovers
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Write\WriteException;
use Shopware\Core\Framework\Uuid\Uuid;
use Shopware\Core\Framework\Validation\WriteConstraintViolationException;
use Shopware\Core\System\SalesChannel\Aggregate\SalesChannelDomain\SalesChannelDomainDefinition;
use Shopware\Core\System\SalesChannel\SalesChannelCollection;
use Shopware\Core\Test\TestDefaults;
use Swag\LanguagePack\Test\Helper\ServicesTrait;
use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Validator\ConstraintViolationList;

class SalesChannelDomainValidatorTest extends TestCase
{
Expand All @@ -43,8 +47,20 @@ public function testCreatingASalesChannelDomainWithADeactivatedLanguageFails():
$context = Context::createDefaultContext();
$languageId = $this->prepareSalesChannelActiveForLanguageByName('Dansk', false, $context);

$this->expectExceptionMessage(\sprintf('The language with the id "%s" is disabled for all Sales Channels.', $languageId));
$this->createSalesChannelDomain(Uuid::randomHex(), $languageId, $context);
$this->expectExceptionObject(new WriteConstraintViolationException(
new ConstraintViolationList([
new ConstraintViolation(\sprintf('The language with the id "%s" is disabled for all Sales Channels.', $languageId), null, [], '', null, null),
]),
));

try {
$this->createSalesChannelDomain(Uuid::randomHex(), $languageId, $context);
} catch (WriteException $e) {
foreach ($e->getExceptions() as $inner) {
throw $inner;
}
throw $e;
}
}

public function testUpdatingASalesChannelDomainToADisabledLanguageFails(): void
Expand All @@ -61,13 +77,25 @@ public function testUpdatingASalesChannelDomainToADisabledLanguageFails(): void
$domain = $this->salesChannelDomainRepository->search($criteria, $context)->first();
static::assertNotNull($domain);

$this->expectExceptionMessage(\sprintf('The language with the id "%s" is disabled for all Sales Channels.', $disabledLanguageId));
$this->salesChannelDomainRepository->update([
[
'id' => $domainId,
'languageId' => $disabledLanguageId,
],
], $context);
$this->expectExceptionObject(new WriteConstraintViolationException(
new ConstraintViolationList([
new ConstraintViolation(\sprintf('The language with the id "%s" is disabled for all Sales Channels.', $disabledLanguageId), null, [], '', null, null),
]),
));

try {
$this->salesChannelDomainRepository->update([
[
'id' => $domainId,
'languageId' => $disabledLanguageId,
],
], $context);
} catch (WriteException $e) {
foreach ($e->getExceptions() as $inner) {
throw $inner;
}
throw $e;
}
}

private function createSalesChannelDomain(string $domainId, string $languageId, Context $context): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
use PHPUnit\Framework\TestCase;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Write\WriteException;
use Shopware\Core\Framework\Validation\WriteConstraintViolationException;
use Shopware\Core\System\SalesChannel\Aggregate\SalesChannelLanguage\SalesChannelLanguageDefinition;
use Shopware\Core\System\SalesChannel\SalesChannelCollection;
use Shopware\Core\Test\TestDefaults;
use Swag\LanguagePack\Test\Helper\ServicesTrait;
use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Validator\ConstraintViolationList;

class SalesChannelLanguageValidatorTest extends TestCase
{
Expand All @@ -40,8 +44,20 @@ public function testCreatingASalesChannelLanguageWithADeactivatedLanguageFails()
$context = Context::createDefaultContext();
$languageId = $this->prepareSalesChannelActiveForLanguageByName('Dansk', false, $context);

$this->expectExceptionMessage(\sprintf('The language with the id "%s" is disabled for all Sales Channels.', $languageId));
$this->createSalesChannelLanguage($languageId, $context);
$this->expectExceptionObject(new WriteConstraintViolationException(
new ConstraintViolationList([
new ConstraintViolation(\sprintf('The language with the id "%s" is disabled for all Sales Channels.', $languageId), null, [], '', null, null),
]),
));

try {
$this->createSalesChannelLanguage($languageId, $context);
} catch (WriteException $e) {
foreach ($e->getExceptions() as $inner) {
throw $inner;
}
throw $e;
}
}

private function createSalesChannelLanguage(string $languageId, Context $context): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Write\WriteException;
use Shopware\Core\Framework\Uuid\Uuid;
use Shopware\Core\Framework\Validation\WriteConstraintViolationException;
use Shopware\Core\System\SalesChannel\SalesChannelCollection;
use Shopware\Core\System\SalesChannel\SalesChannelDefinition;
use Shopware\Core\Test\TestDefaults;
use Swag\LanguagePack\Test\Helper\ServicesTrait;
use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Validator\ConstraintViolationList;

class SalesChannelValidatorTest extends TestCase
{
Expand All @@ -43,8 +47,20 @@ public function testCreatingASalesChannelWithADeactivatedDefaultLanguageFails():
$context = Context::createDefaultContext();
$languageId = $this->prepareSalesChannelActiveForLanguageByName('Dansk', false, $context);

$this->expectExceptionMessage(\sprintf('The language with the id "%s" is disabled for all Sales Channels.', $languageId));
$this->createSalesChannelWithLanguage(Uuid::randomHex(), $languageId, $context);
$this->expectExceptionObject(new WriteConstraintViolationException(
new ConstraintViolationList([
new ConstraintViolation(\sprintf('The language with the id "%s" is disabled for all Sales Channels.', $languageId), null, [], '', null, null),
]),
));

try {
$this->createSalesChannelWithLanguage(Uuid::randomHex(), $languageId, $context);
} catch (WriteException $e) {
foreach ($e->getExceptions() as $inner) {
throw $inner;
}
throw $e;
}
}

public function testThatUpdatingASalesChannelToADisabledSalesChannelFails(): void
Expand All @@ -61,12 +77,24 @@ public function testThatUpdatingASalesChannelToADisabledSalesChannelFails(): voi
$salesChannel = $this->salesChannelRepository->search($criteria, $context)->first();
static::assertNotNull($salesChannel);

$this->expectExceptionMessage(\sprintf('The language with the id "%s" is disabled for all Sales Channels.', $disabledLanguageId));
$this->salesChannelRepository->update([[
'id' => $salesChannelId,
'languageId' => $disabledLanguageId,
'languages' => [['id' => $disabledLanguageId]],
]], $context);
$this->expectExceptionObject(new WriteConstraintViolationException(
new ConstraintViolationList([
new ConstraintViolation(\sprintf('The language with the id "%s" is disabled for all Sales Channels.', $disabledLanguageId), null, [], '', null, null),
]),
));

try {
$this->salesChannelRepository->update([[
'id' => $salesChannelId,
'languageId' => $disabledLanguageId,
'languages' => [['id' => $disabledLanguageId]],
]], $context);
} catch (WriteException $e) {
foreach ($e->getExceptions() as $inner) {
throw $inner;
}
throw $e;
}
}

private function createSalesChannelWithLanguage(string $salesChannelId, string $languageId, Context $context): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Write\WriteException;
use Shopware\Core\Framework\Uuid\Uuid;
use Shopware\Core\Framework\Validation\WriteConstraintViolationException;
use Shopware\Core\System\User\UserCollection;
use Shopware\Core\System\User\UserDefinition;
use Swag\LanguagePack\Test\Helper\ServicesTrait;
use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Validator\ConstraintViolationList;

class UserValidatorTest extends TestCase
{
Expand All @@ -41,8 +45,20 @@ public function testCreateUserWithADeactivatedLanguageFails(): void
$context = Context::createDefaultContext();
$localeId = $this->prepareAdministrationActiveForLanguageByLocale('da-DK', false, $context);

$this->expectExceptionMessage(\sprintf('The language bound to the locale with the id "%s" is disabled for the Administration.', $localeId));
$this->createUser(Uuid::randomHex(), $localeId, $context);
$this->expectExceptionObject(new WriteConstraintViolationException(
new ConstraintViolationList([
new ConstraintViolation(\sprintf('The language bound to the locale with the id "%s" is disabled for the Administration.', $localeId), null, [], '', null, null),
]),
));

try {
$this->createUser(Uuid::randomHex(), $localeId, $context);
} catch (WriteException $e) {
foreach ($e->getExceptions() as $inner) {
throw $inner;
}
throw $e;
}
}

public function testUpdateUserToDisabledLanguageFails(): void
Expand All @@ -59,11 +75,23 @@ public function testUpdateUserToDisabledLanguageFails(): void
$user = $this->userRepository->search($criteria, $context)->first();
static::assertNotNull($user);

$this->expectExceptionMessage(\sprintf('The language bound to the locale with the id "%s" is disabled for the Administration.', $disabledLocaleId));
$this->userRepository->update([[
'id' => $userId,
'localeId' => $disabledLocaleId,
]], $context);
$this->expectExceptionObject(new WriteConstraintViolationException(
new ConstraintViolationList([
new ConstraintViolation(\sprintf('The language bound to the locale with the id "%s" is disabled for the Administration.', $disabledLocaleId), null, [], '', null, null),
]),
));

try {
$this->userRepository->update([[
'id' => $userId,
'localeId' => $disabledLocaleId,
]], $context);
} catch (WriteException $e) {
foreach ($e->getExceptions() as $inner) {
throw $inner;
}
throw $e;
}
}

private function createUser(string $userId, string $localeId, Context $context): void
Expand Down
8 changes: 7 additions & 1 deletion tests/Util/Migration/MigrationHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Shopware\Core\System\Language\LanguageDefinition;
use Swag\LanguagePack\PackLanguage\PackLanguageDefinition;
use Swag\LanguagePack\SwagLanguagePack;
use Swag\LanguagePack\Util\Exception\LanguagePackException;
use Swag\LanguagePack\Util\Lifecycle\Lifecycle;
use Swag\LanguagePack\Util\Migration\MigrationHelper;

Expand Down Expand Up @@ -135,7 +136,12 @@ public function testMissingLocaleWhileCreating(): void
$this->migrationHelper->createPackLanguageTable();
$this->migrationHelper->alterLanguageAddPackLanguageColumn();

$this->expectExceptionMessage('No LocaleEntities associated to the following locale codes: bg-BG, bs-BA, cs-CZ, da-DK, el-GR, en-US, es-ES, fi-FI, fr-FR, hi-IN, hr-HR, hu-HU, id-ID, it-IT, ko-KR, lv-LV, nl-NL, nn-NO, pl-PL, pt-PT, ro-RO, ru-RU, sk-SK, sl-SI, sr-RS, sv-SE, tr-TR, uk-UA, vi-VN');
$this->expectExceptionObject(LanguagePackException::installWithoutLocales([
'bg-BG', 'bs-BA', 'cs-CZ', 'da-DK', 'el-GR', 'en-US', 'es-ES', 'fi-FI', 'fr-FR',
'hi-IN', 'hr-HR', 'hu-HU', 'id-ID', 'it-IT', 'ko-KR', 'lv-LV', 'nl-NL', 'nn-NO',
'pl-PL', 'pt-PT', 'ro-RO', 'ru-RU', 'sk-SK', 'sl-SI', 'sr-RS', 'sv-SE', 'tr-TR',
'uk-UA', 'vi-VN',
]));

$mockedMigrationHelper = new MigrationHelper($connectionMock);
$mockedMigrationHelper->createPackLanguages();
Expand Down
Loading