1<?php
2
3namespace dokuwiki\plugin\vshare\test;
4
5use DokuWikiTest;
6
7/**
8 * site configuration tests for the vshare plugin
9 *
10 * @group plugin_vshare
11 * @group plugins
12 */
13class SitesTest extends DokuWikiTest
14{
15    /**
16     * @see testPlaceholder
17     * @see testRegEx
18     */
19    public function provideSites()
20    {
21        $sites = \helper_plugin_vshare::loadSites();
22        foreach ($sites as $site => $data) {
23            yield [$site, $data];
24        }
25    }
26
27    /**
28     * @dataProvider provideSites
29     * @param string $site
30     * @param string[] $data
31     */
32    public function testPlaceholder($site, $data)
33    {
34        $this->assertArrayHasKey('url', $data, $site);
35        $this->assertStringContainsString('@VIDEO@', $data['url'], $site);
36    }
37
38    /**
39     * @dataProvider provideSites
40     * @param string $site
41     * @param string[] $data
42     */
43    public function testRegEx($site, $data)
44    {
45        if (empty($data['web']) || empty($data['vid'])) {
46            $this->markTestSkipped("$site has no sample data configured");
47        }
48        if (empty($data['rex'])) {
49            $this->markTestSkipped("$site has no regular expression");
50        }
51
52        // URL to use
53        $url = empty($data['emb']) ? $data['web'] : $data['emb'];
54
55        $this->assertSame(
56            1,
57            preg_match('!' . $data['rex'] . '!i', $url, $match),
58            "$site regex did not match web/emb url"
59        );
60        $this->assertEquals($data['vid'], $match[1], "$site regex did not return vid");
61    }
62}
63