diff options
Diffstat (limited to 'tests/formatter/FormatterFactoryTest.php')
-rw-r--r-- | tests/formatter/FormatterFactoryTest.php | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/tests/formatter/FormatterFactoryTest.php b/tests/formatter/FormatterFactoryTest.php new file mode 100644 index 00000000..317c0b2d --- /dev/null +++ b/tests/formatter/FormatterFactoryTest.php | |||
@@ -0,0 +1,101 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Shaarli\Formatter; | ||
4 | |||
5 | use PHPUnit\Framework\TestCase; | ||
6 | use Shaarli\Config\ConfigManager; | ||
7 | |||
8 | /** | ||
9 | * Class FormatterFactoryTest | ||
10 | * | ||
11 | * @package Shaarli\Formatter | ||
12 | */ | ||
13 | class FormatterFactoryTest extends TestCase | ||
14 | { | ||
15 | /** @var string Path of test config file */ | ||
16 | protected static $testConf = 'sandbox/config'; | ||
17 | |||
18 | /** @var FormatterFactory instance */ | ||
19 | protected $factory; | ||
20 | |||
21 | /** @var ConfigManager instance */ | ||
22 | protected $conf; | ||
23 | |||
24 | /** | ||
25 | * Initialize FormatterFactory instance | ||
26 | */ | ||
27 | public function setUp() | ||
28 | { | ||
29 | copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php'); | ||
30 | $this->conf = new ConfigManager(self::$testConf); | ||
31 | $this->factory = new FormatterFactory($this->conf); | ||
32 | } | ||
33 | |||
34 | /** | ||
35 | * Test creating an instance of BookmarkFormatter without any setting -> default formatter | ||
36 | */ | ||
37 | public function testCreateInstanceDefault() | ||
38 | { | ||
39 | $this->assertInstanceOf(BookmarkDefaultFormatter::class, $this->factory->getFormatter()); | ||
40 | } | ||
41 | |||
42 | /** | ||
43 | * Test creating an instance of BookmarkDefaultFormatter from settings | ||
44 | */ | ||
45 | public function testCreateInstanceDefaultSetting() | ||
46 | { | ||
47 | $this->conf->set('formatter', 'default'); | ||
48 | $this->assertInstanceOf(BookmarkDefaultFormatter::class, $this->factory->getFormatter()); | ||
49 | } | ||
50 | |||
51 | /** | ||
52 | * Test creating an instance of BookmarkDefaultFormatter from parameter | ||
53 | */ | ||
54 | public function testCreateInstanceDefaultParameter() | ||
55 | { | ||
56 | $this->assertInstanceOf( | ||
57 | BookmarkDefaultFormatter::class, | ||
58 | $this->factory->getFormatter('default') | ||
59 | ); | ||
60 | } | ||
61 | |||
62 | /** | ||
63 | * Test creating an instance of BookmarkRawFormatter from settings | ||
64 | */ | ||
65 | public function testCreateInstanceRawSetting() | ||
66 | { | ||
67 | $this->conf->set('formatter', 'raw'); | ||
68 | $this->assertInstanceOf(BookmarkRawFormatter::class, $this->factory->getFormatter()); | ||
69 | } | ||
70 | |||
71 | /** | ||
72 | * Test creating an instance of BookmarkRawFormatter from parameter | ||
73 | */ | ||
74 | public function testCreateInstanceRawParameter() | ||
75 | { | ||
76 | $this->assertInstanceOf( | ||
77 | BookmarkRawFormatter::class, | ||
78 | $this->factory->getFormatter('raw') | ||
79 | ); | ||
80 | } | ||
81 | |||
82 | /** | ||
83 | * Test creating an instance of BookmarkMarkdownFormatter from settings | ||
84 | */ | ||
85 | public function testCreateInstanceMarkdownSetting() | ||
86 | { | ||
87 | $this->conf->set('formatter', 'markdown'); | ||
88 | $this->assertInstanceOf(BookmarkMarkdownFormatter::class, $this->factory->getFormatter()); | ||
89 | } | ||
90 | |||
91 | /** | ||
92 | * Test creating an instance of BookmarkMarkdownFormatter from parameter | ||
93 | */ | ||
94 | public function testCreateInstanceMarkdownParameter() | ||
95 | { | ||
96 | $this->assertInstanceOf( | ||
97 | BookmarkMarkdownFormatter::class, | ||
98 | $this->factory->getFormatter('markdown') | ||
99 | ); | ||
100 | } | ||
101 | } | ||