]>
Commit | Line | Data |
---|---|---|
e26e2060 A |
1 | <?php |
2 | ||
3 | namespace Shaarli\Formatter; | |
4 | ||
e26e2060 | 5 | use Shaarli\Config\ConfigManager; |
a5a9cf23 | 6 | use Shaarli\TestCase; |
e26e2060 A |
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 | */ | |
8f60e120 | 27 | protected function setUp(): void |
e26e2060 A |
28 | { |
29 | copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php'); | |
30 | $this->conf = new ConfigManager(self::$testConf); | |
a39acb25 | 31 | $this->factory = new FormatterFactory($this->conf, true); |
e26e2060 A |
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 | } |