xref: /dokuwiki/_test/tests/Feed/FeedCreatorOptionsTest.php (revision 867da04d85140736fab69e0df2be0abb55719386)
1<?php
2
3namespace dokuwiki\test\Feed;
4
5use dokuwiki\Feed\FeedCreatorOptions;
6
7class FeedCreatorOptionsTest extends \DokuWikiTest
8{
9    // region getCacheKey mode behavior
10
11    public function testRecentModeIsCacheable()
12    {
13        $options = new FeedCreatorOptions(['feed_mode' => 'recent']);
14        $this->assertNotNull($options->getCacheKey());
15    }
16
17    public function testListModeIsNotCacheable()
18    {
19        $options = new FeedCreatorOptions(['feed_mode' => 'list', 'namespace' => 'wiki']);
20        $this->assertNull($options->getCacheKey());
21    }
22
23    public function testSearchModeIsNotCacheable()
24    {
25        $options = new FeedCreatorOptions(['feed_mode' => 'search', 'search_query' => 'test']);
26        $this->assertNull($options->getCacheKey());
27    }
28
29    public function testUnknownModeIsNotCacheable()
30    {
31        $options = new FeedCreatorOptions(['feed_mode' => 'foobar']);
32        $this->assertNull($options->getCacheKey());
33    }
34
35    // endregion
36
37    // region irrelevant params don't affect recent key
38
39    public function testSortDoesNotAffectRecentKey()
40    {
41        $a = new FeedCreatorOptions(['feed_mode' => 'recent', 'sort' => 'natural']);
42        $b = new FeedCreatorOptions(['feed_mode' => 'recent', 'sort' => 'date']);
43        $this->assertSame($a->getCacheKey(), $b->getCacheKey());
44    }
45
46    public function testSearchQueryDoesNotAffectRecentKey()
47    {
48        $a = new FeedCreatorOptions(['feed_mode' => 'recent']);
49        $b = new FeedCreatorOptions(['feed_mode' => 'recent', 'search_query' => 'anything']);
50        $this->assertSame($a->getCacheKey(), $b->getCacheKey());
51    }
52
53    // endregion
54
55    // region relevant params DO affect recent key
56
57    public function testNamespaceAffectsRecentKey()
58    {
59        $a = new FeedCreatorOptions(['feed_mode' => 'recent', 'namespace' => '']);
60        $b = new FeedCreatorOptions(['feed_mode' => 'recent', 'namespace' => 'wiki']);
61        $this->assertNotSame($a->getCacheKey(), $b->getCacheKey());
62    }
63
64    public function testItemsAffectsRecentKey()
65    {
66        $a = new FeedCreatorOptions(['feed_mode' => 'recent', 'items' => 10]);
67        $b = new FeedCreatorOptions(['feed_mode' => 'recent', 'items' => 20]);
68        $this->assertNotSame($a->getCacheKey(), $b->getCacheKey());
69    }
70
71    public function testShowMinorAffectsRecentKey()
72    {
73        $a = new FeedCreatorOptions(['feed_mode' => 'recent', 'show_minor' => false]);
74        $b = new FeedCreatorOptions(['feed_mode' => 'recent', 'show_minor' => true]);
75        $this->assertNotSame($a->getCacheKey(), $b->getCacheKey());
76    }
77
78    public function testContentTypeAffectsRecentKey()
79    {
80        $a = new FeedCreatorOptions(['feed_mode' => 'recent', 'content_type' => 'pages']);
81        $b = new FeedCreatorOptions(['feed_mode' => 'recent', 'content_type' => 'both']);
82        $this->assertNotSame($a->getCacheKey(), $b->getCacheKey());
83    }
84
85    // endregion
86
87    // region items clamping
88
89    public function testItemsClampedToMinimumOne()
90    {
91        $options = new FeedCreatorOptions(['items' => 0]);
92        $this->assertSame(1, $options->options['items']);
93    }
94
95    public function testItemsClampedToMaximum()
96    {
97        global $conf;
98        $options = new FeedCreatorOptions(['items' => 999999]);
99        $this->assertSame($conf['recent'] * 5, $options->options['items']);
100    }
101
102    public function testItemsValidValuePassesThrough()
103    {
104        $options = new FeedCreatorOptions(['items' => 10]);
105        $this->assertSame(10, $options->options['items']);
106    }
107
108    // endregion
109}
110