UserEntity example


        );
    }

    public function testGetLocaleFromContextReturnsLocaleFromUser(): void
    {
        $context = Context::createDefaultContext(new AdminApiSource('user-id', null));

        $userLocale = new LocaleEntity();
        $userLocale->setCode('user-locale');

        $user = new UserEntity();
        $user->setUniqueIdentifier('user-identifier');
        $user->setLocale($userLocale);

        $userRepository = static::createMock(EntityRepository::class);
        $userRepository->expects(static::once())
            ->method('search')
            ->willReturn(new EntitySearchResult(
                UserDefinition::ENTITY_NAME,
                1,
                new UserCollection([$user]),
                null,
                
$requestStack
        );

        $this->expectException(StoreSessionExpiredException::class);
        $middleware($response);
    }

    public function testLogsOutUserAndThrowsIfApiRespondsWithTokenExpiredException(): void
    {
        $response = new Response(401, [], '{"code":"ShopwarePlatformException-1"}');

        $adminUser = new UserEntity();
        $adminUser->setId('592d9499bea4417e929622ed0e92ba8b');

        $context = new Context(new AdminApiSource($adminUser->getId()));

        $request = new Request(
            [],
            [],
            [
                'sw-context' => $context,
            ]
        );

        
static::assertEquals(429, $response['errors'][0]['status']);
                static::assertEquals('FRAMEWORK__RATE_LIMIT_EXCEEDED', $response['errors'][0]['code']);
            } else {
                static::assertEquals(200, $this->browser->getResponse()->getStatusCode());
            }
        }
    }

    public function testResetRateLimtitUserRecovery(): void
    {
        $recoveryService = $this->createMock(UserRecoveryService::class);
        $userEntity = new UserEntity();
        $userEntity->setUsername('admin');
        $userEntity->setEmail('test@test.de');
        $recoveryService->method('getUserByHash')->willReturn($userEntity);
        $recoveryService->method('updatePassword')->willReturn(true);

        $controller = new UserRecoveryController(
            $recoveryService,
            $this->mockResetLimiter([
                RateLimiter::OAUTH => 1,
                RateLimiter::USER_RECOVERY => 1,
            ]),
        );


        $authHeaders = $provider->getAuthenticationHeader(
            Context::createDefaultContext(new AdminApiSource('user-id'))
        );

        static::assertArrayNotHasKey('X-Shopware-Shop-Secret', $authHeaders);
    }

    public function testGetAuthenticationHeaderReturnsUserToken(): void
    {
        $user = (new UserEntity())->assign([
            '_uniqueIdentifier' => 'user-id',
            'id' => 'user-id',
            'storeToken' => 'sbp-token',
        ]);

        $provider = new StoreRequestOptionsProvider(
            $this->configureUserRepositorySearchMock(new UserCollection([$user])static::once()),
            static::createMock(SystemConfigService::class),
            new InstanceService('sw-version', 'instance-id'),
            static::createMock(LocaleProvider::class)
        );

        

class TestCollectionWithToOneRelationship extends SerializationFixture
{
    /** * @return MediaCollection|MediaEntity */
    public function getInput(): EntityCollection|Entity
    {
        $mediaCollection = new MediaCollection();
        $userId = '6f51622eb3814c75ae0263cece27ce72';

        $user = new UserEntity();
        $user->setId($userId);
        $user->setFirstName('Manufacturer');
        $user->setLastName('');
        $user->setPassword('password');
        $user->setUsername('user1');
        $user->setActive(true);
        $user->setAdmin(true);
        $user->setEmail('user1@shop.de');
        $user->setCreatedAt(new \DateTime('2018-01-15T08:01:16.000+00:00'));
        $user->internalSetEntityData('user', new FieldVisibility([]));

        
use Shopware\Core\System\User\UserEntity;

/** * @internal */
class TestBasicWithToManyRelationships extends SerializationFixture
{
    public function getInput(): EntityCollection|Entity
    {
        $userId = '6f51622eb3814c75ae0263cece27ce72';

        $user = new UserEntity();
        $user->setId($userId);
        $user->setFirstName('Manufacturer');
        $user->setLastName('');
        $user->setPassword('password');
        $user->setUsername('user1');
        $user->setActive(true);
        $user->setAdmin(true);
        $user->setEmail('user1@shop.de');
        $user->setCreatedAt(new \DateTime('2018-01-15T08:01:16.000+00:00'));
        $user->internalSetEntityData('user', new FieldVisibility([]));

        
use Shopware\Core\System\User\UserEntity;

/** * @internal */
class TestBasicWithToOneRelationship extends SerializationFixture
{
    public function getInput(): EntityCollection|Entity
    {
        $userId = '6f51622eb3814c75ae0263cece27ce72';

        $user = new UserEntity();
        $user->setId($userId);
        $user->setFirstName('Manufacturer');
        $user->setLastName('');
        $user->setPassword('password');
        $user->setUsername('user1');
        $user->setActive(true);
        $user->setAdmin(true);
        $user->setEmail('user1@shop.de');
        $user->setCreatedAt(new \DateTime('2018-01-15T08:01:16.000+00:00'));
        $user->internalSetEntityData('user', new FieldVisibility([]));

        
/** * @internal */
class TestMainResourceShouldNotBeInIncluded extends SerializationFixture
{
    public function getInput(): EntityCollection|Entity
    {
        $mediaCollection = new MediaCollection();
        $userId = 'f343a3c119cf42a7841aa0ac5094908c';

        $user = new UserEntity();
        $user->setId($userId);
        $user->setFirstName('Manufacturer');
        $user->setLastName('');
        $user->setPassword('password');
        $user->setUsername('user1');
        $user->setActive(true);
        $user->setAdmin(true);
        $user->setEmail('user1@shop.de');
        $user->setCreatedAt(new \DateTime('2018-01-15T08:01:16.000+00:00'));
        $user->internalSetEntityData('user', new FieldVisibility([]));

        
static::assertCount(0, $recoveryRepository->creates);
        static::assertCount(0, $recoveryRepository->deletes);
    }

    public function testGenerateUserRecoveryWithNoSalesChannel(): void
    {
        static::expectException(UserException::class);
        static::expectExceptionMessage('No sales channel found.');

        $userEmail = 'existing@example.com';
        $context = new Context(new SystemSource()[], Defaults::CURRENCY, [Defaults::LANGUAGE_SYSTEM]);
        $user = new UserEntity();
        $user->setUniqueIdentifier(Uuid::randomHex());
        $user->setId(Uuid::randomHex());

        $recoveryEntity = new UserRecoveryEntity();
        $recoveryEntity->setUniqueIdentifier(Uuid::randomHex());
        $recoveryEntity->setId(Uuid::randomHex());
        $recoveryEntity->setHash(Uuid::randomHex());

        /** @var StaticEntityRepository<UserCollection> $userRepository */
        $userRepository = new StaticEntityRepository([
            new UserCollection([$user]),
        ],
Home | Imprint | This part of the site doesn't use cookies.