This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace SUC\Tests; |
||
4 | |||
5 | use SUC\ApiSummaryCardContentParser; |
||
6 | use SUC\CacheHelper; |
||
7 | use Onoi\BlobStore\BlobStore; |
||
8 | use Onoi\BlobStore\Container; |
||
9 | use ApiMain; |
||
10 | use ApiResult; |
||
11 | use FauxRequest; |
||
12 | use RequestContext; |
||
13 | use WebRequest; |
||
14 | use Title; |
||
15 | |||
16 | /** |
||
17 | * @covers \SUC\ApiSummaryCardContentParser |
||
18 | * @group summary-cards |
||
19 | * |
||
20 | * @license GNU GPL v2+ |
||
21 | * @since 1.0 |
||
22 | * |
||
23 | * @author mwjames |
||
24 | */ |
||
25 | class ApiSummaryCardContentParserTest extends \PHPUnit_Framework_TestCase { |
||
26 | |||
27 | protected function setUp() { |
||
28 | if ( version_compare( $GLOBALS['wgVersion'], '1.25', '<' ) ) { |
||
29 | $this->markTestSkipped( "Don't test < 1.25 API due to changes in 1.25." ); |
||
30 | } |
||
31 | } |
||
32 | |||
33 | public function testCanConstruct() { |
||
34 | |||
35 | $cacheHelper = $this->getMockBuilder( '\SUC\CacheHelper' ) |
||
36 | ->disableOriginalConstructor() |
||
37 | ->getMock(); |
||
38 | |||
39 | $instance = new ApiSummaryCardContentParser( |
||
40 | $this->newApiMain( array() ), |
||
41 | 'summarycards' |
||
42 | ); |
||
43 | |||
44 | $instance->setCacheHelper( $cacheHelper ); |
||
45 | |||
46 | $this->assertInstanceOf( |
||
47 | 'SUC\ApiSummaryCardContentParser', |
||
48 | $instance |
||
49 | ); |
||
50 | } |
||
51 | |||
52 | public function testExecuteOnEmptyRequest() { |
||
53 | |||
54 | $cacheHelper = $this->getMockBuilder( '\SUC\CacheHelper' ) |
||
55 | ->disableOriginalConstructor() |
||
56 | ->getMock(); |
||
57 | |||
58 | $instance = new ApiSummaryCardContentParser( |
||
59 | $this->newApiMain( array() ), |
||
60 | 'summarycards' |
||
61 | ); |
||
62 | |||
63 | $instance->setCacheHelper( $cacheHelper ); |
||
64 | $instance->execute(); |
||
65 | |||
66 | $this->assertEquals( |
||
67 | array( |
||
68 | 'summarycards' => array( |
||
69 | 'text' => '', |
||
70 | 'time' => false |
||
71 | ), |
||
72 | '_type' => 'assoc' |
||
73 | ), |
||
74 | $instance->getResult()->getResultData() |
||
75 | ); |
||
76 | } |
||
77 | |||
78 | public function testExecuteOnNonCachedParseRequest() { |
||
79 | |||
80 | $container = $this->getMockBuilder( Container::class ) |
||
81 | ->disableOriginalConstructor() |
||
82 | ->getMock(); |
||
83 | |||
84 | $blobStore = $this->getMockBuilder( BlobStore::class ) |
||
85 | ->disableOriginalConstructor() |
||
86 | ->getMock(); |
||
87 | |||
88 | $blobStore->expects( $this->atLeastOnce() ) |
||
89 | ->method( 'read' ) |
||
90 | ->will( $this->returnValue( $container ) ); |
||
91 | |||
92 | $cacheHelper = $this->getMockBuilder( CacheHelper::class ) |
||
93 | ->disableOriginalConstructor() |
||
94 | ->getMock(); |
||
95 | |||
96 | $cacheHelper->expects( $this->any() ) |
||
97 | ->method( 'getBlobStore' ) |
||
98 | ->will( $this->returnValue( $blobStore ) ); |
||
99 | |||
100 | $cacheHelper->expects( $this->atLeastOnce() ) |
||
101 | ->method( 'newTitleFromText' ) |
||
102 | ->will( $this->returnValue( Title::newFromText( __METHOD__ ) ) ); |
||
103 | |||
104 | $params = array( |
||
105 | 'text' => 'Some text', |
||
106 | 'title' => 'Foo' |
||
107 | ); |
||
108 | |||
109 | $instance = new ApiSummaryCardContentParser( |
||
110 | $this->newApiMain( $params ), |
||
111 | 'summarycards' |
||
112 | ); |
||
113 | |||
114 | $instance->setCacheHelper( $cacheHelper ); |
||
115 | $instance->execute(); |
||
116 | |||
117 | $result = $instance->getResult()->getResultData(); |
||
118 | |||
119 | $this->assertInternalType( |
||
120 | 'float', |
||
121 | $result['summarycards']['time']['parse'] |
||
122 | ); |
||
123 | } |
||
124 | |||
125 | public function testExecuteOnUntouchedTemplate() { |
||
126 | |||
127 | $container = $this->getMockBuilder( Container::class ) |
||
128 | ->disableOriginalConstructor() |
||
129 | ->getMock(); |
||
130 | |||
131 | $container->expects( $this->atLeastOnce() ) |
||
132 | ->method( 'has' ) |
||
133 | ->will( $this->returnValue( true ) ); |
||
134 | |||
135 | $blobStore = $this->getMockBuilder( BlobStore::class ) |
||
136 | ->disableOriginalConstructor() |
||
137 | ->getMock(); |
||
138 | |||
139 | $blobStore->expects( $this->atLeastOnce() ) |
||
140 | ->method( 'read' ) |
||
141 | ->will( $this->returnValue( $container ) ); |
||
142 | |||
143 | $cacheHelper = $this->getMockBuilder( CacheHelper::class ) |
||
144 | ->disableOriginalConstructor() |
||
145 | ->getMock(); |
||
146 | |||
147 | $cacheHelper->expects( $this->any() ) |
||
148 | ->method( 'getBlobStore' ) |
||
149 | ->will( $this->returnValue( $blobStore ) ); |
||
150 | |||
151 | $cacheHelper->expects( $this->atLeastOnce() ) |
||
152 | ->method( 'newTitleFromText' ) |
||
153 | ->will( $this->returnValue( Title::newFromText( __METHOD__ ) ) ); |
||
154 | |||
155 | $params = array( |
||
156 | 'text' => 'Some text', |
||
157 | 'title' => 'Foo', |
||
158 | 'template' => 'Bar' |
||
159 | ); |
||
160 | |||
161 | $instance = new ApiSummaryCardContentParser( |
||
162 | $this->newApiMain( $params ), |
||
163 | 'summarycards' |
||
164 | ); |
||
165 | |||
166 | $instance->setCacheHelper( $cacheHelper ); |
||
167 | $instance->execute(); |
||
168 | |||
169 | $result = $instance->getResult()->getResultData(); |
||
170 | |||
171 | $this->assertInternalType( |
||
172 | 'float', |
||
173 | $result['summarycards']['time']['cached'] |
||
174 | ); |
||
175 | } |
||
176 | |||
177 | private function newApiMain( array $params ) { |
||
178 | return new ApiMain( $this->newRequestContext( $params ), true ); |
||
179 | } |
||
180 | |||
181 | private function newRequestContext( $request = array() ) { |
||
182 | |||
183 | $context = new RequestContext(); |
||
184 | |||
185 | if ( $request instanceof WebRequest ) { |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
186 | $context->setRequest( $request ); |
||
187 | } else { |
||
188 | $context->setRequest( new FauxRequest( $request, true ) ); |
||
189 | } |
||
190 | |||
191 | $user = $this->getMockBuilder( '\User' ) |
||
192 | ->disableOriginalConstructor() |
||
193 | ->getMock(); |
||
194 | |||
195 | $context->setUser( $user ); |
||
196 | |||
197 | return $context; |
||
198 | } |
||
199 | |||
200 | } |
||
201 |