1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Sylius\Tests\Fixture; |
15
|
|
|
|
16
|
|
|
use Sylius\Bundle\FixturesBundle\Fixture\FixtureRegistryInterface; |
17
|
|
|
use Sylius\Bundle\FixturesBundle\Listener\ListenerRegistryInterface; |
18
|
|
|
use Sylius\Bundle\FixturesBundle\Loader\SuiteLoaderInterface; |
19
|
|
|
use Sylius\Bundle\FixturesBundle\Suite\Suite; |
20
|
|
|
use Sylius\Component\Core\Model\ProductInterface; |
21
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; |
22
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
23
|
|
|
|
24
|
|
|
final class ProductAttributeFixturesTest extends KernelTestCase |
25
|
|
|
{ |
26
|
|
|
/** @test */ |
27
|
|
|
public function fixtures_are_loaded_properly(): void |
28
|
|
|
{ |
29
|
|
|
$kernel = static::bootKernel(); |
30
|
|
|
$container = $kernel->getContainer()->get('test.service_container', ContainerInterface::NULL_ON_INVALID_REFERENCE) ?? $kernel->getContainer(); |
31
|
|
|
|
32
|
|
|
$fixtureRegistry = $container->get(FixtureRegistryInterface::class); |
33
|
|
|
$listenerRegistry = $container->get(ListenerRegistryInterface::class); |
34
|
|
|
$suiteLoader = $container->get(SuiteLoaderInterface::class); |
35
|
|
|
|
36
|
|
|
$suite = new Suite('test'); |
37
|
|
|
$suite->addListener($listenerRegistry->getListener('orm_purger'), ['mode' => 'delete', 'exclude' => [], 'managers' => [null]]); |
38
|
|
|
$suite->addFixture($fixtureRegistry->getFixture('locale'), ['locales' => [], 'load_default_locale' => true]); |
39
|
|
|
$suite->addFixture($fixtureRegistry->getFixture('taxon'), ['custom' => ['books' => ['name' => 'Books', 'code' => 'BOOKS']]]); |
40
|
|
|
$suite->addFixture($fixtureRegistry->getFixture('product_attribute'), ['custom' => [ |
41
|
|
|
'book_author' => ['name' => 'Author', 'code' => 'AUTHOR', 'type' => 'text'], |
42
|
|
|
'book_date' => ['name' => 'Date', 'code' => 'DATE', 'type' => 'date'], |
43
|
|
|
'book_adults_only' => ['name' => 'Adults only', 'code' => 'ADULT', 'type' => 'checkbox'], |
44
|
|
|
'book_pages' => ['name' => 'Pages', 'code' => 'PAGES', 'type' => 'integer'], |
45
|
|
|
'book_cover' => [ |
46
|
|
|
'name' => 'Cover', |
47
|
|
|
'code' => 'COVER', |
48
|
|
|
'type' => 'select', |
49
|
|
|
'configuration' => [ |
50
|
|
|
'choices' => [ |
51
|
|
|
'SOFT' => ['en_US' => 'Soft'], |
52
|
|
|
'HARD' => ['en_US' => 'Hard'], |
53
|
|
|
], |
54
|
|
|
], |
55
|
|
|
], |
56
|
|
|
]]); |
57
|
|
|
$suite->addFixture($fixtureRegistry->getFixture('product'), ['custom' => [ |
58
|
|
|
'lotr_fellowship' => [ |
59
|
|
|
'name' => 'The Fellowship of the Ring', |
60
|
|
|
'code' => 'LOTR', |
61
|
|
|
'product_attributes' => [ |
62
|
|
|
'AUTHOR' => 'J.R.R Tolkien', |
63
|
|
|
'DATE' => '19-07-1954', |
64
|
|
|
'ADULT' => false, |
65
|
|
|
'PAGES' => 448, |
66
|
|
|
'COVER' => ['SOFT'], |
67
|
|
|
], |
68
|
|
|
], |
69
|
|
|
]]); |
70
|
|
|
|
71
|
|
|
$suiteLoader->load($suite); |
72
|
|
|
|
73
|
|
|
$productRepository = $container->get('sylius.repository.product'); |
74
|
|
|
|
75
|
|
|
/** @var ProductInterface $product */ |
76
|
|
|
$product = $productRepository->findOneByCode('LOTR'); |
77
|
|
|
$this->assertNotNull($product); |
78
|
|
|
|
79
|
|
|
$this->assertValueOfAttributeWithCode($product, 'DATE', new \DateTime('19-07-1954')); |
80
|
|
|
$this->assertValueOfAttributeWithCode($product, 'ADULT', false); |
81
|
|
|
$this->assertValueOfAttributeWithCode($product, 'PAGES', 448); |
82
|
|
|
$this->assertValueOfAttributeWithCode($product, 'COVER', ['SOFT']); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
private function assertValueOfAttributeWithCode(ProductInterface $product, string $code, $value): void |
86
|
|
|
{ |
87
|
|
|
$productAttribute = $product->getAttributeByCodeAndLocale($code, 'en_US'); |
88
|
|
|
$this->assertEquals($value, $productAttribute->getValue()); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|