はじまりの大地
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace dokuwiki\plugin\vshare\test;
|
||||
|
||||
use DokuWikiTest;
|
||||
|
||||
/**
|
||||
* General tests for the vshare plugin
|
||||
*
|
||||
* @group plugin_vshare
|
||||
* @group plugins
|
||||
*/
|
||||
class GeneralTest extends DokuWikiTest
|
||||
{
|
||||
|
||||
/**
|
||||
* Simple test to make sure the plugin.info.txt is in correct format
|
||||
*/
|
||||
public function testPluginInfo(): void
|
||||
{
|
||||
$file = __DIR__ . '/../plugin.info.txt';
|
||||
$this->assertFileExists($file);
|
||||
|
||||
$info = confToHash($file);
|
||||
|
||||
$this->assertArrayHasKey('base', $info);
|
||||
$this->assertArrayHasKey('author', $info);
|
||||
$this->assertArrayHasKey('email', $info);
|
||||
$this->assertArrayHasKey('date', $info);
|
||||
$this->assertArrayHasKey('name', $info);
|
||||
$this->assertArrayHasKey('desc', $info);
|
||||
$this->assertArrayHasKey('url', $info);
|
||||
|
||||
$this->assertEquals('vshare', $info['base']);
|
||||
$this->assertRegExp('/^https?:\/\//', $info['url']);
|
||||
$this->assertTrue(mail_isvalid($info['email']));
|
||||
$this->assertRegExp('/^\d\d\d\d-\d\d-\d\d$/', $info['date']);
|
||||
$this->assertTrue(false !== strtotime($info['date']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to ensure that every conf['...'] entry in conf/default.php has a corresponding meta['...'] entry in
|
||||
* conf/metadata.php.
|
||||
*/
|
||||
public function testPluginConf(): void
|
||||
{
|
||||
$conf_file = __DIR__ . '/../conf/default.php';
|
||||
$meta_file = __DIR__ . '/../conf/metadata.php';
|
||||
|
||||
if (!file_exists($conf_file) && !file_exists($meta_file)) {
|
||||
self::markTestSkipped('No config files exist -> skipping test');
|
||||
}
|
||||
|
||||
if (file_exists($conf_file)) {
|
||||
include($conf_file);
|
||||
}
|
||||
if (file_exists($meta_file)) {
|
||||
include($meta_file);
|
||||
}
|
||||
|
||||
$this->assertEquals(
|
||||
gettype($conf),
|
||||
gettype($meta),
|
||||
'Both ' . DOKU_PLUGIN . 'vshare/conf/default.php and ' . DOKU_PLUGIN . 'vshare/conf/metadata.php have to exist and contain the same keys.'
|
||||
);
|
||||
|
||||
if ($conf !== null && $meta !== null) {
|
||||
foreach ($conf as $key => $value) {
|
||||
$this->assertArrayHasKey(
|
||||
$key,
|
||||
$meta,
|
||||
'Key $meta[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'vshare/conf/metadata.php'
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($meta as $key => $value) {
|
||||
$this->assertArrayHasKey(
|
||||
$key,
|
||||
$conf,
|
||||
'Key $conf[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'vshare/conf/default.php'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace dokuwiki\plugin\vshare\test;
|
||||
|
||||
use DokuWikiTest;
|
||||
|
||||
/**
|
||||
* site configuration tests for the vshare plugin
|
||||
*
|
||||
* @group plugin_vshare
|
||||
* @group plugins
|
||||
*/
|
||||
class SitesTest extends DokuWikiTest
|
||||
{
|
||||
/**
|
||||
* @see testPlaceholder
|
||||
* @see testRegEx
|
||||
*/
|
||||
public function provideSites()
|
||||
{
|
||||
$sites = \helper_plugin_vshare::loadSites();
|
||||
foreach ($sites as $site => $data) {
|
||||
yield [$site, $data];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideSites
|
||||
* @param string $site
|
||||
* @param string[] $data
|
||||
*/
|
||||
public function testPlaceholder($site, $data)
|
||||
{
|
||||
$this->assertArrayHasKey('url', $data, $site);
|
||||
$this->assertStringContainsString('@VIDEO@', $data['url'], $site);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideSites
|
||||
* @param string $site
|
||||
* @param string[] $data
|
||||
*/
|
||||
public function testRegEx($site, $data)
|
||||
{
|
||||
if (empty($data['web']) || empty($data['vid'])) {
|
||||
$this->markTestSkipped("$site has no sample data configured");
|
||||
}
|
||||
if (empty($data['rex'])) {
|
||||
$this->markTestSkipped("$site has no regular expression");
|
||||
}
|
||||
|
||||
// URL to use
|
||||
$url = empty($data['emb']) ? $data['web'] : $data['emb'];
|
||||
|
||||
$this->assertSame(
|
||||
1,
|
||||
preg_match('!' . $data['rex'] . '!i', $url, $match),
|
||||
"$site regex did not match web/emb url"
|
||||
);
|
||||
$this->assertEquals($data['vid'], $match[1], "$site regex did not return vid");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace dokuwiki\plugin\vshare\test;
|
||||
|
||||
use DokuWikiTest;
|
||||
|
||||
/**
|
||||
* syntax handling tests for the vshare plugin
|
||||
*
|
||||
* @group plugin_vshare
|
||||
* @group plugins
|
||||
*/
|
||||
class VideoSyntaxTest extends DokuWikiTest
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
* @see testParseSize
|
||||
*/
|
||||
public function provideParseSize()
|
||||
{
|
||||
return [
|
||||
['', 425, 239],
|
||||
['small', 255, 143],
|
||||
['Small', 255, 143],
|
||||
['178x123', 178, 123],
|
||||
['178X123', 178, 123],
|
||||
['small&medium', 255, 143, ['medium' => '']],
|
||||
['small&autoplay=false', 255, 143, ['autoplay' => 'false']],
|
||||
['178x123&autoplay=false', 178, 123, ['autoplay' => 'false']],
|
||||
['autoplay=false', 425, 239, ['autoplay' => 'false']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideParseSize
|
||||
* @param string $input
|
||||
* @param int $ewidth
|
||||
* @param int $eheight
|
||||
* @param array $eparams
|
||||
*/
|
||||
public function testParseSize($input, $ewidth, $eheight, $eparams = [])
|
||||
{
|
||||
$syntax = new \syntax_plugin_vshare_video();
|
||||
parse_str($input, $params);
|
||||
list($width, $height) = $syntax->parseSize($params);
|
||||
|
||||
$this->assertEquals($ewidth, $width, 'width');
|
||||
$this->assertEquals($eheight, $height, 'height');
|
||||
$this->assertEquals($eparams, $eparams, 'height');
|
||||
}
|
||||
|
||||
/**
|
||||
* @see testHandle
|
||||
*/
|
||||
public function provideHandle()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'{{youtube>L-WM8YxwqEU}}',
|
||||
[
|
||||
'site' => 'youtube',
|
||||
'domain' => 'www.youtube-nocookie.com',
|
||||
'video' => 'L-WM8YxwqEU',
|
||||
'url' => '//www.youtube-nocookie.com/embed/L-WM8YxwqEU?',
|
||||
'align' => 'none',
|
||||
'width' => 425,
|
||||
'height' => 239,
|
||||
'title' => '',
|
||||
],
|
||||
],
|
||||
[
|
||||
'{{youtube>L-WM8YxwqEU?small&start=30&end=45|A random segment of 15 seconds}}',
|
||||
[
|
||||
'site' => 'youtube',
|
||||
'domain' => 'www.youtube-nocookie.com',
|
||||
'video' => 'L-WM8YxwqEU',
|
||||
'url' => '//www.youtube-nocookie.com/embed/L-WM8YxwqEU?start=30&end=45',
|
||||
'align' => 'none',
|
||||
'width' => 255,
|
||||
'height' => 143,
|
||||
'title' => 'A random segment of 15 seconds',
|
||||
],
|
||||
],
|
||||
// FIXME add more tests
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideHandle
|
||||
* @param string $input
|
||||
* @param array $expect
|
||||
*/
|
||||
public function testHandle($input, $expect)
|
||||
{
|
||||
$syntax = new \syntax_plugin_vshare_video();
|
||||
$result = $syntax->handle($input, DOKU_LEXER_MATCHED, 0, new \Doku_Handler());
|
||||
$this->assertEquals($expect, $result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user