Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RouteTest.php
Go to the documentation of this file.
1 <?php
9 
10 use \Magento\Webapi\Controller\Rest\Router\Route;
11 
14 
15 class RouteTest extends \PHPUnit\Framework\TestCase
16 {
20  protected $objectManager;
21 
25  protected $request;
26 
27  protected function setUp()
28  {
29  $this->objectManager = new ObjectManager($this);
30 
31  $this->request = $this->getMockBuilder(\Magento\Framework\App\RequestInterface::class)
32  ->setMethods(['getPathInfo'])
33  ->getMockForAbstractClass();
34  }
35 
41  public function testResourceName()
42  {
44  $model = $this->objectManager->getObject(
45  \Magento\Webapi\Controller\Rest\Router\Route::class,
46  ['route' => '/V1/one']
47  );
48 
50  $this->assertNull($model->getServiceClass(), 'New object has a set Resource name.');
52  $resourceName = 'Resource name';
53  $model->setServiceClass($resourceName);
55  $this->assertEquals($resourceName, $model->getServiceClass(), 'Resource name is wrong.');
56  }
57 
65  public function testRoute($route, $path, $params)
66  {
68  $model = $this->objectManager->getObject(
69  \Magento\Webapi\Controller\Rest\Router\Route::class,
70  ['route' => $route]
71  );
72 
73  $this->request->expects($this->once())
74  ->method('getPathInfo')
75  ->willReturn($path);
76 
77  $match = $model->match($this->request);
78  $this->assertEquals($params, $match);
79  }
80 
84  public function dataProviderRoutes()
85  {
86  return [
87  // Success
88  ['/V1/one', '/V1/one', []],
89  ['/V1/one/:twoValue', '/V1/one/2', ['twoValue' => 2]],
90  ['/V1/one/two', '/V1/one/two', []],
91  ['/V1/one/two/:threeValue', '/V1/one/two/3', ['threeValue' => 3]],
92  ['/V1/one/:twoValue/three', '/V1/one/2/three', ['twoValue' => 2]],
93  ['/V1/one/:twoValue/three/:fourValue', '/V1/one/2/three/4', ['twoValue' => 2, 'fourValue' => 4]],
94  ['/V1/one/:twoValue/three/four', '/V1/one/2/three/four', ['twoValue' => 2]],
95  ['/V1/one/two/:threeValue/four/:fiveValue', '/V1/one/two/3/four/5', ['threeValue' => 3, 'fiveValue' => 5]],
96 
97  ['/v1/One', '/v1/One', []],
98 
99  ['/v1/oNe/:TwoValue', '/v1/oNe/2', ['TwoValue' => 2]],
100  ['/v1/onE/:twovalue', '/v1/onE/2', ['twovalue' => 2]],
101 
102  ['/V1/one-one', '/V1/one-one', []],
103  ['/V1/one-one/:twoValue', '/V1/one-one/2', ['twoValue' => 2]],
104  ['/V1/one_one/:two-value', '/V1/one_one/2', ['two-value' => 2]],
105  ['/V1/one-one/:two_value', '/V1/one-one/2', ['two_value' => 2]],
106 
107  // Error
108  ['/v1/oNe', '/V1/one', false],
109  ['/v1/onE', '/V1/oNe', false],
110  ['/v1/One/:twoValue', '/V1/one/2', false],
111  ['/V1/one', '/V1/two', false],
112  ['/V1/one/:twoValue', '/V1/one', false],
113  ['/V1/one/two', '/V1/one', false],
114  ['/V1/one/two', '/V1/one/two/three', false],
115  ['/V1/one/:twoValue/three', '/V1/one/two/3', false],
116  ];
117  }
118 }
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18