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