1
|
|
|
<?php |
2
|
|
|
/* Copyright (C) 2017 Michael Giesler |
3
|
|
|
* |
4
|
|
|
* This file is part of Dembelo. |
5
|
|
|
* |
6
|
|
|
* Dembelo is free software: you can redistribute it and/or modify |
7
|
|
|
* it under the terms of the GNU Affero General Public License as published by |
8
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
9
|
|
|
* (at your option) any later version. |
10
|
|
|
* |
11
|
|
|
* Dembelo is distributed in the hope that it will be useful, |
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14
|
|
|
* GNU Affero General Public License 3 for more details. |
15
|
|
|
* |
16
|
|
|
* You should have received a copy of the GNU Affero General Public License 3 |
17
|
|
|
* along with Dembelo. If not, see <http://www.gnu.org/licenses/>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace AdminBundle\Tests\Controller; |
21
|
|
|
|
22
|
|
|
use AdminBundle\Controller\TextnodeController; |
23
|
|
|
use DembeloMain\Document\Importfile; |
24
|
|
|
use DembeloMain\Document\Licensee; |
25
|
|
|
use DembeloMain\Document\Textnode; |
26
|
|
|
use DembeloMain\Model\Repository\ImportfileRepositoryInterface; |
27
|
|
|
use DembeloMain\Model\Repository\LicenseeRepositoryInterface; |
28
|
|
|
use DembeloMain\Model\Repository\TextNodeRepositoryInterface; |
29
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
30
|
|
|
use Symfony\Component\HttpFoundation\Response; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Class TextnodeControllerTest |
34
|
|
|
* @package AdminBundle\Tests\Controller |
35
|
|
|
*/ |
36
|
|
|
class TextnodeControllerTest extends WebTestCase |
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* @var TextnodeController |
40
|
|
|
*/ |
41
|
|
|
private $controller; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|TextNodeRepositoryInterface |
45
|
|
|
*/ |
46
|
|
|
private $textnodeRepositoryMock; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|ImportfileRepositoryInterface |
50
|
|
|
*/ |
51
|
|
|
private $importfileRepositoryMock; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|LicenseeRepositoryInterface |
55
|
|
|
*/ |
56
|
|
|
private $licenseeRepositoryMock; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return void |
60
|
|
|
*/ |
61
|
|
|
protected function setUp(): void |
62
|
|
|
{ |
63
|
|
|
$this->textnodeRepositoryMock = $this->createTextnodeRepositoryMock(); |
64
|
|
|
$this->importfileRepositoryMock = $this->createImportfileRepositoryMock(); |
65
|
|
|
$this->licenseeRepositoryMock = $this->createLicenseeRepositoryMock(); |
66
|
|
|
|
67
|
|
|
$this->controller = new TextnodeController( |
68
|
|
|
$this->textnodeRepositoryMock, |
69
|
|
|
$this->importfileRepositoryMock, |
70
|
|
|
$this->licenseeRepositoryMock |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* tests textnode action |
76
|
|
|
* @return void |
77
|
|
|
*/ |
78
|
|
|
public function testTextnodesAction(): void |
79
|
|
|
{ |
80
|
|
|
$textnode = new Textnode(); |
81
|
|
|
$textnode->setId('someId'); |
82
|
|
|
$textnode->setCreated(new \DateTime('2017-01-01 12:00:00')); |
|
|
|
|
83
|
|
|
$textnode->setStatus(1); |
84
|
|
|
$textnode->setAccess(true); |
85
|
|
|
$textnode->setLicenseeId('someLicenseeId'); |
86
|
|
|
$textnode->setArbitraryId('someArbitraryId'); |
87
|
|
|
$textnode->setTwineId('someTwineId'); |
88
|
|
|
$textnode->setMetadata(['key1' => 'val1', 'key2' => 'val2']); |
89
|
|
|
|
90
|
|
|
$licensee = new Licensee(); |
91
|
|
|
$licensee->setId('someLicenseeId'); |
92
|
|
|
$licensee->setName('someLicenseeName'); |
93
|
|
|
|
94
|
|
|
$importfile = new Importfile(); |
95
|
|
|
$importfile->setId('someImportfileId'); |
96
|
|
|
$importfile->setName('someImportfileName'); |
97
|
|
|
|
98
|
|
|
$this->textnodeRepositoryMock->expects($this->once()) |
99
|
|
|
->method('findAll') |
100
|
|
|
->willReturn([$textnode]); |
101
|
|
|
|
102
|
|
|
$this->licenseeRepositoryMock->expects($this->once()) |
103
|
|
|
->method('findAll') |
104
|
|
|
->willReturn([$licensee]); |
105
|
|
|
|
106
|
|
|
$this->importfileRepositoryMock->expects($this->once()) |
107
|
|
|
->method('findAll') |
108
|
|
|
->willReturn([$importfile]); |
109
|
|
|
|
110
|
|
|
/* @var $response \Symfony\Component\HttpFoundation\Response */ |
111
|
|
|
$response = $this->controller->textnodesAction(); |
112
|
|
|
$this->assertInstanceOf(Response::class, $response); |
113
|
|
|
$expectedJson = '[{"id":"someId","status":"aktiv","created":"01.01.2017, 12:00:00",'; |
114
|
|
|
$expectedJson .= '"access":"ja","licensee":"someLicenseeName","importfile":"unbekannt","beginning":"...",'; |
115
|
|
|
$expectedJson .= '"financenode":"ja","arbitraryId":"someArbitraryId","twineId":"someTwineId",'; |
116
|
|
|
$expectedJson .= '"metadata":"key1: val1\nkey2: val2\n"}]'; |
117
|
|
|
$this->assertJsonStringEqualsJsonString($expectedJson, $response->getContent()); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @return TextNodeRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject |
122
|
|
|
*/ |
123
|
|
|
private function createTextnodeRepositoryMock(): TextNodeRepositoryInterface |
124
|
|
|
{ |
125
|
|
|
return $this->createMock(TextNodeRepositoryInterface::class); |
|
|
|
|
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|ImportfileRepositoryInterface |
130
|
|
|
*/ |
131
|
|
|
private function createImportfileRepositoryMock(): ImportfileRepositoryInterface |
132
|
|
|
{ |
133
|
|
|
$repository = $this->getMockBuilder(ImportfileRepositoryInterface::class) |
134
|
|
|
->disableOriginalConstructor() |
135
|
|
|
->setMethods(['findAll', 'save', 'find', 'findBy', 'findOneBy', 'getClassName']) |
136
|
|
|
->getMock(); |
137
|
|
|
|
138
|
|
|
return $repository; |
|
|
|
|
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|LicenseeRepositoryInterface |
143
|
|
|
*/ |
144
|
|
View Code Duplication |
private function createLicenseeRepositoryMock(): LicenseeRepositoryInterface |
|
|
|
|
145
|
|
|
{ |
146
|
|
|
$repository = $this->getMockBuilder(LicenseeRepositoryInterface::class) |
147
|
|
|
->disableOriginalConstructor() |
148
|
|
|
->setMethods(['findAll', 'save', 'find', 'findBy', 'findOneBy', 'getClassName', 'findOneByName']) |
149
|
|
|
->getMock(); |
150
|
|
|
|
151
|
|
|
return $repository; |
|
|
|
|
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|