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