Skip to content

Commit

Permalink
Merge pull request magento#121 from magento-extensibility/ashsmith-86…
Browse files Browse the repository at this point in the history
…5-add-getParams-setParams-to-request-interface

[Github] Merge public Github commits
  • Loading branch information
otoolec committed Mar 5, 2015
2 parents 77b71ad + 2e9764c commit 3ab5b37
Show file tree
Hide file tree
Showing 40 changed files with 256 additions and 592 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class RequestTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->_model = new \Magento\TestFramework\Request(
$this->getMock('Magento\Framework\App\Route\ConfigInterface\Proxy', [], [], '', false),
$this->getMock('Magento\Framework\App\Request\PathInfoProcessorInterface', [], [], '', false),
$this->getMock('Magento\Framework\Stdlib\Cookie\CookieReaderInterface'),
$this->getMock('Magento\Framework\App\Route\ConfigInterface\Proxy', [], [], '', false),
$this->getMock('Magento\Framework\App\Request\PathInfoProcessorInterface'),
$this->getMock('Magento\Framework\ObjectManagerInterface')
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ protected function setUp()
{
$this->messageManager = $this->getMock('\Magento\Framework\Message\Manager', [], [], '', false);
$request = new \Magento\TestFramework\Request(
$this->getMock('Magento\Framework\App\Route\ConfigInterface\Proxy', [], [], '', false),
$this->getMock('Magento\Framework\App\Request\PathInfoProcessorInterface', [], [], '', false),
$this->getMock('Magento\Framework\Stdlib\Cookie\CookieReaderInterface'),
$this->getMock('Magento\Framework\App\Route\ConfigInterface\Proxy', [], [], '', false),
$this->getMock('Magento\Framework\App\Request\PathInfoProcessorInterface'),
$this->getMock('Magento\Framework\ObjectManagerInterface')
);
$response = new \Magento\TestFramework\Response(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2087,7 +2087,6 @@
['getFiles', 'Magento\Framework\App\Request\Http'],
['getAlias', 'Magento\Framework\App\Request\Http', 'Magento\Framework\HTTP\PhpEnvironment\Request'],
['setAlias', 'Magento\Framework\App\Request\Http', 'Magento\Framework\HTTP\PhpEnvironment\Request'],
['getParam', 'Magento\Framework\App\RequestInterface'],
[
'render',
'Magento\Framework\Webapi\ErrorProcessor',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SaveTest extends \PHPUnit_Framework_TestCase
/** @var \Magento\Backend\App\Action\Context|\PHPUnit_Framework_MockObject_MockObject */
protected $context;

/** @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */
/** @var \Magento\Framework\App\Request\Http|\PHPUnit_Framework_MockObject_MockObject */
protected $request;

/** @var \Magento\Framework\App\Response\Http|\PHPUnit_Framework_MockObject_MockObject */
Expand Down Expand Up @@ -150,13 +150,8 @@ protected function prepareContext()
->disableOriginalConstructor()
->getMock();

$this->request = $this->getMock(
'Magento\Framework\App\RequestInterface',
['getParam', 'getModuleName', 'setModuleName', 'getActionName', 'setActionName', 'getCookie', 'isSecure'],
[],
'',
false
);
$this->request = $this->getMockBuilder('Magento\Framework\App\Request\Http')
->disableOriginalConstructor()->getMock();
$this->response = $this->getMock('Magento\Framework\App\Response\Http', [], [], '', false);
$this->objectManager = $this->getMock('Magento\Framework\ObjectManagerInterface');
$this->eventManager = $this->getMock('Magento\Framework\Event\ManagerInterface', [], [], '', false);
Expand Down
17 changes: 2 additions & 15 deletions dev/tests/unit/testsuite/Magento/Checkout/Helper/CartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,8 @@ class CartTest extends \PHPUnit_Framework_TestCase

protected function setUp()
{
$this->requestMock = $this->getMock(
'\Magento\Framework\App\RequestInterface',
[
'getRouteName',
'getControllerName',
'getParam',
'setActionName',
'getActionName',
'setModuleName',
'getModuleName',
'getCookie',
'isAjax',
'isSecure',
]
);
$this->requestMock = $this->getMockBuilder('Magento\Framework\App\Request\Http')
->disableOriginalConstructor()->getMock();
$objectManagerHelper = new \Magento\TestFramework\Helper\ObjectManager($this);
/** @var \Magento\Framework\App\Helper\Context $context */
$context = $objectManagerHelper->getObject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class OnepageTest extends \PHPUnit_Framework_TestCase
/** @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
protected $storeManagerMock;

/** @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */
/** @var \Magento\Framework\App\Request\Http|\PHPUnit_Framework_MockObject_MockObject */
protected $requestMock;

/** @var \PHPUnit_Framework_MockObject_MockObject */
Expand Down Expand Up @@ -132,19 +132,8 @@ protected function setUp()
false
);
$this->storeManagerMock = $this->getMock('Magento\Store\Model\StoreManagerInterface');
$this->requestMock = $this->getMockBuilder('Magento\Framework\App\RequestInterface')
->setMethods([
'isAjax',
'getModuleName',
'setModuleName',
'getActionName',
'setActionName',
'getParam',
'getCookie',
'isSecure',
])
->getMock();

$this->requestMock = $this->getMockBuilder('Magento\Framework\App\Request\Http')
->disableOriginalConstructor()->getMock();
$this->addressFactoryMock = $this->getMock('Magento\Customer\Model\AddressFactory', [], [], '', false);
$this->formFactoryMock = $this->getMock('Magento\Customer\Model\Metadata\FormFactory', [], [], '', false);
$this->customerFactoryMock = $this->getMock('Magento\Customer\Model\CustomerFactory', [], [], '', false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,8 @@ protected function setUp()
$this->registrationMock = $this->getMock('\Magento\Customer\Model\Registration', [], [], '', false);
$this->redirectMock = $this->getMock('Magento\Framework\App\Response\RedirectInterface');
$this->response = $this->getMock('Magento\Framework\App\ResponseInterface');
$this->request = $this->getMockBuilder('Magento\Framework\App\RequestInterface')
->setMethods([
'isPost',
'getModuleName',
'setModuleName',
'getActionName',
'setActionName',
'getParam',
'getCookie',
'isSecure',
])
->getMock();
$this->request = $this->getMockBuilder('Magento\Framework\App\Request\Http')
->disableOriginalConstructor()->getMock();
$this->redirectResultMock = $this->getMock('Magento\Framework\Controller\Result\Redirect', [], [], '', false);

$this->redirectFactoryMock = $this->getMock(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class LoginPostTest extends \PHPUnit_Framework_TestCase
protected $object;

/**
* @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject
* @var \Magento\Framework\App\Request\Http|\PHPUnit_Framework_MockObject_MockObject
*/
protected $request;

Expand Down Expand Up @@ -98,18 +98,8 @@ class LoginPostTest extends \PHPUnit_Framework_TestCase

protected function setUp()
{
$this->request = $this->getMockBuilder('Magento\Framework\App\RequestInterface')
->setMethods([
'isPost',
'getModuleName',
'setModuleName',
'getActionName',
'setActionName',
'getParam',
'getCookie',
'isSecure',
])
->getMock();
$this->request = $this->getMockBuilder('Magento\Framework\App\Request\Http')
->disableOriginalConstructor()->getMock();
$this->response = $this->getMock(
'Magento\Framework\App\ResponseInterface',
['setRedirect', 'sendResponse'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class IndexTest extends \PHPUnit_Framework_TestCase
protected $context;

/**
* @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject
* @var \Magento\Framework\App\Request|\PHPUnit_Framework_MockObject_MockObject
*/
protected $requestMock;

Expand Down Expand Up @@ -62,20 +62,8 @@ class IndexTest extends \PHPUnit_Framework_TestCase

protected function setUp()
{
$this->requestMock = $this->getMockBuilder('Magento\Framework\App\RequestInterface')
->setMethods(
[
'getQuery',
'getModuleName',
'setModuleName',
'getActionName',
'setActionName',
'getParam',
'getCookie',
'isSecure',
]
)
->getMock();
$this->requestMock = $this->getMockBuilder('Magento\Framework\App\Request\Http')
->disableOriginalConstructor()->getMock();
$this->resultForwardFactoryMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\ForwardFactory')
->disableOriginalConstructor()
->setMethods(['create'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class LoginTest extends \PHPUnit_Framework_TestCase
protected $object;

/**
* @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject
* @var \Magento\Framework\App\Request\Http|\PHPUnit_Framework_MockObject_MockObject
*/
protected $request;

Expand Down Expand Up @@ -67,21 +67,8 @@ class LoginTest extends \PHPUnit_Framework_TestCase

protected function setUp()
{
$this->request = $this->getMockBuilder('Magento\Framework\App\RequestInterface')
->setMethods([
'isPost',
'getModuleName',
'setModuleName',
'getActionName',
'setActionName',
'getParam',
'getCookie',
'getContent',
'getMethod',
'isXmlHttpRequest',
'isSecure',
])
->getMock();
$this->request = $this->getMockBuilder('Magento\Framework\App\Request\Http')
->disableOriginalConstructor()->getMock();
$this->response = $this->getMock(
'Magento\Framework\App\ResponseInterface',
['setRedirect', 'sendResponse', 'representJson', 'setHttpResponseCode'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class FileTest extends AbstractFormTestCase
/** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\Filesystem */
protected $fileSystemMock;

/** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\App\RequestInterface */
/** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\App\Request\Http */
protected $requestMock;

/**
Expand All @@ -38,20 +38,8 @@ protected function setUp()
->disableOriginalConstructor()->getMock();
$this->fileSystemMock = $this->getMockBuilder('Magento\Framework\Filesystem')
->disableOriginalConstructor()->getMock();
$this->requestMock = $this->getMockBuilder('Magento\Framework\App\RequestInterface')
->setMethods(
[
'getParam',
'getParams',
'getModuleName',
'setModuleName',
'getActionName',
'setActionName',
'getCookie',
'isSecure',
]
)
->getMock();
$this->requestMock = $this->getMockBuilder('Magento\Framework\App\Request\Http')
->disableOriginalConstructor()->getMock();
$this->uploaderFactoryMock = $this->getMock('Magento\Framework\File\UploaderFactory', [], [], '', false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ public function testMatch(
) {
$this->_model = $this->_prepareMocksForTestMatch($request, $isVde, $isLoggedIn, $routers);
$this->assertEquals($matchedValue, $this->_model->match($request));
if ($isVde && $isLoggedIn) {
$this->assertEquals(self::TEST_PATH, $request->getPathInfo());
}
}

/**
Expand All @@ -79,30 +76,26 @@ public function testMatch(
*/
public function matchDataProvider()
{
$objectManagerMock = $this->getMock('Magento\Framework\ObjectManagerInterface');
$this->_cookieReaderMock = $this->getMock('Magento\Framework\Stdlib\Cookie\CookieReaderInterface');
$uri = self::TEST_HOST . '/' . self::VDE_FRONT_NAME . self::TEST_PATH;
$notVdeUrl = self::TEST_HOST . self::TEST_PATH;
$vdePath = '/' . self::VDE_FRONT_NAME . self::TEST_PATH;
$notVdePath = self::TEST_PATH;

$excludedRouters = ['admin' => 'admin router', 'vde' => 'vde router'];

$routerListMock = $this->getMock(
'\Magento\Framework\App\Route\ConfigInterface\Proxy',
[],
[],
'',
false
);

$infoProcessorMock = $this->getMock('Magento\Framework\App\Request\PathInfoProcessorInterface');
$infoProcessorMock->expects($this->any())->method('process')->will($this->returnArgument(1));

// test data to verify routers match logic
$matchedRequest = $this->getMock(
'Magento\Framework\App\Request\Http',
['_isFrontArea'],
[$routerListMock, $infoProcessorMock, $this->_cookieReaderMock, $objectManagerMock, $uri]
);
$notVdeRequest = $this->getMockBuilder('Magento\Framework\App\Request\Http')
->disableOriginalConstructor()->getMock();
$notVdeRequest->expects($this->any())
->method('getPathInfo')
->willReturn($vdePath);
$vdeRequest = $this->getMockBuilder('Magento\Framework\App\Request\Http')
->disableOriginalConstructor()->getMock();
$vdeRequest->expects($this->any())
->method('getPathInfo')
->willReturn($notVdePath);

$matchedController = $this->getMockForAbstractClass(
'Magento\Framework\App\Action\AbstractAction',
Expand All @@ -118,13 +111,13 @@ public function matchDataProvider()
)->method(
'match'
)->with(
$matchedRequest
$notVdeRequest
)->will(
$this->returnValue($matchedController)
);
$matchedRouter->expects($this->once())
->method('match')
->with($matchedRequest)
->with($notVdeRequest)
->will($this->returnValue($matchedController));

// method "match" will not be invoked for this router because controller will be found by first router
Expand All @@ -138,39 +131,23 @@ public function matchDataProvider()

$routers = [
'not vde request' => [
'$request' => $this->getMock(
'Magento\Framework\App\Request\Http', ['_isFrontArea'], [
$routerListMock,
$infoProcessorMock,
$this->_cookieReaderMock,
$objectManagerMock,
$notVdeUrl
]
),
'$request' => $vdeRequest,
'$isVde' => false,
'$isLoggedIn' => true,
],
'not logged as admin' => [
'$request' => $this->getMock(
'Magento\Framework\App\Request\Http',
['_isFrontArea'],
[$routerListMock, $infoProcessorMock, $this->_cookieReaderMock, $objectManagerMock, $uri]
),
'$request' => $notVdeRequest,
'$isVde' => true,
'$isLoggedIn' => false,
],
'no matched routers' => [
'$request' => $this->getMock(
'Magento\Framework\App\Request\Http',
['_isFrontArea'],
[$routerListMock, $infoProcessorMock, $this->_cookieReaderMock, $objectManagerMock, $uri]
),
'$request' => $notVdeRequest,
'$isVde' => true,
'$isLoggedIn' => true,
'$routers' => $excludedRouters
],
'matched routers' => [
'$request' => $matchedRequest,
'$request' => $notVdeRequest,
'$isVde' => true,
'$isLoggedIn' => true,
'$routers' => $matchedRouters,
Expand Down
Loading

0 comments on commit 3ab5b37

Please sign in to comment.