added plugin screen (#671)

This commit is contained in:
Kevin Papst
2019-04-08 18:38:56 +02:00
committed by GitHub
parent 5bea9915f5
commit 3a4aa5a001
68 changed files with 1392 additions and 490 deletions

View File

@@ -0,0 +1,31 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Tests\Plugin\Fixtures;
use App\Plugin\PluginInterface;
class TestPlugin implements PluginInterface
{
/**
* @return string
*/
public function getName()
{
return 'TestPlugin';
}
/**
* @return string
*/
public function getPath()
{
return __DIR__;
}
}

View File

@@ -0,0 +1,29 @@
{
"name": "kimai/test-plugin-composer",
"description": "Just a test fixture for the PluginManager",
"homepage": "https://github.com/kevinpapst/kimai2",
"type": "kimai-plugin",
"require": {
"kimai/kimai2-composer": "*",
"kevinpapst/kimai2": "*"
},
"keywords": [
"kimai",
"kimai-plugin"
],
"license": "proprietary",
"authors": [
{
"name": "Kevin Papst",
"homepage": "https://www.kevinpapst.de"
}
],
"extra": {
"kimai": {
"require": "0.9",
"version": "1.0",
"name": "TestPlugin from composer.json",
"license": []
}
}
}

View File

@@ -0,0 +1,78 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Tests\Plugin;
use App\Plugin\Plugin;
use App\Plugin\PluginInterface;
use App\Plugin\PluginManager;
use App\Plugin\PluginMetadata;
use App\Tests\Plugin\Fixtures\TestPlugin;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Plugin\PluginManager
*/
class PluginManagerTest extends TestCase
{
public function testEmptyObject()
{
$sut = new PluginManager([]);
$this->assertEmpty($sut->getPlugins());
$this->assertNull($sut->getPlugin('foo'));
}
public function testUnknownRendererReturnsNull()
{
$sut = new PluginManager([]);
$this->assertNull($sut->getPlugin('foo'));
}
public function testAdd()
{
$sut = new PluginManager([]);
$plugin = $this->getMockBuilder(PluginInterface::class)
->setMethods(['getName', 'getPath'])
->getMock();
$plugin->method('getName')->willReturn('foo');
$plugin->method('getPath')->willReturn('bar');
$sut->addPlugin(new TestPlugin());
$sut->addPlugin($plugin);
$sut->addPlugin(new TestPlugin());
// make sure a plugin with the same name is not added twice, the first one wins!
$this->assertEquals(2, count($sut->getPlugins()));
$foo = $sut->getPlugin('foo');
$this->assertInstanceOf(Plugin::class, $foo);
$this->assertEquals('foo', $foo->getName());
$this->assertEquals('bar', $foo->getPath());
$test = $sut->getPlugin('TestPlugin');
$this->assertInstanceOf(Plugin::class, $test);
$this->assertEquals('TestPlugin', $test->getName());
$this->assertEquals(new PluginMetadata(), $test->getMetadata());
}
public function testLoadMetadata()
{
$sut = new PluginManager([new TestPlugin()]);
$plugin = $sut->getPlugin('TestPlugin');
$sut->loadMetadata($plugin);
$meta = $plugin->getMetadata();
$this->assertEquals('0.9', $meta->getKimaiVersion());
$this->assertEquals('1.0', $meta->getVersion());
$this->assertEquals('Just a test fixture for the PluginManager', $meta->getDescription());
$this->assertEquals('https://github.com/kevinpapst/kimai2', $meta->getHomepage());
}
}

View File

@@ -0,0 +1,42 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Tests\Plugin;
use App\Plugin\PluginMetadata;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Plugin\PluginMetadata
*/
class PluginMetadataTest extends TestCase
{
public function testEmptyObject()
{
$sut = new PluginMetadata();
$this->assertNull($sut->getDescription());
$this->assertNull($sut->getHomepage());
$this->assertNull($sut->getVersion());
$this->assertNull($sut->getKimaiVersion());
}
public function testGetterAndSetter()
{
$sut = new PluginMetadata();
$this->assertInstanceOf(PluginMetadata::class, $sut->setVersion('13.7'));
$this->assertInstanceOf(PluginMetadata::class, $sut->setHomepage('http://www.example.com'));
$this->assertInstanceOf(PluginMetadata::class, $sut->setDescription('foo bar'));
$this->assertInstanceOf(PluginMetadata::class, $sut->setKimaiVersion('1.0'));
$this->assertEquals('13.7', $sut->getVersion());
$this->assertEquals('http://www.example.com', $sut->getHomepage());
$this->assertEquals('foo bar', $sut->getDescription());
$this->assertEquals('1.0', $sut->getKimaiVersion());
}
}

View File

@@ -0,0 +1,48 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Tests\Plugin;
use App\Plugin\Plugin;
use App\Plugin\PluginMetadata;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Plugin\Plugin
*/
class PluginTest extends TestCase
{
public function testEmptyObject()
{
$plugin = new Plugin();
$this->assertNull($plugin->getName());
$this->assertNull($plugin->getPath());
$this->assertNull($plugin->getMetadata());
}
public function testGetterAndSetter()
{
$metadata = new PluginMetadata();
$metadata
->setDescription('foo')
->setHomepage('http://www.example.com')
->setVersion('13.7')
->setKimaiVersion('1.1')
;
$plugin = new Plugin();
$this->assertInstanceOf(Plugin::class, $plugin->setName('foo'));
$this->assertInstanceOf(Plugin::class, $plugin->setPath('bar'));
$this->assertInstanceOf(Plugin::class, $plugin->setMetadata($metadata));
$this->assertEquals('foo', $plugin->getName());
$this->assertEquals('bar', $plugin->getPath());
$this->assertSame($metadata, $plugin->getMetadata());
}
}