-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OP-164 - adds tests for faq and section repositories
- Loading branch information
Showing
10 changed files
with
442 additions
and
45 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
...tion/DataFixtures/ORM/FrequentlyAskedQuestionRepositoryTest/test_it_finds_faq_by_code.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
57 changes: 57 additions & 0 deletions
57
.../DataFixtures/ORM/FrequentlyAskedQuestionRepositoryTest/test_it_finds_faq_by_position.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
42 changes: 42 additions & 0 deletions
42
tests/Integration/DataFixtures/ORM/SectionRepositoryTest/test_it_finds_section_by_code.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
42 changes: 42 additions & 0 deletions
42
...tion/DataFixtures/ORM/SectionRepositoryTest/test_it_finds_section_by_codes_and_locale.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
42 changes: 42 additions & 0 deletions
42
tests/Integration/DataFixtures/ORM/SectionRepositoryTest/test_it_finds_section_by_name.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
tests/Integration/Repository/FrequentlyAskedQuestionRepositoryTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.