MslsSelectTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 0
Metric Value
wmc 8
lcom 2
cbo 3
dl 0
loc 69
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A get_test() 0 6 1
A test_get_tags() 0 5 1
A test_init_admin_true() 0 10 1
A test_init_admin_false() 0 10 1
A test_output_get_true() 0 10 1
A test_output_get_false() 0 10 1
A setUp() 0 4 1
A tearDown() 0 4 1
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->assertSame( 10, has_action( 'wp_enqueue_scripts', [ MslsSelect::class, 'enqueue_scripts' ] ) );
40
		$this->assertSame( 10, has_filter( 'msls_output_get_tags', [ MslsSelect::class, 'get_tags' ] ) );
41
		$this->assertSame( 10, 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