xref: /dokuwiki/lib/plugins/extension/_test/ManagerTest.php (revision 8fe483c9dd38f0052abe729cc74057c9cdf54ad3)
1*8fe483c9SAndreas Gohr<?php
2*8fe483c9SAndreas Gohr
3*8fe483c9SAndreas Gohrnamespace dokuwiki\plugin\extension\test;
4*8fe483c9SAndreas Gohr
5*8fe483c9SAndreas Gohruse dokuwiki\plugin\extension\Extension;
6*8fe483c9SAndreas Gohruse dokuwiki\plugin\extension\Manager;
7*8fe483c9SAndreas Gohruse DokuWikiTest;
8*8fe483c9SAndreas Gohruse org\bovigo\vfs\vfsStream;
9*8fe483c9SAndreas Gohr
10*8fe483c9SAndreas Gohr/**
11*8fe483c9SAndreas Gohr * Tests for the Manager class
12*8fe483c9SAndreas Gohr *
13*8fe483c9SAndreas Gohr * @group plugin_extension
14*8fe483c9SAndreas Gohr * @group plugins
15*8fe483c9SAndreas Gohr */
16*8fe483c9SAndreas Gohrclass ManagerTest extends DokuWikiTest
17*8fe483c9SAndreas Gohr{
18*8fe483c9SAndreas Gohr    protected $pluginsEnabled = ['extension'];
19*8fe483c9SAndreas Gohr
20*8fe483c9SAndreas Gohr    /**
21*8fe483c9SAndreas Gohr     * Tests a full cycle of manager.dat operations
22*8fe483c9SAndreas Gohr     *
23*8fe483c9SAndreas Gohr     */
24*8fe483c9SAndreas Gohr    public function testCycle()
25*8fe483c9SAndreas Gohr    {
26*8fe483c9SAndreas Gohr        $root = io_mktmpdir();
27*8fe483c9SAndreas Gohr
28*8fe483c9SAndreas Gohr        $extension = $this->createMock(Extension::class);
29*8fe483c9SAndreas Gohr        $extension->method('getInstallDir')->willReturn($root);
30*8fe483c9SAndreas Gohr
31*8fe483c9SAndreas Gohr        $manager = new Manager($extension);
32*8fe483c9SAndreas Gohr
33*8fe483c9SAndreas Gohr        $this->assertNull($manager->getLastUpdate());
34*8fe483c9SAndreas Gohr        $this->assertEmpty($manager->getDownloadURL());
35*8fe483c9SAndreas Gohr
36*8fe483c9SAndreas Gohr        $manager->storeUpdate('http://example.com/firstinstall');
37*8fe483c9SAndreas Gohr
38*8fe483c9SAndreas Gohr        $this->assertFileExists($root . '/manager.dat');
39*8fe483c9SAndreas Gohr        $content = file_get_contents($root . '/manager.dat');
40*8fe483c9SAndreas Gohr        $this->assertStringContainsString('downloadurl=http://example.com/firstinstall', $content);
41*8fe483c9SAndreas Gohr        $this->assertStringContainsString('installed=', $content);
42*8fe483c9SAndreas Gohr
43*8fe483c9SAndreas Gohr        $updated = $manager->getLastUpdate();
44*8fe483c9SAndreas Gohr        $installed = $manager->getInstallDate();
45*8fe483c9SAndreas Gohr
46*8fe483c9SAndreas Gohr        $this->assertInstanceOf(\DateTime::class, $updated);
47*8fe483c9SAndreas Gohr        $this->assertInstanceOf(\DateTime::class, $installed);
48*8fe483c9SAndreas Gohr        $this->assertEquals($updated, $installed);
49*8fe483c9SAndreas Gohr        $this->assertEquals('http://example.com/firstinstall', $manager->getDownloadURL());
50*8fe483c9SAndreas Gohr
51*8fe483c9SAndreas Gohr        $this->waitForTick();
52*8fe483c9SAndreas Gohr        $manager->storeUpdate('http://example.com/update');
53*8fe483c9SAndreas Gohr
54*8fe483c9SAndreas Gohr        $updated = $manager->getLastUpdate();
55*8fe483c9SAndreas Gohr        $installed = $manager->getInstallDate();
56*8fe483c9SAndreas Gohr
57*8fe483c9SAndreas Gohr        $this->assertInstanceOf(\DateTime::class, $updated);
58*8fe483c9SAndreas Gohr        $this->assertInstanceOf(\DateTime::class, $installed);
59*8fe483c9SAndreas Gohr        $this->assertNotEquals($updated, $installed);
60*8fe483c9SAndreas Gohr        $this->assertEquals('http://example.com/update', $manager->getDownloadURL());
61*8fe483c9SAndreas Gohr    }
62*8fe483c9SAndreas Gohr
63*8fe483c9SAndreas Gohr
64*8fe483c9SAndreas Gohr}
65