1 | <?php |
||
16 | class NcbiPubMedResponseParserTest extends \PHPUnit_Framework_TestCase { |
||
17 | |||
18 | public function testCanConstruct() { |
||
19 | |||
20 | $ncbiPubMedFilteredHttpResponseParser = $this->getMockBuilder( '\Onoi\Remi\Ncbi\NcbiPubMedFilteredHttpResponseParser' ) |
||
21 | ->disableOriginalConstructor() |
||
22 | ->getMock(); |
||
23 | |||
24 | $this->assertInstanceOf( |
||
25 | '\Onoi\Remi\ResponseParser', |
||
26 | new NcbiPubMedResponseParser( $ncbiPubMedFilteredHttpResponseParser ) |
||
27 | ); |
||
28 | } |
||
29 | |||
30 | public function testInterfaceMethods() { |
||
31 | |||
32 | $ncbiPubMedFilteredHttpResponseParser = $this->getMockBuilder( '\Onoi\Remi\Ncbi\NcbiPubMedFilteredHttpResponseParser' ) |
||
33 | ->disableOriginalConstructor() |
||
34 | ->getMock(); |
||
35 | |||
36 | $instance = new NcbiPubMedResponseParser( $ncbiPubMedFilteredHttpResponseParser ); |
||
37 | |||
38 | $this->assertNull( |
||
39 | $instance->usesCache() |
||
40 | ); |
||
41 | |||
42 | $this->assertNull( |
||
43 | $instance->getMessages() |
||
44 | ); |
||
45 | |||
46 | $this->assertNull( |
||
47 | $instance->getFilteredRecord() |
||
48 | ); |
||
49 | |||
50 | $this->assertNull( |
||
51 | $instance->getRawResponse( 42 ) |
||
52 | ); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @dataProvider idProvider |
||
57 | */ |
||
58 | public function testDoParseForId( $id, $type, $expects ) { |
||
59 | |||
60 | $record = $this->getMockBuilder( '\SCI\FilteredMetadata\BibliographicFilteredRecord' ) |
||
61 | ->disableOriginalConstructor() |
||
62 | ->getMock(); |
||
63 | |||
64 | $record->expects( $this->at( 0 ) ) |
||
65 | ->method( 'get' ) |
||
66 | ->with( $this->stringContains( 'ncbi-dbtype' ) ) |
||
67 | ->will( $this->returnValue( $type ) ); |
||
68 | |||
69 | $ncbiPubMedFilteredHttpResponseParser = $this->getMockBuilder( '\Onoi\Remi\Ncbi\NcbiPubMedFilteredHttpResponseParser' ) |
||
70 | ->disableOriginalConstructor() |
||
71 | ->getMock(); |
||
72 | |||
73 | $ncbiPubMedFilteredHttpResponseParser->expects( $this->any() ) |
||
74 | ->method( 'getFilteredRecord' ) |
||
75 | ->will( $this->returnValue( $record ) ); |
||
76 | |||
77 | $ncbiPubMedFilteredHttpResponseParser->expects( $expects ) |
||
78 | ->method( 'doFilterResponseFor' ); |
||
79 | |||
80 | $instance = new NcbiPubMedResponseParser( $ncbiPubMedFilteredHttpResponseParser ); |
||
81 | $instance->doFilterResponseFor( $id ); |
||
82 | } |
||
83 | |||
84 | public function idProvider() { |
||
85 | |||
86 | $provider[] = [ |
||
87 | 'abc', |
||
88 | 'pmc', |
||
89 | $this->never() |
||
90 | ]; |
||
91 | |||
92 | $provider[] = [ |
||
93 | 'abc', |
||
94 | 'pubmed', |
||
95 | $this->never() |
||
96 | ]; |
||
97 | |||
98 | $provider[] = [ |
||
99 | 'PMID54846467', |
||
100 | 'pmc', |
||
101 | $this->never() |
||
102 | ]; |
||
103 | |||
104 | $provider[] = [ |
||
105 | 'PMC54846467', |
||
106 | 'pmc', |
||
107 | $this->once() |
||
108 | ]; |
||
109 | |||
110 | $provider[] = [ |
||
111 | 'PMID54846467', |
||
112 | 'pmid', |
||
113 | $this->once() |
||
114 | ]; |
||
115 | |||
116 | $provider[] = [ |
||
117 | 'PMID54846467', |
||
118 | 'pubmed', |
||
119 | $this->once() |
||
120 | ]; |
||
121 | |||
122 | return $provider; |
||
123 | } |
||
124 | |||
125 | } |
||
126 |