2020-01-17 21:34:12 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Shaarli\Formatter;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Shaarli\Config\ConfigManager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class FormatterFactoryTest
|
|
|
|
*
|
|
|
|
* @package Shaarli\Formatter
|
|
|
|
*/
|
|
|
|
class FormatterFactoryTest extends TestCase
|
|
|
|
{
|
|
|
|
/** @var string Path of test config file */
|
|
|
|
protected static $testConf = 'sandbox/config';
|
|
|
|
|
|
|
|
/** @var FormatterFactory instance */
|
|
|
|
protected $factory;
|
|
|
|
|
|
|
|
/** @var ConfigManager instance */
|
|
|
|
protected $conf;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize FormatterFactory instance
|
|
|
|
*/
|
2020-09-26 15:08:39 +02:00
|
|
|
protected function setUp(): void
|
2020-01-17 21:34:12 +01:00
|
|
|
{
|
|
|
|
copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php');
|
|
|
|
$this->conf = new ConfigManager(self::$testConf);
|
2020-01-18 11:33:23 +01:00
|
|
|
$this->factory = new FormatterFactory($this->conf, true);
|
2020-01-17 21:34:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test creating an instance of BookmarkFormatter without any setting -> default formatter
|
|
|
|
*/
|
|
|
|
public function testCreateInstanceDefault()
|
|
|
|
{
|
|
|
|
$this->assertInstanceOf(BookmarkDefaultFormatter::class, $this->factory->getFormatter());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test creating an instance of BookmarkDefaultFormatter from settings
|
|
|
|
*/
|
|
|
|
public function testCreateInstanceDefaultSetting()
|
|
|
|
{
|
|
|
|
$this->conf->set('formatter', 'default');
|
|
|
|
$this->assertInstanceOf(BookmarkDefaultFormatter::class, $this->factory->getFormatter());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test creating an instance of BookmarkDefaultFormatter from parameter
|
|
|
|
*/
|
|
|
|
public function testCreateInstanceDefaultParameter()
|
|
|
|
{
|
|
|
|
$this->assertInstanceOf(
|
|
|
|
BookmarkDefaultFormatter::class,
|
|
|
|
$this->factory->getFormatter('default')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test creating an instance of BookmarkRawFormatter from settings
|
|
|
|
*/
|
|
|
|
public function testCreateInstanceRawSetting()
|
|
|
|
{
|
|
|
|
$this->conf->set('formatter', 'raw');
|
|
|
|
$this->assertInstanceOf(BookmarkRawFormatter::class, $this->factory->getFormatter());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test creating an instance of BookmarkRawFormatter from parameter
|
|
|
|
*/
|
|
|
|
public function testCreateInstanceRawParameter()
|
|
|
|
{
|
|
|
|
$this->assertInstanceOf(
|
|
|
|
BookmarkRawFormatter::class,
|
|
|
|
$this->factory->getFormatter('raw')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test creating an instance of BookmarkMarkdownFormatter from settings
|
|
|
|
*/
|
|
|
|
public function testCreateInstanceMarkdownSetting()
|
|
|
|
{
|
|
|
|
$this->conf->set('formatter', 'markdown');
|
|
|
|
$this->assertInstanceOf(BookmarkMarkdownFormatter::class, $this->factory->getFormatter());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test creating an instance of BookmarkMarkdownFormatter from parameter
|
|
|
|
*/
|
|
|
|
public function testCreateInstanceMarkdownParameter()
|
|
|
|
{
|
|
|
|
$this->assertInstanceOf(
|
|
|
|
BookmarkMarkdownFormatter::class,
|
|
|
|
$this->factory->getFormatter('markdown')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|