aboutsummaryrefslogtreecommitdiff
path: root/tests/jsonapi/NewsDeleteTest.php
blob: ac671a675f49a5ab54a17a801b057a87a634241d (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
64
65
66
67
68
69
70
71
<?php

require_once 'NewsTestHelper.php';
use JsonApi\Routes\News\NewsDelete;
use JsonApi\Routes\News\CommentsDelete;

class NewsDeleteTest extends \Codeception\Test\Unit
{
    use NewsTestHelper;

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

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

    protected function _after()
    {
    }

    public function testShouldDeleteNews()
    {
        $credentials = $this->tester->getCredentialsForRoot();
        $title = 'A testing title';
        $content = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit';
        $news = $this->createNews($credentials, $title, $content);

        $newsId = $news->id;

        $response = $this->deleteNews($credentials, $newsId);
        $this->tester->assertSame(204, $response->getStatusCode());
    }

    private function deleteNews(array $credentials, $newsId)
    {
        $app = $this->tester->createApp($credentials, 'delete', '/news/{id}', NewsDelete::class);

        return $this->tester->sendMockRequest(
            $app,
            $this->tester
            ->createRequestBuilder($credentials)
            ->setUri('/news/'.$newsId)
            ->delete()
            ->getRequest()
        );
    }
    public function testShouldCommentDelete()
    {
        
        $title = 'A course testing title';
        $credentials = $this->tester->getCredentialsForTestDozent();
        $content = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit';
        $news = $this->createNews($credentials, $title, $content);
        $changeContent = 'time for a change';
        $comment = $this->createComment($credentials, $news, $changeContent);

        $app = $this->tester->createApp($credentials, 'delete', '/comments/{id}', CommentsDelete::class);
        $requestBuilder = $this->tester->createRequestBuilder($credentials);
        $requestBuilder
            ->setUri('/comments/'.$comment->id)
            ->delete()
            ->setJsonApiBody($entry_json);
    
        $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
        $this->tester->assertIsEmpty(StudipComment::find($comment->id));
    }
}