WordPoints_Importers_Test   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 147
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 147
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 1

8 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 12 1
A tearDown() 0 19 4
A test_register() 0 15 1
A test_deregister() 0 8 1
A test_is_registered() 0 4 1
A test_is_registered_unregistered() 0 6 1
A test_get_unregistered_importer() 0 6 1
A test_get_importer() 0 7 1
1
<?php
2
3
/**
4
 * Testcase for the WordPoints_Importers class.
5
 *
6
 * @package WordPoints_Importer\Tests
7
 * @since 1.0.0
8
 */
9
10
/**
11
 * Tests for the WordPoints_Importers class.
12
 *
13
 * @since 1.0.0
14
 *
15
 * @group importers
16
 */
17
class WordPoints_Importers_Test extends WP_UnitTestCase {
18
19
	/**
20
	 * Backup of the importers when the test begins.
21
	 *
22
	 * @since 1.0.0
23
	 *
24
	 * @var array[]
25
	 */
26
	protected $_backup_importers;
27
28
	/**
29
	 * @since 1.0.0
30
	 */
31
	public function setUp() {
32
33
		parent::setUp();
34
35
		$this->_backup_importers = WordPoints_Importers::get();
36
37
		WordPoints_Importers::register(
38
			'test'
39
			, array( 'class' => 'WordPoints_Importer_Mock', 'name' => 'Test' )
40
		);
41
42
	}
43
44
	/**
45
	 * @since 1.0.0
46
	 */
47
	public function tearDown() {
48
49
		$importers = WordPoints_Importers::get();
50
51
		foreach ( $this->_backup_importers as $slug => $args ) {
52
53
			if ( ! isset( $importers[ $slug ] ) ) {
54
				WordPoints_Importers::register( $slug, $args );
55
			}
56
57
			unset( $importers[ $slug ] );
58
		}
59
60
		foreach ( $importers as $slug => $args ) {
61
			WordPoints_Importers::deregister( $slug );
62
		}
63
64
		parent::tearDown();
65
	}
66
67
	/**
68
	 * Test registration.
69
	 *
70
	 * @since 1.0.0
71
	 *
72
	 * @covers WordPoints_Importers::register
73
	 * @covers WordPoints_Importers::get
74
	 */
75
	public function test_register() {
76
77
		WordPoints_Importers::register(
78
			__METHOD__
79
			, array( 'class' => 'WordPoints_Importer_Mock', 'name' => 'Test' )
80
		);
81
82
		$importers = WordPoints_Importers::get();
83
84
		$this->assertArrayHasKey( 'test', $importers );
85
		$this->assertSame(
86
			array( 'class' => 'WordPoints_Importer_Mock', 'name' => 'Test' )
87
			, $importers['test']
88
		);
89
	}
90
91
	/**
92
	 * Test that deregister() deregisters the importer.
93
	 *
94
	 * @since 1.0.0
95
	 *
96
	 * @covers WordPoints_Importers::register
97
	 * @covers WordPoints_Importers::get
98
	 */
99
	public function test_deregister() {
100
101
		WordPoints_Importers::deregister( 'test' );
102
103
		$importers = WordPoints_Importers::get();
104
105
		$this->assertArrayNotHasKey( 'test', $importers );
106
	}
107
108
	/**
109
	 * Test that is_registered() returns true for a registered importer.
110
	 *
111
	 * @since 1.0.0
112
	 *
113
	 * @covers WordPoints_Importers::is_registered
114
	 */
115
	public function test_is_registered() {
116
117
		$this->assertTrue( WordPoints_Importers::is_registered( 'test' ) );
118
	}
119
120
	/**
121
	 * Test that is_registered() returns false for an unregistered importer.
122
	 *
123
	 * @since 1.0.0
124
	 *
125
	 * @covers WordPoints_Importers::is_registered
126
	 */
127
	public function test_is_registered_unregistered() {
128
129
		WordPoints_Importers::deregister( 'test' );
130
131
		$this->assertFalse( WordPoints_Importers::is_registered( 'test' ) );
132
	}
133
134
	/**
135
	 * Test that get_importer() returns false for an unregistered importer.
136
	 *
137
	 * @since 1.0.0
138
	 *
139
	 * @covers WordPoints_Importers::get_importer
140
	 */
141
	public function test_get_unregistered_importer() {
142
143
		WordPoints_Importers::deregister( 'test' );
144
145
		$this->assertFalse( WordPoints_Importers::get_importer( 'test' ) );
146
	}
147
148
	/**
149
	 * Test that get_importer() returns an importer object.
150
	 *
151
	 * @since 1.0.0
152
	 *
153
	 * @covers WordPoints_Importers::get_importer
154
	 */
155
	public function test_get_importer() {
156
157
		$this->assertInstanceOf(
158
			'WordPoints_Importer_Mock'
159
			, WordPoints_Importers::get_importer( 'test' )
160
		);
161
	}
162
163
}
164
165
// EOF
166