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
24 changes: 24 additions & 0 deletions src/Context/SalesChannelContext/LanguageInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Shopware\App\SDK\Context\SalesChannelContext;

use Shopware\App\SDK\Context\ArrayStruct;

class LanguageInfo extends ArrayStruct
{
public function getName(): string
{
\assert(\is_string($this->data['name']));

return $this->data['name'];
}

public function getLocaleCode(): string
{
\assert(\is_string($this->data['localeCode']));

return $this->data['localeCode'];
}
}
6 changes: 6 additions & 0 deletions src/Context/SalesChannelContext/SalesChannelContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,10 @@ public function getCustomer(): ?Customer

return new Customer($this->data['customer']);
}

public function getLanguageInfo(): LanguageInfo
{
\assert(\is_array($this->data['languageInfo']));
return new LanguageInfo($this->data['languageInfo']);
}
}
24 changes: 24 additions & 0 deletions tests/Context/SalesChannelContext/LanguageInfoTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Shopware\App\SDK\Tests\Context\SalesChannelContext;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Shopware\App\SDK\Context\SalesChannelContext\LanguageInfo;

#[CoversClass(LanguageInfo::class)]
class LanguageInfoTest extends TestCase
{
public function testConstruct(): void
{
$languageInfo = new LanguageInfo([
'name' => 'English',
'localeCode' => 'en-GB',
]);

static::assertSame('English', $languageInfo->getName());
static::assertSame('en-GB', $languageInfo->getLocaleCode());
}
}
6 changes: 6 additions & 0 deletions tests/Context/SalesChannelContext/SalesChannelContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public function testConstruct(): void
'customer' => [
'id' => 'customer-id',
],
'languageInfo' => [
'name' => 'English',
'localeCode' => 'en-GB',
],
]);

static::assertSame('context-token', $context->getToken());
Expand All @@ -46,6 +50,8 @@ public function testConstruct(): void
static::assertSame('payment-method-id', $context->getPaymentMethod()->getId());
static::assertSame('sales-channel-id', $context->getSalesChannel()->getId());
static::assertSame('customer-id', $context->getCustomer()->getId());
static::assertSame('English', $context->getLanguageInfo()->getName());
static::assertSame('en-GB', $context->getLanguageInfo()->getLocaleCode());
}

public function testConstructNullable(): void
Expand Down
Loading