xref: /dokuwiki/lib/plugins/extension/_test/ExtensionTest.php (revision 9af82229f03804fb3198cbdf48d60d34d8afb191)
1cf2dcf1bSAndreas Gohr<?php
2cf2dcf1bSAndreas Gohr
3cf2dcf1bSAndreas Gohrnamespace dokuwiki\plugin\extension\test;
4cf2dcf1bSAndreas Gohr
5cf2dcf1bSAndreas Gohruse dokuwiki\plugin\extension\Extension;
6cf2dcf1bSAndreas Gohruse DokuWikiTest;
7cf2dcf1bSAndreas Gohr
8cf2dcf1bSAndreas Gohr/**
9cf2dcf1bSAndreas Gohr * Tests for the extension plugin
10cf2dcf1bSAndreas Gohr *
11cf2dcf1bSAndreas Gohr * @group plugin_extension
12cf2dcf1bSAndreas Gohr * @group plugins
13cf2dcf1bSAndreas Gohr */
14cf2dcf1bSAndreas Gohrclass ExtensionTest extends DokuWikiTest
15cf2dcf1bSAndreas Gohr{
168fe483c9SAndreas Gohr    protected $pluginsEnabled = ['extension'];
17cf2dcf1bSAndreas Gohr
188fe483c9SAndreas Gohr    /**
198fe483c9SAndreas Gohr     * Run checks against the extension plugin itself
208fe483c9SAndreas Gohr     */
218fe483c9SAndreas Gohr    public function testSelf()
22cf2dcf1bSAndreas Gohr    {
23cf2dcf1bSAndreas Gohr        $extension = Extension::createFromDirectory(__DIR__.'/../');
24cf2dcf1bSAndreas Gohr
25cf2dcf1bSAndreas Gohr        $this->assertFalse($extension->isTemplate());
268fe483c9SAndreas Gohr        $this->assertEquals('plugin', $extension->getType());
27cf2dcf1bSAndreas Gohr        $this->assertEquals('extension', $extension->getBase());
288fe483c9SAndreas Gohr        $this->assertEquals('extension', $extension->getId());
298fe483c9SAndreas Gohr        $this->assertEquals('`extension`', $extension->getId(true));
308fe483c9SAndreas Gohr        $this->assertEquals(DOKU_INC.'lib/plugins/extension', $extension->getCurrentDir());
318fe483c9SAndreas Gohr        $this->assertEquals(DOKU_INC.'lib/plugins/extension', $extension->getInstallDir());
328fe483c9SAndreas Gohr        $this->assertEquals('Extension Manager', $extension->getDisplayName());
338fe483c9SAndreas Gohr        $this->assertEquals('Andreas Gohr', $extension->getAuthor());
348fe483c9SAndreas Gohr        $this->assertEquals('andi@splitbrain.org', $extension->getEmail());
358fe483c9SAndreas Gohr        $this->assertEquals(md5('andi@splitbrain.org'), $extension->getEmailID());
368fe483c9SAndreas Gohr        $this->assertStringContainsString('plugins', $extension->getDescription());
378fe483c9SAndreas Gohr        $this->assertEquals('https://www.dokuwiki.org/plugin:extension', $extension->getURL());
38ea9e07cfSAndreas Gohr        $this->assertMatchesRegularExpression('/\d\d\d\d-\d\d-\d\d/',$extension->getInstalledVersion());
398fe483c9SAndreas Gohr        $this->assertContains('Admin', $extension->getComponentTypes());
408fe483c9SAndreas Gohr        $this->assertIsArray($extension->getDependencyList());
418fe483c9SAndreas Gohr        $this->assertEmpty($extension->getDependencyList());
428fe483c9SAndreas Gohr        $this->assertEmpty($extension->getMinimumPHPVersion());
438fe483c9SAndreas Gohr        $this->assertEmpty($extension->getMaximumPHPVersion());
448fe483c9SAndreas Gohr        $this->assertTrue($extension->isInstalled());
458fe483c9SAndreas Gohr        $this->assertFalse($extension->isGitControlled());
468fe483c9SAndreas Gohr        $this->assertTrue($extension->isBundled());
478fe483c9SAndreas Gohr        $this->assertFalse($extension->isProtected());
488fe483c9SAndreas Gohr        $this->assertFalse($extension->isInWrongFolder());
498fe483c9SAndreas Gohr        $this->assertTrue($extension->isEnabled());
508fe483c9SAndreas Gohr        $this->assertFalse($extension->hasChangedURL());
518fe483c9SAndreas Gohr        $this->assertFalse($extension->isUpdateAvailable());
528fe483c9SAndreas Gohr    }
538fe483c9SAndreas Gohr
548fe483c9SAndreas Gohr    /**
558fe483c9SAndreas Gohr     * Run checks against the dokuwiki template
568fe483c9SAndreas Gohr     */
578fe483c9SAndreas Gohr    public function testDokuWikiTemplate()
588fe483c9SAndreas Gohr    {
598fe483c9SAndreas Gohr        $extension = Extension::createFromDirectory(__DIR__.'/../../../tpl/dokuwiki/');
608fe483c9SAndreas Gohr
618fe483c9SAndreas Gohr        $this->assertTrue($extension->isTemplate());
628fe483c9SAndreas Gohr        $this->assertEquals('template', $extension->getType());
638fe483c9SAndreas Gohr        $this->assertEquals('dokuwiki', $extension->getBase());
648fe483c9SAndreas Gohr        $this->assertEquals('template:dokuwiki', $extension->getId());
658fe483c9SAndreas Gohr        $this->assertEquals('`template:dokuwiki`', $extension->getId(true));
668fe483c9SAndreas Gohr        $this->assertEquals(DOKU_INC.'lib/tpl/dokuwiki', $extension->getCurrentDir());
678fe483c9SAndreas Gohr        $this->assertEquals(DOKU_INC.'lib/tpl/dokuwiki', $extension->getInstallDir());
688fe483c9SAndreas Gohr        $this->assertEquals('DokuWiki Template', $extension->getDisplayName());
698fe483c9SAndreas Gohr        $this->assertEquals('Anika Henke', $extension->getAuthor());
708fe483c9SAndreas Gohr        $this->assertEquals('anika@selfthinker.org', $extension->getEmail());
718fe483c9SAndreas Gohr        $this->assertEquals(md5('anika@selfthinker.org'), $extension->getEmailID());
728fe483c9SAndreas Gohr        $this->assertStringContainsString('default template', $extension->getDescription());
738fe483c9SAndreas Gohr        $this->assertEquals('https://www.dokuwiki.org/template:dokuwiki', $extension->getURL());
74ea9e07cfSAndreas Gohr        $this->assertMatchesRegularExpression('/\d\d\d\d-\d\d-\d\d/',$extension->getInstalledVersion());
758fe483c9SAndreas Gohr        $this->assertContains('Template', $extension->getComponentTypes());
768fe483c9SAndreas Gohr        $this->assertIsArray($extension->getDependencyList());
778fe483c9SAndreas Gohr        $this->assertEmpty($extension->getDependencyList());
788fe483c9SAndreas Gohr        $this->assertEmpty($extension->getMinimumPHPVersion());
798fe483c9SAndreas Gohr        $this->assertEmpty($extension->getMaximumPHPVersion());
808fe483c9SAndreas Gohr        $this->assertTrue($extension->isInstalled());
818fe483c9SAndreas Gohr        $this->assertFalse($extension->isGitControlled());
828fe483c9SAndreas Gohr        $this->assertTrue($extension->isBundled());
83ea9e07cfSAndreas Gohr        $this->assertTrue($extension->isProtected()); // protected because it's the current template
848fe483c9SAndreas Gohr        $this->assertFalse($extension->isInWrongFolder());
858fe483c9SAndreas Gohr        $this->assertTrue($extension->isEnabled());
868fe483c9SAndreas Gohr        $this->assertFalse($extension->hasChangedURL());
878fe483c9SAndreas Gohr        $this->assertFalse($extension->isUpdateAvailable());
88cf2dcf1bSAndreas Gohr    }
89*9af82229SAndreas Gohr
90*9af82229SAndreas Gohr    /**
91*9af82229SAndreas Gohr     * A traversal base name in an archive's info file must be rejected
92*9af82229SAndreas Gohr     */
93*9af82229SAndreas Gohr    public function testBaseFromInfoFileRejectsTraversal()
94*9af82229SAndreas Gohr    {
95*9af82229SAndreas Gohr        $this->expectException(\RuntimeException::class);
96*9af82229SAndreas Gohr        Extension::createFromDirectory(__DIR__ . '/testdata/evilbase');
97*9af82229SAndreas Gohr    }
98*9af82229SAndreas Gohr
99*9af82229SAndreas Gohr    /**
100*9af82229SAndreas Gohr     * A traversal base passed as an extension id must be rejected
101*9af82229SAndreas Gohr     */
102*9af82229SAndreas Gohr    public function testBaseFromIdRejectsTraversal()
103*9af82229SAndreas Gohr    {
104*9af82229SAndreas Gohr        $this->expectException(\RuntimeException::class);
105*9af82229SAndreas Gohr        Extension::createFromId('../../../../tmp/evil');
106*9af82229SAndreas Gohr    }
107*9af82229SAndreas Gohr
108*9af82229SAndreas Gohr    /**
109*9af82229SAndreas Gohr     * A traversal base hidden behind the template: prefix must be rejected
110*9af82229SAndreas Gohr     */
111*9af82229SAndreas Gohr    public function testBaseFromTemplateIdRejectsTraversal()
112*9af82229SAndreas Gohr    {
113*9af82229SAndreas Gohr        $this->expectException(\RuntimeException::class);
114*9af82229SAndreas Gohr        Extension::createFromId('template:../../../evil');
115*9af82229SAndreas Gohr    }
116cf2dcf1bSAndreas Gohr}
117