Skip to content

Commit

Permalink
OP-164 - adds api tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MacBalc committed Jun 23, 2023
1 parent b88ecf8 commit 7304a78
Show file tree
Hide file tree
Showing 21 changed files with 1,320 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/Functional/Api/BlockTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on [email protected].
*/

declare(strict_types=1);

namespace Tests\BitBag\SyliusCmsPlugin\Functional\Api;

use BitBag\SyliusCmsPlugin\Entity\BlockInterface;
use BitBag\SyliusCmsPlugin\Repository\BlockRepositoryInterface;
use Symfony\Component\HttpFoundation\Response;
use Tests\BitBag\SyliusCmsPlugin\Functional\FunctionalTestCase;

class BlockTest extends FunctionalTestCase
{
public const CONTENT_TYPE_HEADER = ['CONTENT_TYPE' => 'application/ld+json', 'HTTP_ACCEPT' => 'application/ld+json'];

public function setUp(): void
{
$this->loadFixturesFromFile('Api/BlockTest/block.yml');
}

public function test_block_response(): void
{
/** @var BlockInterface $block */
$block = $this->getRepository()->findEnabledByCode('block1-code', 'code');
$this->client->request('GET', '/api/v2/shop/cms-plugin/blocks/' . $block->getId(), [], [], self::CONTENT_TYPE_HEADER);
$response = $this->client->getResponse();

$this->assertResponse($response, 'Api/BlockTest/test_it_get_block_by_id', Response::HTTP_OK);
}

public function test_blocks_response(): void
{
$this->client->request('GET', '/api/v2/shop/cms-plugin/blocks', [], [], self::CONTENT_TYPE_HEADER);
$response = $this->client->getResponse();

$this->assertResponse($response, 'Api/BlockTest/test_it_get_blocks', Response::HTTP_OK);
}

private function getRepository(): BlockRepositoryInterface
{
/** @var BlockRepositoryInterface $repository */
$repository = $this->getEntityManager()->getRepository(BlockInterface::class);

return $repository;
}
}
52 changes: 52 additions & 0 deletions tests/Functional/Api/FrequentlyAskedQuestionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on [email protected].
*/

declare(strict_types=1);

namespace Tests\BitBag\SyliusCmsPlugin\Functional\Api;

use BitBag\SyliusCmsPlugin\Entity\FrequentlyAskedQuestionInterface;
use BitBag\SyliusCmsPlugin\Repository\FrequentlyAskedQuestionRepositoryInterface;
use Symfony\Component\HttpFoundation\Response;
use Tests\BitBag\SyliusCmsPlugin\Functional\FunctionalTestCase;

class FrequentlyAskedQuestionTest extends FunctionalTestCase
{
public const CONTENT_TYPE_HEADER = ['CONTENT_TYPE' => 'application/ld+json', 'HTTP_ACCEPT' => 'application/ld+json'];

public function setUp(): void
{
$this->loadFixturesFromFile('Api/FrequentlyAskedQuestionTest/frequently_asked_question.yml');
}

public function test_block_response(): void
{
/** @var FrequentlyAskedQuestionInterface $faq */
$faq = $this->getRepository()->findOneEnabledByCode('faq1-code');
$this->client->request('GET', '/api/v2/shop/cms-plugin/faq/' . $faq->getId(), [], [], self::CONTENT_TYPE_HEADER);
$response = $this->client->getResponse();

$this->assertResponse($response, 'Api/FrequentlyAskedQuestionTest/test_it_get_frequently_asked_question_by_id', Response::HTTP_OK);
}

// public function test_blocks_response(): void{
// $this->client->request('GET', '/api/v2/shop/cms-plugin/faq', [], [], self::CONTENT_TYPE_HEADER);
// $response = $this->client->getResponse();
//
// $this->assertResponse($response, 'Api/BlockTest/test_it_get_blocks', Response::HTTP_OK);
// }

private function getRepository(): FrequentlyAskedQuestionRepositoryInterface
{
/** @var FrequentlyAskedQuestionRepositoryInterface $repository */
$repository = $this->getEntityManager()->getRepository(FrequentlyAskedQuestionInterface::class);

return $repository;
}
}
54 changes: 54 additions & 0 deletions tests/Functional/Api/MediaTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on [email protected].
*/

declare(strict_types=1);

namespace Tests\BitBag\SyliusCmsPlugin\Functional\Api;

use BitBag\SyliusCmsPlugin\Entity\MediaInterface;
use BitBag\SyliusCmsPlugin\Repository\MediaRepositoryInterface;
use Symfony\Component\HttpFoundation\Response;
use Tests\BitBag\SyliusCmsPlugin\Functional\FunctionalTestCase;

class MediaTest extends FunctionalTestCase
{
public const CONTENT_TYPE_HEADER = ['CONTENT_TYPE' => 'application/ld+json', 'HTTP_ACCEPT' => 'application/ld+json'];

public function setUp(): void
{
$this->loadFixturesFromFile('Api/MediaTest/media.yml');
}

public function test_media_response(): void
{
/** @var MediaInterface $media */
$media = $this->getRepository()->findOneEnabledByCode('media1-code', 'en_US', 'code');

$this->client->request('GET', '/api/v2/shop/cms-plugin/media/' . $media->getId(), [], [], self::CONTENT_TYPE_HEADER);
$response = $this->client->getResponse();

$this->assertResponse($response, 'Api/MediaTest/test_it_get_media_by_id', Response::HTTP_OK);
}

public function test_medias_response(): void
{
$this->client->request('GET', '/api/v2/shop/cms-plugin/media', [], [], self::CONTENT_TYPE_HEADER);
$response = $this->client->getResponse();

$this->assertResponse($response, 'Api/MediaTest/test_it_get_media', Response::HTTP_OK);
}

private function getRepository(): MediaRepositoryInterface
{
/** @var MediaRepositoryInterface $repository */
$repository = $this->getEntityManager()->getRepository(MediaInterface::class);

return $repository;
}
}
53 changes: 53 additions & 0 deletions tests/Functional/Api/PageTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on [email protected].
*/

declare(strict_types=1);

namespace Tests\BitBag\SyliusCmsPlugin\Functional\Api;

use BitBag\SyliusCmsPlugin\Entity\PageInterface;
use BitBag\SyliusCmsPlugin\Repository\PageRepositoryInterface;
use Symfony\Component\HttpFoundation\Response;
use Tests\BitBag\SyliusCmsPlugin\Functional\FunctionalTestCase;

class PageTest extends FunctionalTestCase
{
public const CONTENT_TYPE_HEADER = ['CONTENT_TYPE' => 'application/ld+json', 'HTTP_ACCEPT' => 'application/ld+json'];

public function setUp(): void
{
$this->loadFixturesFromFile('Api/PageTest/page.yml');
}

public function test_page_response(): void
{
/** @var PageInterface $page */
$page = $this->getRepository()->findOneEnabledByCode('page1-code', 'en_US');
$this->client->request('GET', '/api/v2/shop/cms-plugin/pages/' . $page->getId(), [], [], self::CONTENT_TYPE_HEADER);
$response = $this->client->getResponse();

$this->assertResponse($response, 'Api/PageTest/test_it_get_page_by_id', Response::HTTP_OK);
}

public function test_pages_response(): void
{
$this->client->request('GET', '/api/v2/shop/cms-plugin/pages', [], [], self::CONTENT_TYPE_HEADER);
$response = $this->client->getResponse();

$this->assertResponse($response, 'Api/PageTest/test_it_get_pages', Response::HTTP_OK);
}

private function getRepository(): PageRepositoryInterface
{
/** @var PageRepositoryInterface $repository */
$repository = $this->getEntityManager()->getRepository(PageInterface::class);

return $repository;
}
}
53 changes: 53 additions & 0 deletions tests/Functional/Api/SectionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on [email protected].
*/

declare(strict_types=1);

namespace Tests\BitBag\SyliusCmsPlugin\Functional\Api;

use BitBag\SyliusCmsPlugin\Entity\SectionInterface;
use BitBag\SyliusCmsPlugin\Repository\SectionRepositoryInterface;
use Symfony\Component\HttpFoundation\Response;
use Tests\BitBag\SyliusCmsPlugin\Functional\FunctionalTestCase;

class SectionTest extends FunctionalTestCase
{
public const CONTENT_TYPE_HEADER = ['CONTENT_TYPE' => 'application/ld+json', 'HTTP_ACCEPT' => 'application/ld+json'];

public function setUp(): void
{
$this->loadFixturesFromFile('Api/SectionTest/section.yml');
}

public function test_section_response(): void
{
/** @var SectionInterface $section */
$section = $this->getRepository()->findOneByCode('section1-code', 'en_US');
$this->client->request('GET', '/api/v2/shop/cms-plugin/sections/' . $section->getId(), [], [], self::CONTENT_TYPE_HEADER);
$response = $this->client->getResponse();

$this->assertResponse($response, 'Api/SectionTest/test_it_get_section_by_id', Response::HTTP_OK);
}

public function test_sections_response(): void
{
$this->client->request('GET', '/api/v2/shop/cms-plugin/sections', [], [], self::CONTENT_TYPE_HEADER);
$response = $this->client->getResponse();

$this->assertResponse($response, 'Api/SectionTest/test_it_get_sections', Response::HTTP_OK);
}

private function getRepository(): SectionRepositoryInterface
{
/** @var SectionRepositoryInterface $repository */
$repository = $this->getEntityManager()->getRepository(SectionInterface::class);

return $repository;
}
}
Loading

0 comments on commit 7304a78

Please sign in to comment.