|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Database\OptionManager; |
|
6
|
|
|
use WP_UnitTestCase; |
|
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Test case for the Plugin. |
|
10
|
|
|
* @group plugin |
|
11
|
|
|
*/ |
|
12
|
|
|
class OptionManagerTest extends WP_UnitTestCase |
|
13
|
|
|
{ |
|
14
|
|
|
use Setup; |
|
15
|
|
|
|
|
16
|
|
|
public function test_all() |
|
17
|
|
|
{ |
|
18
|
|
|
$options = glsr(OptionManager::class)->all(); |
|
19
|
|
|
$this->assertArrayHasKey('settings', $options); |
|
20
|
|
|
$this->assertArrayHasKey('version', $options); |
|
21
|
|
|
$this->assertArrayHasKey('version_upgraded_from', $options); |
|
22
|
|
|
$this->assertArrayHasKey('general', $options['settings']); |
|
23
|
|
|
$this->assertArrayHasKey('forms', $options['settings']); |
|
24
|
|
|
$this->assertArrayHasKey('reviews', $options['settings']); |
|
25
|
|
|
$this->assertArrayHasKey('schema', $options['settings']); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function test_database_key() |
|
29
|
|
|
{ |
|
30
|
|
|
$this->assertEquals(OptionManager::databaseKey(), 'site_reviews'); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function test_database_keys() |
|
34
|
|
|
{ |
|
35
|
|
|
$this->assertEquals(OptionManager::databaseKeys(), [ |
|
36
|
|
|
8 => "site_reviews", |
|
37
|
|
|
7 => "site_reviews", |
|
38
|
|
|
6 => "site_reviews_v6", |
|
39
|
|
|
5 => "site_reviews_v5", |
|
40
|
|
|
4 => "site_reviews_v4", |
|
41
|
|
|
3 => "site_reviews_v3", |
|
42
|
|
|
2 => "geminilabs_site_reviews-v2", |
|
43
|
|
|
1 => "geminilabs_site_reviews_settings", |
|
44
|
|
|
]); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function test_get() |
|
48
|
|
|
{ |
|
49
|
|
|
$options = glsr(OptionManager::class); |
|
50
|
|
|
$path = 'settings.general.require.approval'; |
|
51
|
|
|
$this->assertEquals($options->get($path), 'no'); |
|
52
|
|
|
$this->assertEquals($options->get($path, 'yes'), 'no'); |
|
53
|
|
|
$this->assertEquals($options->get($path, 'yes', 'bool'), false); |
|
54
|
|
|
$this->assertEquals($options->get('xyz', 'fallback'), 'fallback'); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function test_get_array() |
|
58
|
|
|
{ |
|
59
|
|
|
$options = glsr(OptionManager::class); |
|
60
|
|
|
$path = 'settings.general.require.approval'; |
|
61
|
|
|
$this->assertEquals($options->getArray($path), ['no']); |
|
62
|
|
|
$this->assertEquals($options->getArray($path, ['yes']), ['no']); |
|
63
|
|
|
$this->assertEquals($options->getArray('xyz', ['fallback']), ['fallback']); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function test_get_bool() |
|
67
|
|
|
{ |
|
68
|
|
|
$options = glsr(OptionManager::class); |
|
69
|
|
|
$path = 'settings.general.require.approval'; |
|
70
|
|
|
$this->assertFalse($options->getBool($path)); |
|
71
|
|
|
$this->assertFalse($options->getBool($path, 'yes')); |
|
72
|
|
|
$options->set($path, 'yes'); |
|
73
|
|
|
$this->assertTrue($options->getBool($path)); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function test_get_int() |
|
77
|
|
|
{ |
|
78
|
|
|
$options = glsr(OptionManager::class); |
|
79
|
|
|
$path = 'settings.reviews.excerpts_length'; |
|
80
|
|
|
$this->assertEquals($options->getInt($path), 55); |
|
81
|
|
|
$options->set($path, '50'); |
|
82
|
|
|
$this->assertEquals($options->getInt($path), 50); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function test_set() |
|
86
|
|
|
{ |
|
87
|
|
|
$options = glsr(OptionManager::class); |
|
88
|
|
|
$path = 'settings.general.require.approval'; |
|
89
|
|
|
$value = $options->get($path); |
|
90
|
|
|
$this->assertEquals($options->get($path), 'no'); |
|
91
|
|
|
$options->set($path, 'yes'); |
|
92
|
|
|
$this->assertEquals($options->get($path), 'yes'); |
|
93
|
|
|
$options->set($path, $value); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function test_wp() |
|
97
|
|
|
{ |
|
98
|
|
|
$options = glsr(OptionManager::class); |
|
99
|
|
|
$this->assertEquals($options->wp('blog_charset'), 'UTF-8'); |
|
100
|
|
|
$this->assertEquals($options->wp('blog_charset_x'), ''); |
|
101
|
|
|
$this->assertEquals($options->wp('blog_charset_x', 'xyz'), 'xyz'); |
|
102
|
|
|
$this->assertEquals($options->wp('blog_charset_x', 'xyz', 'bool'), false); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths