xref: /dokuwiki/_test/tests/Subscriptions/SubscriberRegexBuilderTest.php (revision 98640fd3947e9ff996e1c9206b5f845465794486)
1*98640fd3SAndreas Gohr<?php
2*98640fd3SAndreas Gohr
3*98640fd3SAndreas Gohrnamespace dokuwiki\test\Subscriptions;
4*98640fd3SAndreas Gohr
5*98640fd3SAndreas Gohruse dokuwiki\Subscriptions\SubscriberRegexBuilder;
6*98640fd3SAndreas Gohruse DokuWikiTest;
7*98640fd3SAndreas Gohr
8*98640fd3SAndreas Gohrclass SubscriberRegexBuilderTest extends DokuWikiTest
9*98640fd3SAndreas Gohr{
10*98640fd3SAndreas Gohr
11*98640fd3SAndreas Gohr    public function regexTestdataProvider()
12*98640fd3SAndreas Gohr    {
13*98640fd3SAndreas Gohr        return [
14*98640fd3SAndreas Gohr            ['Cold Fusion', null, null, 1],
15*98640fd3SAndreas Gohr            ['casper', null, null, 1],
16*98640fd3SAndreas Gohr            ['nope', null, null, 0],
17*98640fd3SAndreas Gohr            ['lights', null, null, 0],
18*98640fd3SAndreas Gohr            [['Cold Fusion', 'casper', 'nope'], null, null, 2],
19*98640fd3SAndreas Gohr            [null, 'list', null, 1],
20*98640fd3SAndreas Gohr            [null, 'every', null, 2],
21*98640fd3SAndreas Gohr            [null, 'digest', null, 3],
22*98640fd3SAndreas Gohr            [null, ['list', 'every'], null, 3],
23*98640fd3SAndreas Gohr            ['casper', 'digest', null, 0],
24*98640fd3SAndreas Gohr            ['casper', ['digest', 'every'], null, 1],
25*98640fd3SAndreas Gohr            ['zioth', 'list', '1344691369', 1],
26*98640fd3SAndreas Gohr            ['zioth', null, '1344691369', 1],
27*98640fd3SAndreas Gohr            ['zioth', 'digest', '1344691369', 0],
28*98640fd3SAndreas Gohr        ];
29*98640fd3SAndreas Gohr    }
30*98640fd3SAndreas Gohr
31*98640fd3SAndreas Gohr    /**
32*98640fd3SAndreas Gohr     * @dataProvider regexTestdataProvider
33*98640fd3SAndreas Gohr     */
34*98640fd3SAndreas Gohr    public function testRegexp($user, $style, $inputData, $expectedNumResults)
35*98640fd3SAndreas Gohr    {
36*98640fd3SAndreas Gohr        // data to test against
37*98640fd3SAndreas Gohr        $data = [
38*98640fd3SAndreas Gohr            "casper every\n",
39*98640fd3SAndreas Gohr            "Andreas digest 1344689733",
40*98640fd3SAndreas Gohr            "Cold%20Fusion every",
41*98640fd3SAndreas Gohr            "zioth list 1344691369\n",
42*98640fd3SAndreas Gohr            "nlights digest",
43*98640fd3SAndreas Gohr            "rikblok\tdigest  \t 1344716803",
44*98640fd3SAndreas Gohr        ];
45*98640fd3SAndreas Gohr
46*98640fd3SAndreas Gohr        $sub = new SubscriberRegexBuilder();
47*98640fd3SAndreas Gohr        $re = $sub->buildRegex($user, $style, $inputData);
48*98640fd3SAndreas Gohr        $this->assertFalse(empty($re));
49*98640fd3SAndreas Gohr        $result = preg_grep($re, $data);
50*98640fd3SAndreas Gohr        $this->assertEquals($expectedNumResults, count($result));
51*98640fd3SAndreas Gohr    }
52*98640fd3SAndreas Gohr}
53