Skip to content

Commit 8d448eb

Browse files
author
Oleksii Korshenko
committed
MAGETWO-52493: Bug Fixes Contribution
- fixed unit tests
1 parent cd09ee1 commit 8d448eb

File tree

1 file changed

+0
-101
lines changed

1 file changed

+0
-101
lines changed

app/code/Magento/Webapi/Test/Unit/Controller/RestTest.php

Lines changed: 0 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -228,106 +228,5 @@ public function testDispatchAllSchemaRequest()
228228
$this->_restController->dispatch($this->_requestMock);
229229
$this->assertEquals($schema, $this->_responseMock->getBody());
230230
}
231-
232-
/**
233-
* Test Secure Request and Secure route combinations
234-
*
235-
* @dataProvider dataProviderSecureRequestSecureRoute
236-
*/
237-
public function testSecureRouteAndRequest($isSecureRoute, $isSecureRequest)
238-
{
239-
240-
$this->deploymentConfigMock->expects($this->once())
241-
->method('get')
242-
->with('x-frame-options')
243-
->willReturn('SAMEORIGIN');
244-
245-
$this->_responseMock->expects($this->once())->method('setHeader')->with('X-Frame-Options', 'SAMEORIGIN');
246-
247-
$this->_serviceMock->expects($this->any())->method(self::SERVICE_METHOD)->will($this->returnValue([]));
248-
$this->_routeMock->expects($this->any())->method('isSecure')->will($this->returnValue($isSecureRoute));
249-
$this->_routeMock->expects($this->once())->method('getParameters')->will($this->returnValue([]));
250-
$this->_routeMock->expects($this->any())->method('getAclResources')->will($this->returnValue(['1']));
251-
$this->_requestMock->expects($this->any())->method('getRequestData')->will($this->returnValue([]));
252-
$this->_requestMock->expects($this->any())->method('isSecure')->will($this->returnValue($isSecureRequest));
253-
$this->_authorizationMock->expects($this->once())->method('isAllowed')->will($this->returnValue(true));
254-
$this->serviceInputProcessorMock->expects($this->any())->method('process')->will($this->returnValue([]));
255-
$this->_restController->dispatch($this->_requestMock);
256-
$this->assertFalse($this->_responseMock->isException());
257-
}
258-
259-
/**
260-
* Data provider for testSecureRouteAndRequest.
261-
*
262-
* @return array
263-
*/
264-
public function dataProviderSecureRequestSecureRoute()
265-
{
266-
// Each array contains return type for isSecure method of route and request objects.
267-
return [[true, true], [false, true], [false, false]];
268-
}
269-
270-
/**
271-
* Test insecure request for a secure route
272-
*/
273-
public function testInSecureRequestOverSecureRoute()
274-
{
275-
$this->_serviceMock->expects($this->any())->method(self::SERVICE_METHOD)->will($this->returnValue([]));
276-
$this->_routeMock->expects($this->any())->method('isSecure')->will($this->returnValue(true));
277-
$this->_routeMock->expects($this->any())->method('getAclResources')->will($this->returnValue(['1']));
278-
$this->_requestMock->expects($this->any())->method('isSecure')->will($this->returnValue(false));
279-
$this->_authorizationMock->expects($this->once())->method('isAllowed')->will($this->returnValue(true));
280-
281-
// Override default prepareResponse. It should never be called in this case
282-
$this->_responseMock->expects($this->never())->method('prepareResponse');
283-
284-
$this->_restController->dispatch($this->_requestMock);
285-
$this->assertTrue($this->_responseMock->isException());
286-
$exceptionArray = $this->_responseMock->getException();
287-
$this->assertEquals('Operation allowed only in HTTPS', $exceptionArray[0]->getMessage());
288-
$this->assertEquals(\Magento\Framework\Webapi\Exception::HTTP_BAD_REQUEST, $exceptionArray[0]->getHttpCode());
289-
}
290-
291-
public function testAuthorizationFailed()
292-
{
293-
$this->_authorizationMock->expects($this->once())->method('isAllowed')->will($this->returnValue(false));
294-
$this->_oauthServiceMock->expects(
295-
$this->any())->method('validateAccessTokenRequest')->will($this->returnValue('fred')
296-
);
297-
$this->_routeMock->expects($this->any())->method('getAclResources')->will($this->returnValue(['5', '6']));
298-
299-
$this->_restController->dispatch($this->_requestMock);
300-
/** Ensure that response contains proper error message. */
301-
$expectedMsg = 'Consumer is not authorized to access 5, 6';
302-
$this->assertTrue($this->_responseMock->isException());
303-
$exceptionArray = $this->_responseMock->getException();
304-
$this->assertEquals($expectedMsg, $exceptionArray[0]->getMessage());
305-
}
306-
307-
public function testGetMethodAllStoresInvalid()
308-
{
309-
$this->_routeMock->expects($this->any())->method('getAclResources')->will($this->returnValue(['1']));
310-
$this->_authorizationMock->expects($this->any())->method('isAllowed')->will($this->returnValue(true));
311-
$this->storeMock->expects($this->once())->method('getCode')->willReturn('admin');
312-
$this->_requestMock->expects($this->once())->method('getMethod')->willReturn('get');
313-
314-
$this->_restController->dispatch($this->_requestMock);
315-
316-
$this->assertTrue($this->_responseMock->isException());
317-
$this->assertSame(
318-
"Cannot perform GET operation with store code 'all'",
319-
$this->_responseMock->getException()[0]->getMessage()
320-
);
321-
}
322231
}
323232

324-
class TestService
325-
{
326-
/**
327-
* @return null
328-
*/
329-
public function testMethod()
330-
{
331-
return null;
332-
}
333-
}

0 commit comments

Comments
 (0)