stripWhitespace example

$response = $this->getBrowser()->getResponse();
        static::assertNotFalse($response->getContent());
        static::assertEquals(200, $response->getStatusCode());

        $json = \file_get_contents(__DIR__ . '/_fixtures/expectedCmsBlocks.json');
        static::assertNotFalse($json);
        static::assertJson($json);

        $expected = \json_decode($json, true, 512, \JSON_THROW_ON_ERROR);
        $actual = \json_decode($response->getContent(), true, 512, \JSON_THROW_ON_ERROR);

        $expected['blocks'][0]['template'] = $this->stripWhitespace($expected['blocks'][0]['template']);
        $expected['blocks'][1]['template'] = $this->stripWhitespace($expected['blocks'][1]['template']);
        $actual['blocks'][0]['template'] = $this->stripWhitespace($actual['blocks'][0]['template']);
        $actual['blocks'][1]['template'] = $this->stripWhitespace($actual['blocks'][1]['template']);

        static::assertEquals(
            $expected,
            $actual
        );
    }

    private function stripWhitespace(string $text): string
    {
$cmsBlocks = $cmsBlockRepository->search($criteria$this->context)->getEntities();
        static::assertCount(2, $cmsBlocks);

        /** @var AppCmsBlockEntity $firstCmsBlock */
        $firstCmsBlock = $cmsBlocks->filterByProperty('name', 'my-first-block')->first();
        static::assertEquals('my-first-block', $firstCmsBlock->getName());
        static::assertEquals('First block from app', $firstCmsBlock->getLabel());
        $firstBlockJson = json_encode($firstCmsBlock->getBlock(), \JSON_THROW_ON_ERROR);
        static::assertIsString($firstBlockJson);
        static::assertJsonStringEqualsJsonFile(__DIR__ . '/_fixtures/cms/expectedFirstCmsBlock.json', $firstBlockJson);
        static::assertEquals(
            $this->stripWhitespace((string) file_get_contents(__DIR__ . '/../Manifest/_fixtures/test/Resources/cms/blocks/my-first-block/preview.html')),
            $this->stripWhitespace($firstCmsBlock->getTemplate())
        );
        static::assertEquals(
            file_get_contents(__DIR__ . '/../Manifest/_fixtures/test/Resources/cms/blocks/my-first-block/styles.css'),
            $firstCmsBlock->getStyles()
        );

        /** @var AppCmsBlockEntity $secondCmsBlock */
        $secondCmsBlock = $cmsBlocks->filterByProperty('name', 'my-second-block')->first();
        static::assertEquals('my-second-block', $secondCmsBlock->getName());
        static::assertEquals('Second block from app', $secondCmsBlock->getLabel());
        
Home | Imprint | This part of the site doesn't use cookies.