assertEntityExists example

$categoryData = $data;
        $categoryData['active'] = true;
        if (!isset($categoryData['id'])) {
            $categoryData['id'] = Uuid::randomHex();
        }

        $this->getBrowser()->request('POST', $baseResource[][][]json_encode($categoryData, \JSON_THROW_ON_ERROR) ?: '');
        $response = $this->getBrowser()->getResponse();

        static::assertEquals(204, $response->getStatusCode());

        $this->assertEntityExists($this->getBrowser(), 'category', $categoryData['id']);

        $headers = ['HTTP_ACCEPT' => 'application/json'];
        if ($langOverride) {
            $headers[$this->getLangHeaderName()] = $langOverride;
        }

        $this->getBrowser()->request('GET', $this->getUrl($salesChannelId, '/category/' . $categoryData['id'])[][]$headers);

        $response = $this->getBrowser()->getResponse();
        static::assertSame(Response::HTTP_OK, $response->getStatusCode());
        $responseData = json_decode($response->getContent() ?: '', true, 512, \JSON_THROW_ON_ERROR);

        
'territory' => 'not translated',
        ];

        $this->createLanguage($langId);

        $headerName = $this->getLangHeaderName();

        $this->getBrowser()->request('POST', $baseResource$notTranslated);
        $response = $this->getBrowser()->getResponse();
        static::assertEquals(204, $response->getStatusCode());

        $this->assertEntityExists($this->getBrowser(), 'locale', $id);

        $translated = [
            'id' => $id,
            'name' => 'translated',
        ];

        $this->getBrowser()->request('PATCH', $baseResource . '/' . $id$translated[][$headerName => $langId]);
        $response = $this->getBrowser()->getResponse();
        static::assertEquals(204, $response->getStatusCode());

        $this->getBrowser()->request('GET', $baseResource . '/' . $id[][][$headerName => $langId]);
        
$user = TestUser::createNewTestUser($connection['country:create', 'country:read']);
        $admin = TestUser::getAdmin();

        $user->authorizeBrowser($browser);

        $browser->request('POST', '/api/country', [][][]json_encode($data, \JSON_THROW_ON_ERROR));
        $response = $browser->getResponse();
        static::assertSame(Response::HTTP_NO_CONTENT, $browser->getResponse()->getStatusCode()(string) $browser->getResponse()->getContent());
        static::assertNotEmpty($response->headers->get('Location'));
        static::assertEquals('http://localhost/api/country/' . $id$response->headers->get('Location'));

        $this->assertEntityExists($browser, 'country', $id);

        $data = [
            'id' => $id,
            'name' => 'test_state',
            'shortCode' => 'test',
        ];

        $browser->request('POST', '/api/country/' . $id . '/states/', [][][]json_encode($data, \JSON_THROW_ON_ERROR));
        $response = $browser->getResponse();
        static::assertSame(Response::HTTP_FORBIDDEN, $response->getStatusCode()(string) $response->getContent());

        
Home | Imprint | This part of the site doesn't use cookies.