aboutsummaryrefslogtreecommitdiff
path: root/tests/jsonapi/ForumEntriesDeleteTest.php
blob: 60ae3a6492c36c91fd6a9781bcf781697ebb9bc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php

require_once 'ForumTestHelper.php';

use JsonApi\Models\ForumEntry;
use JsonApi\Routes\Forum\ForumEntriesDelete;
use JsonApi\Errors\RecordNotFoundException;

class ForumEntriesDeleteTest extends \Codeception\Test\Unit
{
    use ForumTestHelper;

    /**
     * @var \UnitTester
     */
    protected $tester;

    protected function _before()
    {
        \DBManager::getInstance()->setConnection('studip', $this->getModule('\\Helper\\StudipDb')->dbh);
    }

    protected function _after()
    {
    }

    // tests

    public function testShouldDeleteEntry()
    {
        $credentials = $this->tester->getCredentialsForTestDozent();
        $cat = $this->createCategory($credentials);
        $entry = $this->createEntry($credentials, $cat->id);
        $app = $this->tester->createApp($credentials, 'delete', '/forum-entries/{id}', ForumEntriesDelete::class);

        $requestBuilder = $this->tester->createRequestBuilder($credentials);
        $requestBuilder
            ->setUri('/forum-entries/'.$entry->id)
            ->delete()
            ->setJsonApiBody($entry_json);

        $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());

        $this->tester->assertIsEmpty(ForumEntry::find($entry->id));
    }

    public function testShouldNotDeleteEntry()
    {
        $credentials = $this->tester->getCredentialsForTestDozent();
        $cat = $this->createCategory($credentials);
        $entry = $this->createEntry($credentials, $cat->id);
        $app = $this->tester->createApp($credentials, 'delete', '/forum-entries/{id}', ForumEntriesDelete::class);

        $requestBuilder = $this->tester->createRequestBuilder($credentials);
        $requestBuilder
            ->setUri('/forum-entries/badId')
            ->delete()
            ->setJsonApiBody($entry_json);

        $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
        $this->tester->assertSame(404, $response->getStatusCode());
    }
}