summaryrefslogtreecommitdiffstats
path: root/tests/integration/db/ItemMapperTest.php
blob: b0b979f8fd4f704d80a8cf59339409dccccff64c (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
72
73
74
75
76
77
78
79
80
81
82
<?php

namespace OCA\News\Db;

use \OCA\News\Tests\Integration\NewsIntegrationTest;

class ItemMapperTest extends NewsIntegrationTest {


    public function testFind() {
        $feedId = $this->feeds['first feed']->getId();

        $item = new Item();
        $item->setTitle('my title thats long');
        $item->setGuid('a doner');
        $item->setFeedId($feedId);
        $item->setUnread();
        $item->setBody('Döner');

        $created = $this->itemMapper->insert($item);
        $fetched = $this->itemMapper->find($created->getId(), $this->userId);

        $this->assertEquals($item->getTitle(), $fetched->getTitle());
        $this->assertEquals($item->getGuid(), $fetched->getGuid());
        $this->assertEquals($item->getGuidHash(), $fetched->getGuidHash());
        $this->assertEquals($item->getFeedId(), $fetched->getFeedId());
        $this->assertEquals($item->isRead(), $fetched->isRead());
        $this->assertEquals('Döner', $fetched->getBody());
    }


    /**
     * @expectedException OCP\AppFramework\Db\DoesNotExistException
     */
    public function testFindNotFoundWhenDeletedFeed() {
        $id = $this->items['not found feed']->getId();
        $this->itemMapper->find($id, $this->userId);
    }


    /**
     * @expectedException OCP\AppFramework\Db\DoesNotExistException
     */
    public function testFindNotFoundWhenDeletedFolder() {
        $id = $this->items['not found folder']->getId();
        $this->itemMapper->find($id, $this->userId);
    }


    private function deleteReadOlderThanThreshold() {
        $this->itemMapper->deleteReadOlderThanThreshold(1);

        $this->itemMapper->find($this->items['a title1']->getId(),
                                $this->userId);
        $this->itemMapper->find($this->items['a title2']->getId(),
                                $this->userId);
        $this->itemMapper->find($this->items['a title3']->getId(),
                                $this->userId);
        $this->itemMapper->find($this->items['del3']->getId(), $this->userId);
        $this->itemMapper->find($this->items['del4']->getId(), $this->userId);
    }


    public function testDeleteOlderThanThresholdOne() {
        $this->deleteReadOlderThanThreshold();

        $this->setExpectedException(
            'OCP\AppFramework\Db\DoesNotExistException');
        $this->itemMapper->find($this->items['del1']->getId(), $this->userId);
    }


    public function testDeleteOlderThanThresholdTwo() {
        $this->deleteReadOlderThanThreshold();

        $this->setExpectedException(
            'OCP\AppFramework\Db\DoesNotExistException');
        $this->itemMapper->find($this->items['del2']->getId(), $this->userId);
    }


}