Skip to content

Commit

Permalink
OP-164 - adds tests for faq and section repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
MacBalc committed Jun 23, 2023
1 parent 859465c commit b88ecf8
Show file tree
Hide file tree
Showing 10 changed files with 442 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Sylius\Component\Addressing\Model\Country:
USA:
code: 'US'
Sylius\Component\Currency\Model\Currency:
dollar:
code: 'USD'
Sylius\Component\Locale\Model\Locale:
locale:
createdAt: '<dateTimeBetween("-200 days", "now")>'
code: 'en_US'
Sylius\Component\Core\Model\Channel:
channel:
code: "code"
name: "name"
locales:
- '@locale'
default_locale: '@locale'
tax_calculation_strategy: 'order_items_based'
base_currency: '@dollar'
BitBag\SyliusCmsPlugin\Entity\FrequentlyAskedQuestionTranslation:
frequently_asked_question1_translation:
question: "How many days there are in one year?"
answer: "It may vary depending on whether you are working on a new question"
locale: 'en_US'
frequently_asked_question2_translation:
question: "Who is responsible for the translation"
answer: "Translators are"
locale: 'en_US'
frequently_asked_question3_translation:
question: "What is the date?"
answer: "Dunno"
locale: 'en_US'
BitBag\SyliusCmsPlugin\Entity\FrequentlyAskedQuestion:
frequently_asked_question1:
code: 'faq1-code'
enabled: true
position: 10
channels:
- '@channel'
translations:
- '@frequently_asked_question1_translation'
frequently_asked_question2:
code: 'faq2-code'
enabled: true
position: 20
channels:
- '@channel'
translations:
- '@frequently_asked_question2_translation'
frequently_asked_question3:
code: 'faq3-code'
enabled: false
position: 30
channels:
- '@channel'
translations:
- '@frequently_asked_question3_translation'
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Sylius\Component\Addressing\Model\Country:
USA:
code: 'US'
Sylius\Component\Currency\Model\Currency:
dollar:
code: 'USD'
Sylius\Component\Locale\Model\Locale:
locale:
createdAt: '<dateTimeBetween("-200 days", "now")>'
code: 'en_US'
Sylius\Component\Core\Model\Channel:
channel:
code: "code"
name: "name"
locales:
- '@locale'
default_locale: '@locale'
tax_calculation_strategy: 'order_items_based'
base_currency: '@dollar'
BitBag\SyliusCmsPlugin\Entity\FrequentlyAskedQuestionTranslation:
frequently_asked_question1_translation:
question: "How many days there are in one year?"
answer: "It may vary depending on whether you are working on a new question"
locale: 'en_US'
frequently_asked_question2_translation:
question: "Who is responsible for the translation"
answer: "Translators are"
locale: 'en_US'
frequently_asked_question3_translation:
question: "What is the date?"
answer: "Dunno"
locale: 'en_US'
BitBag\SyliusCmsPlugin\Entity\FrequentlyAskedQuestion:
frequently_asked_question1:
code: 'faq1-code'
enabled: true
position: 10
channels:
- '@channel'
translations:
- '@frequently_asked_question1_translation'
frequently_asked_question2:
code: 'faq2-code'
enabled: true
position: 20
channels:
- '@channel'
translations:
- '@frequently_asked_question2_translation'
frequently_asked_question3:
code: 'faq3-code'
enabled: false
position: 30
channels:
- '@channel'
translations:
- '@frequently_asked_question3_translation'
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Sylius\Component\Addressing\Model\Country:
USA:
code: 'US'
Sylius\Component\Currency\Model\Currency:
dollar:
code: 'USD'
Sylius\Component\Locale\Model\Locale:
locale:
createdAt: '<dateTimeBetween("-200 days", "now")>'
code: 'en_US'
Sylius\Component\Core\Model\Channel:
channel:
code: "code"
name: "name"
locales:
- '@locale'
default_locale: '@locale'
tax_calculation_strategy: 'order_items_based'
base_currency: '@dollar'
BitBag\SyliusCmsPlugin\Entity\SectionTranslation:
section1_translation:
name: 'translation1_name_en_US'
locale: 'en_US'
section2_translation:
name: 'translation2_name_en_US'
locale: 'en_US'
section3_translation:
name: 'translation3_name_en_US'
locale: 'en_US'
BitBag\SyliusCmsPlugin\Entity\Section:
section1:
code: 'section1-code'
translations:
- '@section1_translation'
section2:
code: 'section2-code'
translations:
- '@section2_translation'
section3:
code: 'section3-code'
translations:
- '@section3_translation'
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Sylius\Component\Addressing\Model\Country:
USA:
code: 'US'
Sylius\Component\Currency\Model\Currency:
dollar:
code: 'USD'
Sylius\Component\Locale\Model\Locale:
locale:
createdAt: '<dateTimeBetween("-200 days", "now")>'
code: 'en_US'
Sylius\Component\Core\Model\Channel:
channel:
code: "code"
name: "name"
locales:
- '@locale'
default_locale: '@locale'
tax_calculation_strategy: 'order_items_based'
base_currency: '@dollar'
BitBag\SyliusCmsPlugin\Entity\SectionTranslation:
section1_translation:
name: 'translation1_name_en_US'
locale: 'en_US'
section2_translation:
name: 'translation2_name_en_US'
locale: 'en_US'
section3_translation:
name: 'translation3_name_en_US'
locale: 'en_US'
BitBag\SyliusCmsPlugin\Entity\Section:
section1:
code: 'section1-code'
translations:
- '@section1_translation'
section2:
code: 'section2-code'
translations:
- '@section2_translation'
section3:
code: 'section3-code'
translations:
- '@section3_translation'
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Sylius\Component\Addressing\Model\Country:
USA:
code: 'US'
Sylius\Component\Currency\Model\Currency:
dollar:
code: 'USD'
Sylius\Component\Locale\Model\Locale:
locale:
createdAt: '<dateTimeBetween("-200 days", "now")>'
code: 'en_US'
Sylius\Component\Core\Model\Channel:
channel:
code: "code"
name: "name"
locales:
- '@locale'
default_locale: '@locale'
tax_calculation_strategy: 'order_items_based'
base_currency: '@dollar'
BitBag\SyliusCmsPlugin\Entity\SectionTranslation:
section1_translation:
name: 'translation1_name_en_US'
locale: 'en_US'
section2_translation:
name: 'translation2_name_en_US'
locale: 'en_US'
section3_translation:
name: 'translation3_name_en_US'
locale: 'en_US'
BitBag\SyliusCmsPlugin\Entity\Section:
section1:
code: 'section1-code'
translations:
- '@section1_translation'
section2:
code: 'section2-code'
translations:
- '@section2_translation'
section3:
code: 'section3-code'
translations:
- '@section3_translation'
33 changes: 16 additions & 17 deletions tests/Integration/Repository/BlockRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@

declare(strict_types=1);


namespace Tests\BitBag\SyliusCmsPlugin\Integration\Repository;

use ApiTestCase\JsonApiTestCase;
use BitBag\SyliusCmsPlugin\Entity\Block;
use BitBag\SyliusCmsPlugin\Entity\BlockInterface;
use BitBag\SyliusCmsPlugin\Repository\BlockRepositoryInterface;

class BlockRepositoryTest extends JsonApiTestCase
Expand All @@ -27,12 +26,10 @@ public function test_it_finds_enabled_block_by_code(): void
{
$this->loadFixturesFromFile('BlockRepositoryTest/test_it_finds_block_by_code.yml');

/** @var BlockRepositoryInterface $blockRepostitory */
$blockRepostitory = $this->getEntityManager()->getRepository(Block::class);

$blockRepository = $this->getRepository();

$block1 = $blockRepostitory->findEnabledByCode('block1-code', 'code');
$block3 = $blockRepostitory->findEnabledByCode('block3-code', 'code');
$block1 = $blockRepository->findEnabledByCode('block1-code', 'code');
$block3 = $blockRepository->findEnabledByCode('block3-code', 'code');

self::assertNotNull($block1);
self::assertNull($block3);
Expand All @@ -42,12 +39,10 @@ public function test_it_finds_enabled_block_by_section_code(): void
{
$this->loadFixturesFromFile('BlockRepositoryTest/test_it_finds_block_by_section_code.yml');

/** @var BlockRepositoryInterface $blockRepostitory */
$blockRepostitory = $this->getEntityManager()->getRepository(Block::class);

$blockRepository = $this->getRepository();

$block_array1 = $blockRepostitory->findBySectionCode('section1-code', 'en_US', 'code');
$block_array3 = $blockRepostitory->findBySectionCode('section3-code', 'en_US', 'code');
$block_array1 = $blockRepository->findBySectionCode('section1-code', 'en_US', 'code');
$block_array3 = $blockRepository->findBySectionCode('section3-code', 'en_US', 'code');

self::assertNotEmpty($block_array1);
self::assertEmpty($block_array3);
Expand All @@ -57,16 +52,20 @@ public function test_it_finds_enabled_block_by_product_code(): void
{
$this->loadFixturesFromFile('BlockRepositoryTest/test_it_finds_block_by_product_code.yml');

/** @var BlockRepositoryInterface $blockRepostitory */
$blockRepostitory = $this->getEntityManager()->getRepository(Block::class);
$blockRepository = $this->getRepository();


$block_array1 = $blockRepostitory->findByProductCode('MUG_SW', 'en_US', 'code');
$block_array3 = $blockRepostitory->findByProductCode('MUG_SW3', 'en_US', 'code');
$block_array1 = $blockRepository->findByProductCode('MUG_SW', 'en_US', 'code');
$block_array3 = $blockRepository->findByProductCode('MUG_SW3', 'en_US', 'code');

self::assertNotEmpty($block_array1);
self::assertEmpty($block_array3);
}

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

return $repository;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace Tests\BitBag\SyliusCmsPlugin\Integration\Repository;

use ApiTestCase\JsonApiTestCase;
use BitBag\SyliusCmsPlugin\Entity\FrequentlyAskedQuestionInterface;
use BitBag\SyliusCmsPlugin\Repository\FrequentlyAskedQuestionRepositoryInterface;

class FrequentlyAskedQuestionRepositoryTest extends JsonApiTestCase
{
public function setUp(): void
{
parent::setUp();
}

public function test_it_finds_enabled_frequently_asked_questions_ordered_by_position(): void
{
$this->loadFixturesFromFile('FrequentlyAskedQuestionRepositoryTest//test_it_finds_faq_by_position.yml');

$localeCode = 'en_US';
$channelCode = 'code';

$faqRepository = $this->getRepository();

$faqs = $faqRepository->findEnabledOrderedByPosition($localeCode, $channelCode);

self::assertNotEmpty($faqs);
self::assertCount(2, $faqs);

$previousPosition = null;
foreach ($faqs as $faq) {
if (null !== $previousPosition) {
self::assertGreaterThanOrEqual($previousPosition, $faq->getPosition());
self::assertTrue($faq->isEnabled());
}
$previousPosition = $faq->getPosition();
}
}

public function test_it_finds_enabled_frequently_asked_question_by_code(): void
{
$this->loadFixturesFromFile('FrequentlyAskedQuestionRepositoryTest/test_it_finds_faq_by_code.yml');

$faq1Code = 'faq1-code';
$faq3Code = 'faq3-code';

$faqRepository = $this->getRepository();

$faq1 = $faqRepository->findOneEnabledByCode($faq1Code);
$faq3 = $faqRepository->findOneEnabledByCode($faq3Code);

self::assertNotNull($faq1);
self::assertEquals($faq1Code, $faq1->getCode());
self::assertTrue($faq1->isEnabled());
self::assertNull($faq3);
}

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

return $repository;
}
}
Loading

0 comments on commit b88ecf8

Please sign in to comment.