|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package wpmautic\tests |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Test generic plugin behaviour |
|
8
|
|
|
*/ |
|
9
|
|
|
class PluginTest extends WP_UnitTestCase |
|
|
|
|
|
|
10
|
|
|
{ |
|
11
|
|
|
public function test_plugin_is_loaded() |
|
12
|
|
|
{ |
|
13
|
|
|
$active = get_option( 'active_plugins', array() ); |
|
14
|
|
|
$this->assertContains('mautic-wordpress/wpmautic.php', $active); |
|
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
$this->assertTrue(function_exists('wpmautic_option')); |
|
|
|
|
|
|
17
|
|
|
$this->assertTrue(function_exists('wpmautic_inject_script')); |
|
|
|
|
|
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function test_action_loaded() |
|
21
|
|
|
{ |
|
22
|
|
|
$this->assertTrue(false !== has_action('admin_menu', 'wpmautic_settings')); |
|
|
|
|
|
|
23
|
|
|
$this->assertTrue(false !== has_action('plugins_loaded', 'wpmautic_injector')); |
|
|
|
|
|
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function test_filter_loaded() |
|
27
|
|
|
{ |
|
28
|
|
|
$this->assertTrue(false !== has_filter('plugin_action_links', 'wpmautic_plugin_actions')); |
|
|
|
|
|
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function test_settings_link_is_present() |
|
32
|
|
|
{ |
|
33
|
|
|
$links = apply_filters('plugin_action_links', array(), 'mautic-wordpress/wpmautic.php'); |
|
34
|
|
|
|
|
35
|
|
|
$this->assertCount(1, $links); |
|
|
|
|
|
|
36
|
|
|
$this->assertContains('options-general.php?page=wpmautic', $links[0]); |
|
|
|
|
|
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function test_option_page_is_loaded() |
|
40
|
|
|
{ |
|
41
|
|
|
$current_user = get_current_user_id(); |
|
42
|
|
|
wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); |
|
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
$this->assertEmpty(menu_page_url('wpmautic', false)); |
|
|
|
|
|
|
45
|
|
|
wpmautic_settings(); |
|
46
|
|
|
$this->assertEquals( |
|
|
|
|
|
|
47
|
|
|
admin_url( 'options-general.php?page=wpmautic' ), |
|
48
|
|
|
menu_page_url('wpmautic', false) |
|
49
|
|
|
); |
|
50
|
|
|
|
|
51
|
|
|
wp_set_current_user( $current_user ); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.