-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMetaboxServiceProviderTest.php
More file actions
128 lines (110 loc) · 4.09 KB
/
MetaboxServiceProviderTest.php
File metadata and controls
128 lines (110 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
namespace OWC\OpenPub\Tests\Base\Metabox;
use Mockery as m;
use OWC\OpenPub\Base\Foundation\Config;
use OWC\OpenPub\Base\Foundation\Loader;
use OWC\OpenPub\Base\Foundation\Plugin;
use OWC\OpenPub\Base\Metabox\AdminNotice;
use OWC\OpenPub\Base\Metabox\MetaboxServiceProvider;
use OWC\OpenPub\Tests\TestCase;
use WP_Mock;
class MetaboxServiceProviderTest extends TestCase
{
protected function setUp(): void
{
WP_Mock::setUp();
\WP_Mock::userFunction('wp_parse_args', [
'return' => [
'_owc_setting_portal_url' => '',
'_owc_setting_portal_openpub_item_slug' => '',
'_owc_setting_use_portal_url' => 0,
'_owc_setting_use_escape_element' => 1,
'_owc_setting_openpub_expired_auto' => 0,
'_owc_setting_openpub_expired_auto_after_days' => 0
]
]);
\WP_Mock::userFunction('get_option', [
'return' => [
'_owc_setting_portal_url' => '',
'_owc_setting_portal_openpub_item_slug' => '',
'_owc_setting_use_portal_url' => 0,
'_owc_setting_use_escape_element' => 1,
'_owc_setting_openpub_expired_auto' => 0,
'_owc_setting_openpub_expired_auto_after_days' => 0
]
]);
}
protected function tearDown(): void
{
WP_Mock::tearDown();
}
/** @test */
public function check_registration_of_metaboxes()
{
$config = m::mock(Config::class);
$plugin = m::mock(Plugin::class);
$plugin->config = $config;
$plugin->loader = m::mock(Loader::class);
$service = new MetaboxServiceProvider($plugin);
$plugin->loader->shouldReceive('addAction')->withArgs([
'cmb2_admin_init',
$service,
'registerMetaboxes',
10,
0
])->once();
$plugin->loader->shouldReceive('addAction')->withArgs([
'admin_notices',
\Mockery::type(AdminNotice::class),
'upgradeAdminNotice',
10,
0
])->once();
$service->register();
$configMetaboxes = [
'base' => [
'id' => 'metadata',
'fields' => [
'general' => [
'testfield_noid' => [
'type' => 'heading'
],
'testfield1' => [
'id' => 'metabox_id1'
],
'testfield2' => [
'id' => 'metabox_id2'
]
]
]
],
'escape_element' => [
'id' => 'escape_element',
'fields' => [
'general' => [
'testfield_noid' => [
'type' => 'heading'
],
'testfield1' => [
'id' => 'metabox_id1'
],
'testfield2' => [
'id' => 'metabox_id2'
]
]
]
]
];
$config->shouldReceive('get')->with('cmb2_metaboxes')->once()->andReturn($configMetaboxes['base']);
$config->shouldReceive('get')->with('escape_element_metabox')->once()->andReturn($configMetaboxes['escape_element']);
$cmb2 = \Mockery::mock('CMB2');
$cmb2->shouldReceive('add_field')->with(['type' => 'heading']);
$cmb2->shouldReceive('add_field')->with(['id' => '_owc_metabox_id1']);
$cmb2->shouldReceive('add_field')->with(['id' => '_owc_metabox_id2']);
\WP_Mock::userFunction('new_cmb2_box', [
'return' => $cmb2,
]);
$service->registerMetaboxes();
$this->expectNotToPerformAssertions();
}
}