|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Brain\Monkey; |
|
4
|
|
|
use Brain\Monkey\Functions; |
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
|
|
7
|
|
|
class MslsSelectTest extends TestCase { |
|
8
|
|
|
|
|
9
|
|
|
public function get_test() { |
|
10
|
|
|
Functions\expect( 'get_option' )->once()->andReturn( [] ); |
|
11
|
|
|
Functions\expect( 'update_option' )->once(); |
|
12
|
|
|
|
|
13
|
|
|
return new MslsSelect(); |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
public function test_get_tags() { |
|
17
|
|
|
$test = $this->get_test(); |
|
18
|
|
|
|
|
19
|
|
|
$this->assertNotEmpty( $test->get_tags() ); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function test_init_admin_true() { |
|
23
|
|
|
Functions\expect( 'get_option' )->once()->andReturn( [ 'output_current_blog' => 1 ] ); |
|
24
|
|
|
Functions\expect( 'is_admin' )->once()->andReturn( true ); |
|
25
|
|
|
|
|
26
|
|
|
$this->assertInstanceOf( MslsSelect::class, MslsSelect::init() ); |
|
27
|
|
|
|
|
28
|
|
|
$this->assertFalse( has_action('wp_enqueue_scripts', [ MslsSelect::class, 'enqueue_scripts' ] ) ); |
|
29
|
|
|
$this->assertFalse( has_filter('msls_output_get_tags', [ MslsSelect::class, 'get_tags' ] ) ); |
|
30
|
|
|
$this->assertFalse( has_filter('msls_output_get', [ MslsSelect::class, 'output_get' ] ) ); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function test_init_admin_false() { |
|
34
|
|
|
Functions\expect( 'get_option' )->once()->andReturn( [ 'output_current_blog' => 1 ] ); |
|
35
|
|
|
Functions\expect( 'is_admin' )->once()->andReturn( false ); |
|
36
|
|
|
|
|
37
|
|
|
$this->assertInstanceOf( MslsSelect::class, MslsSelect::init() ); |
|
38
|
|
|
|
|
39
|
|
|
$this->assertTrue( has_action('wp_enqueue_scripts', [ MslsSelect::class, 'enqueue_scripts' ] ) ); |
|
40
|
|
|
$this->assertTrue( has_filter('msls_output_get_tags', [ MslsSelect::class, 'get_tags' ] ) ); |
|
41
|
|
|
$this->assertTrue( has_filter('msls_output_get', [ MslsSelect::class, 'output_get' ] ) ); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function test_output_get_true() { |
|
45
|
|
|
$test = $this->get_test(); |
|
46
|
|
|
|
|
47
|
|
|
$url = '/test/'; |
|
48
|
|
|
$link = (object) [ 'txt' => 'Test' ]; |
|
49
|
|
|
|
|
50
|
|
|
$expected = '<option value="/test/" selected="selected">Test</option>'; |
|
51
|
|
|
|
|
52
|
|
|
$this->assertEquals( $expected, $test->output_get( $url, $link, true ) ); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function test_output_get_false() { |
|
56
|
|
|
$test = $this->get_test(); |
|
57
|
|
|
|
|
58
|
|
|
$url = '/test/'; |
|
59
|
|
|
$link = (object) [ 'txt' => 'Test' ]; |
|
60
|
|
|
|
|
61
|
|
|
$expected = '<option value="/test/">Test</option>'; |
|
62
|
|
|
|
|
63
|
|
|
$this->assertEquals( $expected, $test->output_get( $url, $link, false ) ); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
protected function setUp(): void { |
|
67
|
|
|
parent::setUp(); |
|
68
|
|
|
Monkey\setUp(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
protected function tearDown(): void { |
|
72
|
|
|
Monkey\tearDown(); |
|
73
|
|
|
parent::tearDown(); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|