testReadTopicActionWithAccessNode()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 17
nc 1
nop 0
1
<?php
2
/* Copyright (C) 2018 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 DembeloMain\IntegrationTests\Controller;
21
22
use DembeloMain\Document\Textnode;
23
use DembeloMain\Document\TextnodeHitch;
24
use DembeloMain\Document\Topic;
25
use DembeloMain\IntegrationTests\WebTestCase;
26
27
/**
28
 * @group integration
29
 */
30
class DefaultControllerTest extends WebTestCase
31
{
32
    /**
33
     * @return void
34
     */
35
    public function testReadTopicActionWithAccessNode(): void
36
    {
37
        static::createClient();
38
39
        $topic = new Topic();
40
        $topic->setStatus(Topic::STATUS_ACTIVE);
41
        $this->getMongo()->persist($topic);
42
43
        $textnode = new Textnode();
44
        $textnode->setStatus(Textnode::STATUS_ACTIVE);
45
        $textnode->setTopicId($topic->getId());
46
        $textnode->setAccess(true);
47
        $textnode->setArbitraryId('someArbitraryId');
48
        $this->getMongo()->persist($textnode);
49
        $this->getMongo()->flush();
50
51
        $client = static::createClient();
52
53
        $client->request('GET', '/themenfeld/'.$topic->getId());
54
55
        $response = $client->getResponse();
56
57
        self::assertNotNull($response);
58
        self::assertEquals(302, $response->getStatusCode());
59
        self::assertTrue($response->isRedirect('/collect/someArbitraryId'), $response->getContent());
60
    }
61
62
    /**
63
     * @return void
64
     */
65
    public function testReadTextnodeActionWithoutHitchRedirectsToFinanceNodeAction(): void
66
    {
67
        $textnode = new Textnode();
68
        $textnode->setStatus(Textnode::STATUS_ACTIVE);
69
        $textnode->setAccess(true);
70
        $textnode->setArbitraryId('someArbitraryId');
71
        $this->getMongo()->persist($textnode);
72
        $this->getMongo()->flush();
73
74
        $client = static::createClient();
75
        $client->request('GET', '/text/someArbitraryId');
76
        $response = $client->getResponse();
77
78
        self::assertNotNull($response);
79
        self::assertEquals(302, $response->getStatusCode());
80
        self::assertTrue($response->isRedirect('/collect/someArbitraryId'));
81
    }
82
83
    /**
84
     * @return void
85
     */
86
    public function testReadTextnodeActionWithHitchShowsTextnode(): void
87
    {
88
        $topic = new Topic();
89
        $topic->setStatus(Topic::STATUS_ACTIVE);
90
        $topic->setName('someTopic');
91
        $this->getMongo()->persist($topic);
92
        $this->getMongo()->flush();
93
94
        $textnode = new Textnode();
95
        $textnode->setStatus(Textnode::STATUS_ACTIVE);
96
        $textnode->setAccess(true);
97
        $textnode->setArbitraryId('someArbitraryId');
98
        $textnode->setTopicId($topic->getId());
99
        $textnode->setMetadata(
100
            [
101
                'Titel' => 'some title',
102
                'Autor' => 'some author',
103
                'Verlag' => 'some publisher',
104
            ]
105
        );
106
        $this->getMongo()->persist($textnode);
107
108
        $textnodeChild = new Textnode();
109
        $textnodeChild->setStatus(Textnode::STATUS_ACTIVE);
110
        $textnodeChild->setAccess(true);
111
        $textnodeChild->setArbitraryId('someArbitraryIdChild');
112
        $textnodeChild->setTopicId($topic->getId());
113
        $this->getMongo()->persist($textnodeChild);
114
115
        $hitch = new TextnodeHitch();
116
        $hitch->setSourceTextnode($textnode);
117
        $hitch->setTargetTextnode($textnodeChild);
118
        $hitch->setDescription('hitch to target textnode');
119
        $hitch->setStatus(TextnodeHitch::STATUS_ACTIVE);
120
        $this->getMongo()->persist($hitch);
121
122
        $this->getMongo()->flush();
123
124
        $client = static::createClient();
125
        $client->request('GET', '/text/someArbitraryId');
126
        $response = $client->getResponse();
127
128
        self::assertNotNull($response);
129
        self::assertEquals(200, $response->getStatusCode());
130
        self::assertContains(
131
            'hitch to target textnode',
132
            $response->getContent()
133
        );
134
    }
135
}
136