aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/lib/plugins/extension/_test/ManagerTest.php
blob: 20af24770b57679a360a4509acb303b131d4c9a1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php

namespace dokuwiki\plugin\extension\test;

use dokuwiki\plugin\extension\Extension;
use dokuwiki\plugin\extension\Manager;
use DokuWikiTest;
use org\bovigo\vfs\vfsStream;

/**
 * Tests for the Manager class
 *
 * @group plugin_extension
 * @group plugins
 */
class ManagerTest extends DokuWikiTest
{
    protected $pluginsEnabled = ['extension'];

    /**
     * Tests a full cycle of manager.dat operations
     *
     */
    public function testCycle()
    {
        $root = io_mktmpdir();

        $extension = $this->createMock(Extension::class);
        $extension->method('getInstallDir')->willReturn($root);

        $manager = new Manager($extension);

        $this->assertNull($manager->getLastUpdate());
        $this->assertEmpty($manager->getDownloadURL());

        $manager->storeUpdate('http://example.com/firstinstall');

        $this->assertFileExists($root . '/manager.dat');
        $content = file_get_contents($root . '/manager.dat');
        $this->assertStringContainsString('downloadurl=http://example.com/firstinstall', $content);
        $this->assertStringContainsString('installed=', $content);

        $updated = $manager->getLastUpdate();
        $installed = $manager->getInstallDate();

        $this->assertInstanceOf(\DateTime::class, $updated);
        $this->assertInstanceOf(\DateTime::class, $installed);
        $this->assertEquals($updated, $installed);
        $this->assertEquals('http://example.com/firstinstall', $manager->getDownloadURL());

        $this->waitForTick();
        $manager->storeUpdate('http://example.com/update');

        $updated = $manager->getLastUpdate();
        $installed = $manager->getInstallDate();

        $this->assertInstanceOf(\DateTime::class, $updated);
        $this->assertInstanceOf(\DateTime::class, $installed);
        $this->assertNotEquals($updated, $installed);
        $this->assertEquals('http://example.com/update', $manager->getDownloadURL());
    }
}