Passed
Pull Request — master (#136)
by None
04:09
created

ResourceIdentifierStringValueTest::doiLinkedTextProvider()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 107

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 107
rs 8
c 0
b 0
f 0
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace SCI\Tests\DataValues;
4
5
use SCI\DataValues\ResourceIdentifierStringValue;
6
7
/**
8
 * @covers \SCI\DataValues\ResourceIdentifierStringValue
9
 * @group semantic-cite
10
 *
11
 * @license GNU GPL v2+
12
 * @since 1.0
13
 *
14
 * @author mwjames
15
 */
16
class ResourceIdentifierStringValueTest extends \PHPUnit_Framework_TestCase {
17
18
	/**
19
	 * @dataProvider typeProvider
20
	 */
21
	public function testCanConstruct( $type ) {
22
23
		$this->assertInstanceOf(
24
			'\SCI\DataValues\ResourceIdentifierStringValue',
25
			new ResourceIdentifierStringValue()
26
		);
27
	}
28
29
	/**
30
	 * @dataProvider doiNonLinkedTextProvider
31
	 */
32
	public function testNonLinkedText( $type, $value, $expectedWikiText, $expectedHtmlText ) {
33
34
		$instance = new ResourceIdentifierStringValue( $type );
35
		$instance->setUserValue( $value );
36
37
		$this->assertEquals(
38
			$expectedWikiText,
39
			$instance->getShortWikiText()
40
		);
41
42
		$this->assertEquals(
43
			$expectedWikiText,
44
			$instance->getLongWikiText()
45
		);
46
47
		$this->assertEquals(
48
			$expectedHtmlText,
49
			$instance->getShortHTMLText()
50
		);
51
52
		$this->assertEquals(
53
			$expectedHtmlText,
54
			$instance->getLongHTMLText()
55
		);
56
	}
57
58
	/**
59
	 * @dataProvider doiLinkedTextProvider
60
	 */
61
	public function testLinkedText( $type, $value, $expectedWikiText, $expectedHtmlText ) {
62
63
		$instance = new ResourceIdentifierStringValue( $type );
64
		$instance->setUserValue( $value );
65
66
		$this->assertEquals(
67
			$expectedWikiText,
68
			$instance->getShortWikiText( 'foo' )
69
		);
70
71
		$this->assertEquals(
72
			$expectedWikiText,
73
			$instance->getLongWikiText( 'foo' )
74
		);
75
76
		$this->assertEquals(
77
			$expectedHtmlText,
78
			$instance->getShortHTMLText( 'foo' )
79
		);
80
81
		$this->assertEquals(
82
			$expectedHtmlText,
83
			$instance->getLongHTMLText( 'foo' )
84
		);
85
	}
86
87
	/**
88
	 * @dataProvider outputFormattedTextProvider
89
	 */
90
	public function testOutputFormattedText( $type, $value, $format, $expectedWikiText, $expectedHtmlText ) {
91
92
		$instance = new ResourceIdentifierStringValue( $type );
93
		$instance->setUserValue( $value );
94
		$instance->setOutputFormat( $value );
95
96
		$this->assertEquals(
97
			$expectedWikiText,
98
			$instance->getShortWikiText()
99
		);
100
101
		$this->assertEquals(
102
			$expectedWikiText,
103
			$instance->getLongWikiText()
104
		);
105
106
		$this->assertEquals(
107
			$expectedHtmlText,
108
			$instance->getShortHTMLText()
109
		);
110
111
		$this->assertEquals(
112
			$expectedHtmlText,
113
			$instance->getLongHTMLText()
114
		);
115
	}
116
117
	public function typeProvider() {
118
119
		$provider[] = [
120
			'_sci_doi',
121
		];
122
123
		$provider[] = [
124
			'_sci_viaf',
125
		];
126
127
		$provider[] = [
128
			'_sci_oclc',
129
		];
130
131
		$provider[] = [
132
			'_sci_olid',
133
		];
134
135
		$provider[] = [
136
			'_sci_pmcid',
137
		];
138
139
		$provider[] = [
140
			'_sci_pmid',
141
		];
142
143
		return $provider;
144
	}
145
146
	public function doiNonLinkedTextProvider() {
147
148
		// DOI
149
150
		$provider[] = [
151
			'_sci_doi',
152
			'foo',
153
			'',
154
			''
155
		];
156
157
		$provider[] = [
158
			'_sci_doi',
159
			'10.1000/123456',
160
			'10.1000/123456',
161
			'10.1000/123456'
162
		];
163
164
		$provider[] = [
165
			'_sci_doi',
166
			'http://dx.doi.org/10.1000/123456',
167
			'10.1000/123456',
168
			'10.1000/123456'
169
		];
170
171
		$provider[] = [
172
			'_sci_doi',
173
			'http://dx.doi.org/10.1000/abc.456',
174
			'10.1000/abc.456',
175
			'10.1000/abc.456'
176
		];
177
178
		// PMC
179
180
		$provider[] = [
181
			'_sci_pmcid',
182
			'foo',
183
			'',
184
			''
185
		];
186
187
		$provider[] = [
188
			'_sci_pmcid',
189
			'PMC123456',
190
			'PMC123456',
191
			'PMC123456'
192
		];
193
194
		// VIAF
195
196
		$provider[] = [
197
			'_sci_viaf',
198
			'foo',
199
			'',
200
			''
201
		];
202
203
		$provider[] = [
204
			'_sci_viaf',
205
			'VIAF123456',
206
			'123456',
207
			'123456'
208
		];
209
210
		// OCLC
211
212
		$provider[] = [
213
			'_sci_oclc',
214
			'foo',
215
			'',
216
			''
217
		];
218
219
		$provider[] = [
220
			'_sci_oclc',
221
			'OCLC123456',
222
			'123456',
223
			'123456'
224
		];
225
226
		// PMID
227
228
		$provider[] = [
229
			'_sci_pmid',
230
			'foo',
231
			'',
232
			''
233
		];
234
235
		$provider[] = [
236
			'_sci_pmid',
237
			'PMID123456',
238
			'123456',
239
			'123456'
240
		];
241
242
		// OLID
243
244
		$provider[] = [
245
			'_sci_olid',
246
			'foo',
247
			'',
248
			''
249
		];
250
251
		$provider[] = [
252
			'_sci_olid',
253
			'OL123456M',
254
			'OL123456M',
255
			'OL123456M'
256
		];
257
258
		return $provider;
259
	}
260
261
	public function doiLinkedTextProvider() {
262
263
		// DOI
264
265
		$provider[] = [
266
			'_sci_doi',
267
			'foo',
268
			'',
269
			''
270
		];
271
272
		$provider[] = [
273
			'_sci_doi',
274
			'10.1000/123456',
275
			'<span class="plainlinks">[https://doi.org/10.1000%2F123456 10.1000/123456]</span>',
276
			'<a href="https://doi.org/10.1000/123456" target="_blank">10.1000/123456</a>'
277
		];
278
279
		$provider[] = [
280
			'_sci_doi',
281
			'http://dx.doi.org/10.1000/123456',
282
			'<span class="plainlinks">[https://doi.org/10.1000%2F123456 10.1000/123456]</span>',
283
			'<a href="https://doi.org/10.1000/123456" target="_blank">10.1000/123456</a>'
284
		];
285
286
		// PMC
287
288
		$provider[] = [
289
			'_sci_pmcid',
290
			'foo',
291
			'',
292
			''
293
		];
294
295
		$provider[] = [
296
			'_sci_pmcid',
297
			'PMC123456',
298
			'<span class="plainlinks">[https://www.ncbi.nlm.nih.gov/pmc/PMC123456 PMC123456]</span>',
299
			'<a href="https://www.ncbi.nlm.nih.gov/pmc/PMC123456" target="_blank">PMC123456</a>'
300
		];
301
302
		// VIAF
303
304
		$provider[] = [
305
			'_sci_viaf',
306
			'foo',
307
			'',
308
			''
309
		];
310
311
		$provider[] = [
312
			'_sci_viaf',
313
			'VIAF123456',
314
			'<span class="plainlinks">[https://viaf.org/viaf/123456 123456]</span>',
315
			'<a href="https://viaf.org/viaf/123456" target="_blank">123456</a>'
316
		];
317
318
		// OCLC
319
320
		$provider[] = [
321
			'_sci_oclc',
322
			'foo',
323
			'',
324
			''
325
		];
326
327
		$provider[] = [
328
			'_sci_oclc',
329
			'OCLC123456',
330
			'<span class="plainlinks">[https://www.worldcat.org/oclc/123456 123456]</span>',
331
			'<a href="https://www.worldcat.org/oclc/123456" target="_blank">123456</a>'
332
		];
333
334
		// PMID
335
336
		$provider[] = [
337
			'_sci_pmid',
338
			'foo',
339
			'',
340
			''
341
		];
342
343
		$provider[] = [
344
			'_sci_pmid',
345
			'PMID123456',
346
			'<span class="plainlinks">[https://www.ncbi.nlm.nih.gov/pubmed/123456 123456]</span>',
347
			'<a href="https://www.ncbi.nlm.nih.gov/pubmed/123456" target="_blank">123456</a>'
348
		];
349
350
		// OLID
351
352
		$provider[] = [
353
			'_sci_olid',
354
			'foo',
355
			'',
356
			''
357
		];
358
359
		$provider[] = [
360
			'_sci_olid',
361
			'OL123456M',
362
			'<span class="plainlinks">[https://openlibrary.org/books/OL123456M OL123456M]</span>',
363
			'<a href="https://openlibrary.org/books/OL123456M" target="_blank">OL123456M</a>'
364
		];
365
366
		return $provider;
367
	}
368
369
	public function outputFormattedTextProvider() {
370
371
		// DOI
372
373
		$provider[] = [
374
			'_sci_doi',
375
			'10.1000/123456',
376
			'-',
377
			'10.1000/123456',
378
			'10.1000/123456'
379
		];
380
381
		$provider[] = [
382
			'_sci_doi',
383
			'http://dx.doi.org/10.1000/123456',
384
			'-',
385
			'10.1000/123456',
386
			'10.1000/123456'
387
		];
388
389
		return$provider;
390
	}
391
392
}
393