Skip to content

Commit 911fe32

Browse files
committed
MC-5806: Detection of URL dependencies does not work for the Dependency static test
1 parent b4ef1f3 commit 911fe32

File tree

6 files changed

+144
-22
lines changed

6 files changed

+144
-22
lines changed

app/code/Magento/Catalog/Block/Adminhtml/Product/Grid.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Magento\Store\Model\Store;
99

1010
/**
11+
* Catalog product grid
12+
*
1113
* @api
1214
* @since 100.0.2
1315
*/

app/code/Magento/Checkout/Controller/Onepage/SaveOrder.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66

77
namespace Magento\Checkout\Controller\Onepage;
88

9+
use Magento\Framework\App\Action\HttpPostActionInterface;
910
use Magento\Framework\DataObject;
1011
use Magento\Framework\Exception\PaymentException;
1112

12-
class SaveOrder extends \Magento\Checkout\Controller\Onepage
13+
/**
14+
* One Page Checkout saveOrder action
15+
*/
16+
class SaveOrder extends \Magento\Checkout\Controller\Onepage implements HttpPostActionInterface
1317
{
1418
/**
1519
* Create order action

app/code/Magento/Paypal/Model/Payflow/Service/Request/SecureToken.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function requestToken(Quote $quote)
6969
$request->setSecuretokenid($this->mathRandom->getUniqueHash());
7070
$request->setReturnurl($this->url->getUrl('paypal/transparent/response'));
7171
$request->setErrorurl($this->url->getUrl('paypal/transparent/response'));
72-
$request->setCancelurl('');
72+
$request->setCancelurl($this->url->getUrl('paypal/transparent/response'));
7373
$request->setDisablereceipt('TRUE');
7474
$request->setSilenttran('TRUE');
7575

app/code/Magento/Review/Test/Unit/Block/Adminhtml/RssTest.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1010

11+
/**
12+
* Test RSS adminhtml block
13+
*/
1114
class RssTest extends \PHPUnit\Framework\TestCase
1215
{
1316
/**
@@ -35,6 +38,9 @@ class RssTest extends \PHPUnit\Framework\TestCase
3538
*/
3639
protected $urlBuilder;
3740

41+
/**
42+
* @inheritDoc
43+
*/
3844
protected function setUp()
3945
{
4046
$this->storeManagerInterface = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
@@ -51,18 +57,22 @@ protected function setUp()
5157
);
5258
}
5359

60+
/**
61+
* @return void
62+
*/
5463
public function testGetRssData()
5564
{
65+
$rssUrl = '';
5666
$rssData = [
5767
'title' => 'Pending product review(s)',
5868
'description' => 'Pending product review(s)',
59-
'link' => 'http://rss.magento.com',
69+
'link' => $rssUrl,
6070
'charset' => 'UTF-8',
6171
'entries' => [
6272
'title' => 'Product: "Product Name" reviewed by: Product Nick',
6373
'link' => 'http://product.magento.com',
6474
'description' => [
65-
'rss_url' => 'http://rss.magento.com',
75+
'rss_url' => $rssUrl,
6676
'name' => 'Product Name',
6777
'summary' => 'Product Title',
6878
'review' => 'Product Detail',
@@ -71,7 +81,6 @@ public function testGetRssData()
7181
],
7282
],
7383
];
74-
$rssUrl = 'http://rss.magento.com';
7584
$productModel = $this->createPartialMock(\Magento\Catalog\Model\ResourceModel\Product::class, [
7685
'getStoreId',
7786
'getId',
@@ -118,16 +127,25 @@ public function testGetRssData()
118127
$this->assertContains($rssData['entries']['description']['store'], $data['entries'][0]['description']);
119128
}
120129

130+
/**
131+
* @return void
132+
*/
121133
public function testGetCacheLifetime()
122134
{
123135
$this->assertEquals(0, $this->block->getCacheLifetime());
124136
}
125137

138+
/**
139+
* @return void
140+
*/
126141
public function testIsAllowed()
127142
{
128143
$this->assertEquals(true, $this->block->isAllowed());
129144
}
130145

146+
/**
147+
* @return void
148+
*/
131149
public function testGetFeeds()
132150
{
133151
$this->assertEquals([], $this->block->getFeeds());

dev/tests/static/framework/Magento/TestFramework/Dependency/PhpRule.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,9 @@ protected function _caseGetUrl(string $currentModule, string &$contents): array
304304
$item['action_name'] ?? UrlInterface::DEFAULT_ACTION_NAME
305305
);
306306
if (!in_array($currentModule, $modules)) {
307+
if (count($modules) === 1) {
308+
$modules = reset($modules);
309+
}
307310
$dependencies[] = [
308311
'module' => $modules,
309312
'type' => RuleInterface::TYPE_HARD,

dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/Dependency/PhpRuleTest.php

Lines changed: 112 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,29 @@
55
*/
66
namespace Magento\TestFramework\Dependency;
77

8+
use Magento\Framework\Exception\LocalizedException;
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
10+
use Magento\TestFramework\Exception\NoSuchActionException;
11+
12+
/**
13+
* Test for PhpRule dependency check
14+
*/
815
class PhpRuleTest extends \PHPUnit\Framework\TestCase
916
{
1017
/**
1118
* @var PhpRule
1219
*/
1320
protected $model;
1421

22+
/**
23+
* @var ObjectManagerHelper
24+
*/
25+
private $objectManagerHelper;
26+
27+
/**
28+
* @inheritDoc
29+
* @throws \Exception
30+
*/
1531
protected function setUp()
1632
{
1733
$mapRoutes = ['someModule' => ['Magento\SomeModule'], 'anotherModule' => ['Magento\OneModule']];
@@ -20,9 +36,23 @@ protected function setUp()
2036
'Magento\Module1\Plugin1' => 'Magento\Module1\Subject',
2137
'Magento\Module1\Plugin2' => 'Magento\Module2\Subject',
2238
];
23-
$this->model = new PhpRule($mapRoutes, $mapLayoutBlocks, $pluginMap);
39+
$whitelist = [];
40+
41+
$this->objectManagerHelper = new ObjectManagerHelper($this);
42+
$this->model = $this->objectManagerHelper->getObject(
43+
PhpRule::class,
44+
[
45+
'mapRouters' => $mapRoutes,
46+
'mapLayoutBlocks' => $mapLayoutBlocks,
47+
'pluginMap' => $pluginMap,
48+
'whitelists' => $whitelist,
49+
]
50+
);
2451
}
2552

53+
/**
54+
* @throws \Exception
55+
*/
2656
public function testNonPhpGetDependencyInfo()
2757
{
2858
$content = 'any content';
@@ -34,6 +64,7 @@ public function testNonPhpGetDependencyInfo()
3464
* @param string $content
3565
* @param array $expected
3666
* @dataProvider getDependencyInfoDataProvider
67+
* @throws \Exception
3768
*/
3869
public function testGetDependencyInfo($class, $content, array $expected)
3970
{
@@ -96,22 +127,6 @@ public function getDependencyInfoDataProvider()
96127
]
97128
]
98129
],
99-
'getUrl from same module' => [
100-
'Magento\SomeModule\SomeClass',
101-
'$this->getUrl("someModule")',
102-
[]
103-
],
104-
'getUrl from another module' => [
105-
'Magento\SomeModule\SomeClass',
106-
'$this->getUrl("anotherModule")',
107-
[
108-
[
109-
'module' => 'Magento\OneModule',
110-
'type' => \Magento\TestFramework\Dependency\RuleInterface::TYPE_HARD,
111-
'source' => 'getUrl("anotherModule"',
112-
]
113-
]
114-
],
115130
'getBlock from same module' => [
116131
'Magento\SomeModule\SomeClass',
117132
'$this->getLayout()->getBlock(\'block.name\');', []
@@ -173,11 +188,88 @@ public function getDependencyInfoDataProvider()
173188
];
174189
}
175190

191+
/**
192+
* @param string $class
193+
* @param string $content
194+
* @param array $expected
195+
* @throws \Exception
196+
* @dataProvider getDependencyInfoDataCaseGetUrlDataProvider
197+
*/
198+
public function testGetDependencyInfoCaseGetUrl(
199+
string $class,
200+
string $content,
201+
array $expected
202+
) {
203+
$file = $this->makeMockFilepath($class);
204+
$module = $this->getModuleFromClass($class);
205+
206+
$this->assertEquals($expected, $this->model->getDependencyInfo($module, 'php', $file, $content));
207+
}
208+
209+
/**
210+
* @return array
211+
*/
212+
public function getDependencyInfoDataCaseGetUrlDataProvider()
213+
{
214+
return [
215+
'getUrl from same module' => [
216+
'Magento\Cms\SomeClass',
217+
'$this->getUrl("cms/index/index")',
218+
[]
219+
],
220+
'getUrl from another module' => [
221+
'Magento\SomeModule\SomeClass',
222+
'$this->getUrl("cms/index/index")',
223+
[
224+
[
225+
'module' => 'Magento\Cms',
226+
'type' => \Magento\TestFramework\Dependency\RuleInterface::TYPE_HARD,
227+
'source' => 'getUrl("cms/index/index"',
228+
]
229+
]
230+
],
231+
];
232+
}
233+
234+
/**
235+
* @param string $class
236+
* @param string $content
237+
* @param \Exception $expected
238+
* @throws \Exception
239+
* @dataProvider getDependencyInfoDataCaseGetUrlExceptionDataProvider
240+
*/
241+
public function testGetDependencyInfoCaseGetUrlException(
242+
string $class,
243+
string $content,
244+
\Exception $expected
245+
) {
246+
$file = $this->makeMockFilepath($class);
247+
$module = $this->getModuleFromClass($class);
248+
$this->expectExceptionObject($expected);
249+
250+
$this->model->getDependencyInfo($module, 'php', $file, $content);
251+
}
252+
253+
/**
254+
* @return array
255+
*/
256+
public function getDependencyInfoDataCaseGetUrlExceptionDataProvider()
257+
{
258+
return [
259+
'getUrl from same module' => [
260+
'Magento\SomeModule\SomeClass',
261+
'$this->getUrl("someModule")',
262+
new LocalizedException(__('Invalid URL path: %1', 'somemodule/index/index')),
263+
],
264+
];
265+
}
266+
176267
/**
177268
* @param string $module
178269
* @param string $content
179270
* @param array $expected
180271
* @dataProvider getDefaultModelDependencyDataProvider
272+
* @throws \Exception
181273
*/
182274
public function testGetDefaultModelDependency($module, $content, array $expected)
183275
{
@@ -192,6 +284,9 @@ public function testGetDefaultModelDependency($module, $content, array $expected
192284
$this->assertEquals($expected, $this->model->getDependencyInfo($module, 'template', 'any', $content));
193285
}
194286

287+
/**
288+
* @return array
289+
*/
195290
public function getDefaultModelDependencyDataProvider()
196291
{
197292
return [

0 commit comments

Comments
 (0)