1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Sonata Project package. |
7
|
|
|
* |
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Sonata\NewsBundle\Tests\DependencyInjection; |
15
|
|
|
|
16
|
|
|
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; |
17
|
|
|
use Sonata\ClassificationBundle\Model\Collection; |
18
|
|
|
use Sonata\ClassificationBundle\Model\Tag; |
19
|
|
|
use Sonata\Doctrine\Mapper\DoctrineCollector; |
20
|
|
|
use Sonata\MediaBundle\Model\Media; |
21
|
|
|
use Sonata\NewsBundle\DependencyInjection\SonataNewsExtension; |
22
|
|
|
use Sonata\NewsBundle\Model\Comment; |
23
|
|
|
use Sonata\NewsBundle\Model\Post; |
24
|
|
|
use Sonata\NewsBundle\Tests\Fixtures\UserMock; |
25
|
|
|
use Twig\Extra\String\StringExtension; |
26
|
|
|
|
27
|
|
|
class SonataNewsExtensionTest extends AbstractExtensionTestCase |
28
|
|
|
{ |
29
|
|
|
protected function setUp(): void |
30
|
|
|
{ |
31
|
|
|
parent::setUp(); |
32
|
|
|
$this->container->setParameter('kernel.bundles', ['SonataDoctrineBundle' => true]); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testLoadWithTagWithCollection(): void |
36
|
|
|
{ |
37
|
|
|
$this->load($this->getConfigurationWithTagWithCollection()); |
38
|
|
|
$collector = DoctrineCollector::getInstance(); |
39
|
|
|
$this->assertCount(2, $collector->getAssociations(), 'Our models should have 2 associations (post, comment)'); |
40
|
|
|
$postManyToOneAssociation = $collector->getAssociations()[Post::class]['mapManyToOne']; |
41
|
|
|
$this->assertCount(3, $postManyToOneAssociation, 'The post model should have 3 many to one associations (user, media, collection)'); |
42
|
|
|
$postManyToManyAssociation = $collector->getAssociations()[Post::class]['mapManyToMany']; |
43
|
|
|
$this->assertCount(1, $postManyToManyAssociation, 'The post model should have 1 many to many association (tag)'); |
44
|
|
|
$postOneToManyAssociation = $collector->getAssociations()[Post::class]['mapOneToMany']; |
45
|
|
|
$this->assertCount(1, $postOneToManyAssociation, 'The post model should have 1 one to many association (comment)'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testLoadTwigStringExtension(): void |
49
|
|
|
{ |
50
|
|
|
$this->load($this->getConfigurationWithTagWithCollection()); |
51
|
|
|
|
52
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithTag(StringExtension::class, 'twig.extension'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
protected function getConfigurationWithTagWithCollection(): array |
56
|
|
|
{ |
57
|
|
|
return [ |
58
|
|
|
'title' => 'Foo title', |
59
|
|
|
'link' => '/foo/bar', |
60
|
|
|
'description' => 'Foo description', |
61
|
|
|
'salt' => 'pepper', |
62
|
|
|
'comment' => [ |
63
|
|
|
'notification' => [ |
64
|
|
|
'emails' => ['[email protected]', '[email protected]'], |
65
|
|
|
'from' => '[email protected]', |
66
|
|
|
'template' => '@SonataNews/Mail/comment_notification.txt.twig', |
67
|
|
|
], |
68
|
|
|
], |
69
|
|
|
'class' => [ |
70
|
|
|
'post' => Post::class, |
71
|
|
|
'comment' => Comment::class, |
72
|
|
|
'media' => Media::class, |
73
|
|
|
'user' => UserMock::class, |
74
|
|
|
'collection' => Collection::class, |
75
|
|
|
'tag' => Tag::class, |
76
|
|
|
], |
77
|
|
|
]; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
protected function getContainerExtensions(): array |
81
|
|
|
{ |
82
|
|
|
return [ |
83
|
|
|
new SonataNewsExtension(), |
84
|
|
|
]; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|