xref: /dokuwiki/_test/tests/Feed/FeedPageProcessorTest.php (revision 2ee6c32db8425e90b058cc4532511ffd71f65087)
1<?php
2
3namespace dokuwiki\test\Feed;
4
5use dokuwiki\Feed\FeedPageProcessor;
6use DOMWrap\Document;
7
8class FeedPageProcessorTest extends \DokuWikiTest
9{
10
11    public function provideData()
12    {
13        // an Item returned by FeedCreator::fetchItemsFromRecentChanges()
14        yield ([
15            [
16                'date' => 1705501370,
17                'ip' => '::1',
18                'type' => 'E',
19                'id' => 'wiki:dokuwiki',
20                'user' => 'testuser',
21                'sum' => 'test editing',
22                'extra' => '',
23                'sizechange' => 41,
24                'perms' => 8,
25                'mode' => 'page',
26            ],
27            1705501370, // fixed revision
28            ['testuser@undisclosed.example.com', 'Arthur Dent'], // proper author
29            'test editing', // summary
30        ]);
31
32        // an Item returned by FeedCreator::fetchItemsFromNamespace()
33        yield ([
34            [
35                'id' => 'wiki:dokuwiki',
36                'ns' => 'wiki',
37                'perm' => 8,
38                'type' => 'f',
39                'level' => 1,
40                'open' => true,
41            ],
42            null, // current revision
43            ['anonymous@undisclosed.example.com', 'Anonymous'], // unknown author
44            '', // no summary
45        ]);
46
47        // an Item returned by FeedCreator::fetchItemsFromSearch()
48        yield ([
49            [
50                'id' => 'wiki:dokuwiki',
51            ],
52            null, // current revision
53            ['anonymous@undisclosed.example.com', 'Anonymous'], // unknown author
54            '', // no summary
55        ]);
56    }
57
58
59    /**
60     * @dataProvider provideData
61     */
62    public function testProcessing($data, $expectedMtime, $expectedAuthor, $expectedSummary)
63    {
64        global $conf;
65        $conf['useacl'] = 1;
66        $conf['showuseras'] = 'username';
67        $conf['useheading'] = 1;
68
69        // if no expected mtime is given, we expect the filemtime of the page
70        // see https://github.com/dokuwiki/dokuwiki/pull/4156#issuecomment-1911842452 why we can't
71        // create this in the data provider
72        if ($expectedMtime === null) {
73            $expectedMtime = filemtime(wikiFN($data['id']));
74        }
75
76        $proc = new FeedPageProcessor($data);
77
78        $this->assertEquals('wiki:dokuwiki', $proc->getId());
79        $this->assertEquals('DokuWiki', $proc->getTitle());
80        $this->assertEquals($expectedAuthor, $proc->getAuthor());
81        $this->assertEquals($expectedMtime, $proc->getRev());
82        $this->assertEquals(null, $proc->getPrev());
83        $this->assertTrue($proc->isExisting());
84        $this->assertEquals(['wiki'], $proc->getCategory());
85        $this->assertStringContainsString('standards compliant', $proc->getAbstract());
86        $this->assertEquals($expectedSummary, $proc->getSummary());
87
88        $this->assertEquals(
89            "http://wiki.example.com/doku.php?id=wiki:dokuwiki&rev=$expectedMtime",
90            $proc->getURL('page')
91        );
92        $this->assertEquals(
93            "http://wiki.example.com/doku.php?id=wiki:dokuwiki&rev=$expectedMtime&do=revisions",
94            $proc->getURL('rev')
95        );
96        $this->assertEquals(
97            'http://wiki.example.com/doku.php?id=wiki:dokuwiki',
98            $proc->getURL('current')
99        );
100        $this->assertEquals(
101            "http://wiki.example.com/doku.php?id=wiki:dokuwiki&rev=$expectedMtime&do=diff",
102            $proc->getURL('diff')
103        );
104
105        $diff = explode("\n", $proc->getBody('diff'));
106        $this->assertEquals('<pre>', $diff[0]);
107        $this->assertStringStartsWith('@@', $diff[1]);
108
109        $doc = new Document();
110        $doc->html($proc->getBody('htmldiff'));
111        $th = $doc->find('table th');
112        $this->assertGreaterThanOrEqual(2, $th->count());
113
114        $doc = new Document();
115        $doc->html($proc->getBody('html'));
116        $home = $doc->find('a[href^="https://www.dokuwiki.org/manual"]');
117        $this->assertGreaterThanOrEqual(1, $home->count());
118
119        $this->assertStringContainsString('standards compliant', $proc->getBody('abstract'));
120    }
121
122}
123