xref: /plugin/vshare/_test/SitesTest.php (revision b82f24af674525b493dac939915358a71279a32e)
17148e535SAndreas Gohr<?php
27148e535SAndreas Gohr
37148e535SAndreas Gohrnamespace dokuwiki\plugin\vshare\test;
47148e535SAndreas Gohr
57148e535SAndreas Gohruse DokuWikiTest;
67148e535SAndreas Gohr
77148e535SAndreas Gohr/**
8*b82f24afSAndreas Gohr * site configuration tests for the vshare plugin
97148e535SAndreas Gohr *
107148e535SAndreas Gohr * @group plugin_vshare
117148e535SAndreas Gohr * @group plugins
127148e535SAndreas Gohr */
137148e535SAndreas Gohrclass SitesTest extends DokuWikiTest
147148e535SAndreas Gohr{
15*b82f24afSAndreas Gohr    /**
16*b82f24afSAndreas Gohr     * @see testPlaceholder
17*b82f24afSAndreas Gohr     * @see testRegEx
18*b82f24afSAndreas Gohr     */
197148e535SAndreas Gohr    public function provideSites()
207148e535SAndreas Gohr    {
21*b82f24afSAndreas Gohr        $sites = \helper_plugin_vshare::loadSites();
227148e535SAndreas Gohr        foreach ($sites as $site => $data) {
237148e535SAndreas Gohr            yield [$site, $data];
247148e535SAndreas Gohr        }
257148e535SAndreas Gohr    }
267148e535SAndreas Gohr
277148e535SAndreas Gohr    /**
287148e535SAndreas Gohr     * @dataProvider provideSites
297148e535SAndreas Gohr     * @param string $site
307148e535SAndreas Gohr     * @param string[] $data
317148e535SAndreas Gohr     */
327148e535SAndreas Gohr    public function testPlaceholder($site, $data)
337148e535SAndreas Gohr    {
347148e535SAndreas Gohr        $this->assertArrayHasKey('url', $data, $site);
357148e535SAndreas Gohr        $this->assertStringContainsString('@VIDEO@', $data['url'], $site);
367148e535SAndreas Gohr    }
377148e535SAndreas Gohr
387148e535SAndreas Gohr    /**
397148e535SAndreas Gohr     * @dataProvider provideSites
407148e535SAndreas Gohr     * @param string $site
417148e535SAndreas Gohr     * @param string[] $data
427148e535SAndreas Gohr     */
437148e535SAndreas Gohr    public function testRegEx($site, $data)
447148e535SAndreas Gohr    {
457148e535SAndreas Gohr        if (empty($data['web']) || empty($data['vid'])) {
467148e535SAndreas Gohr            $this->markTestSkipped("$site has no sample data configured");
477148e535SAndreas Gohr        }
487148e535SAndreas Gohr        if (empty($data['rex'])) {
497148e535SAndreas Gohr            $this->markTestSkipped("$site has no regular expression");
507148e535SAndreas Gohr        }
517148e535SAndreas Gohr
527148e535SAndreas Gohr        // URL to use
537148e535SAndreas Gohr        $url = empty($data['emb']) ? $data['web'] : $data['emb'];
547148e535SAndreas Gohr
557148e535SAndreas Gohr        $this->assertSame(
567148e535SAndreas Gohr            1,
577148e535SAndreas Gohr            preg_match('!' . $data['rex'] . '!i', $url, $match),
587148e535SAndreas Gohr            "$site regex did not match web/emb url"
597148e535SAndreas Gohr        );
607148e535SAndreas Gohr        $this->assertEquals($data['vid'], $match[1], "$site regex did not return vid");
617148e535SAndreas Gohr    }
627148e535SAndreas Gohr}
63