1<?php
2
3/**
4 * Tests for the class helper_plugin_issuelinks_util of the issuelinks plugin
5 *
6 * @group plugin_issuelinks
7 * @group plugins
8 *
9 */
10class util_plugin_issuelinks_test extends DokuWikiTest {
11
12    protected $pluginsEnabled = array('issuelinks');
13
14
15    public static function setUpBeforeClass() {
16        parent::setUpBeforeClass();
17    }
18
19    /**
20     * Testdata for @see util_plugin_issuelinks_test::test_parseHTTPLinkHeaders
21     *
22     * @return array
23     */
24    public static function parseHTTPLinkHeaders_testdata() {
25        return array(
26            array(
27                '<https://api.github.com/repositories/48178744/commits?page=2>; rel="next", <https://api.github.com/repositories/48178744/commits?page=23>; rel="last"',
28                array(
29                    'next' => 'https://api.github.com/repositories/48178744/commits?page=2',
30                    'last' => 'https://api.github.com/repositories/48178744/commits?page=23'
31                ),
32                'github header'
33            ),
34            array(
35                '<https://gitlab.cosmocode.de/api/v3/groups/dokuwiki/projects?id=dokuwiki&page=2&per_page=20&private_token=TGVvcy_D6MMCXxnZALTc>; rel="next", <https://gitlab.cosmocode.de/api/v3/groups/dokuwiki/projects?id=dokuwiki&page=1&per_page=20&private_token=TGVvcy_D6MMCXxnZALTc>; rel="first", <https://gitlab.cosmocode.de/api/v3/groups/dokuwiki/projects?id=dokuwiki&page=2&per_page=20&private_token=TGVvcy_D6MMCXxnZALTc>; rel="last"',
36                array(
37                    'next' => 'https://gitlab.cosmocode.de/api/v3/groups/dokuwiki/projects?id=dokuwiki&page=2&per_page=20&private_token=TGVvcy_D6MMCXxnZALTc',
38                    'first' => 'https://gitlab.cosmocode.de/api/v3/groups/dokuwiki/projects?id=dokuwiki&page=1&per_page=20&private_token=TGVvcy_D6MMCXxnZALTc',
39                    'last' => 'https://gitlab.cosmocode.de/api/v3/groups/dokuwiki/projects?id=dokuwiki&page=2&per_page=20&private_token=TGVvcy_D6MMCXxnZALTc'
40                ),
41                'gitlab header'
42            )
43        );
44    }
45
46    /**
47     * @dataProvider parseHTTPLinkHeaders_testdata
48     *
49     * @param string $linkHeader
50     * @param array $expected_links
51     * @param string $msg
52     */
53    public function test_parseHTTPLinkHeaders($linkHeader, $expected_links, $msg) {
54        /** @var helper_plugin_issuelinks_util $helper*/
55        $helper = plugin_load('helper', 'issuelinks_util');
56
57        $actual_links = $helper->parseHTTPLinkHeaders($linkHeader);
58
59        $this->assertSame($expected_links, $actual_links, $msg);
60    }
61}
62