Passed
Push — master ( 9fa2bb...0992fe )
by Michael
01:53
created

DefaultControllerTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
wmc 3
dl 0
loc 90
rs 10
c 1
b 1
f 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testReadTopicActionWithAccessNode() 0 22 1
B testReadTextnodeActionWithHitchShowsTextnode() 0 38 1
A testReadTextnodeActionWithoutHitchRedirectsToFinanceNodeAction() 0 15 1
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
        $topic = new Topic();
38
        $topic->setStatus(Topic::STATUS_ACTIVE);
39
        $this->getMongo()->persist($topic);
40
41
        $textnode = new Textnode();
42
        $textnode->setStatus(Textnode::STATUS_ACTIVE);
43
        $textnode->setTopicId($topic->getId());
44
        $textnode->setAccess(true);
45
        $textnode->setArbitraryId('someArbitraryId');
46
        $this->getMongo()->persist($textnode);
47
        $this->getMongo()->flush();
48
49
        $client = static::createClient();
50
51
        $client->request('GET', '/themenfeld/'.$topic->getId());
52
53
        $response = $client->getResponse();
54
55
        self::assertEquals(302, $response->getStatusCode());
56
        self::assertTrue($response->isRedirect('/collect/someArbitraryId'));
57
    }
58
59
    /**
60
     * @return void
61
     */
62
    public function testReadTextnodeActionWithoutHitchRedirectsToFinanceNodeAction(): void
63
    {
64
        $textnode = new Textnode();
65
        $textnode->setStatus(Textnode::STATUS_ACTIVE);
66
        $textnode->setAccess(true);
67
        $textnode->setArbitraryId('someArbitraryId');
68
        $this->getMongo()->persist($textnode);
69
        $this->getMongo()->flush();
70
71
        $client = static::createClient();
72
        $client->request('GET', '/text/someArbitraryId');
73
        $response = $client->getResponse();
74
75
        self::assertEquals(302, $response->getStatusCode());
76
        self::assertTrue($response->isRedirect('/collect/someArbitraryId'));
77
    }
78
79
    /**
80
     * @return void
81
     */
82
    public function testReadTextnodeActionWithHitchShowsTextnode(): void
83
    {
84
        $textnode = new Textnode();
85
        $textnode->setStatus(Textnode::STATUS_ACTIVE);
86
        $textnode->setAccess(true);
87
        $textnode->setArbitraryId('someArbitraryId');
88
        $textnode->setMetadata(
89
            [
90
                'Titel' => 'some title',
91
                'Autor' => 'some author',
92
                'Verlag' => 'some publisher',
93
            ]
94
        );
95
        $this->getMongo()->persist($textnode);
96
97
        $textnodeChild = new Textnode();
98
        $textnodeChild->setStatus(Textnode::STATUS_ACTIVE);
99
        $textnodeChild->setAccess(true);
100
        $textnodeChild->setArbitraryId('someArbitraryIdChild');
101
        $this->getMongo()->persist($textnodeChild);
102
103
        $hitch = new TextnodeHitch();
104
        $hitch->setSourceTextnode($textnode);
105
        $hitch->setTargetTextnode($textnodeChild);
106
        $hitch->setDescription('hitch to target textnode');
107
        $hitch->setStatus(TextnodeHitch::STATUS_ACTIVE);
108
        $this->getMongo()->persist($hitch);
109
110
        $this->getMongo()->flush();
111
112
        $client = static::createClient();
113
        $client->request('GET', '/text/someArbitraryId');
114
        $response = $client->getResponse();
115
116
        self::assertEquals(200, $response->getStatusCode());
117
        self::assertContains(
118
            'hitch to target textnode',
119
            $client->getResponse()->getContent()
120
        );
121
    }
122
}
123