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