|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SWP\Behat\Contexts; |
|
6
|
|
|
|
|
7
|
|
|
use Behat\Behat\Context\Context; |
|
8
|
|
|
use Behat\Gherkin\Node\TableNode; |
|
9
|
|
|
use SWP\Bundle\ContentBundle\Doctrine\ArticleRepositoryInterface; |
|
10
|
|
|
use SWP\Component\ContentList\Model\ContentListItemInterface; |
|
11
|
|
|
use SWP\Component\ContentList\Repository\ContentListRepositoryInterface; |
|
12
|
|
|
use SWP\Component\Storage\Factory\FactoryInterface; |
|
13
|
|
|
|
|
14
|
|
|
final class ContentListItemContext extends AbstractContext implements Context |
|
15
|
|
|
{ |
|
16
|
|
|
private $contentListItemFactory; |
|
17
|
|
|
|
|
18
|
|
|
private $contentListRepository; |
|
19
|
|
|
|
|
20
|
|
|
private $articleRepository; |
|
21
|
|
|
|
|
22
|
|
|
public function __construct( |
|
23
|
|
|
FactoryInterface $contentListItemFactory, |
|
24
|
|
|
ContentListRepositoryInterface $contentListRepository, |
|
25
|
|
|
ArticleRepositoryInterface $articleRepository |
|
26
|
|
|
) { |
|
27
|
|
|
$this->contentListItemFactory = $contentListItemFactory; |
|
28
|
|
|
$this->contentListRepository = $contentListRepository; |
|
29
|
|
|
$this->articleRepository = $articleRepository; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @Given the following Content List Items: |
|
34
|
|
|
*/ |
|
35
|
|
|
public function theFollowingContentListItems(TableNode $table) |
|
36
|
|
|
{ |
|
37
|
|
|
foreach ($table as $row => $columns) { |
|
38
|
|
|
/** @var ContentListItemInterface $contentListItem */ |
|
39
|
|
|
$contentListItem = $this->contentListItemFactory->create(); |
|
40
|
|
|
$contentListItem->setPosition(0); |
|
41
|
|
|
|
|
42
|
|
|
$columns['content_list'] = $this->contentListRepository->findOneBy(['name' => $columns['content_list']]); |
|
43
|
|
|
$columns['content'] = $this->articleRepository->findOneBy(['title' => $columns['article']]); |
|
44
|
|
|
unset($columns['article']); |
|
45
|
|
|
|
|
46
|
|
|
$this->fillObject($contentListItem, $columns); |
|
47
|
|
|
$this->contentListRepository->persist($contentListItem); |
|
48
|
|
|
$this->contentListRepository->flush(); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|