Skip to content

Commit 805814b

Browse files
committed
Add Upgrade Script
- Added upgrade script to PR branch's feature
1 parent 247029e commit 805814b

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\FunctionalTestingFramework\Upgrade;
8+
9+
use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig;
10+
use Magento\FunctionalTestingFramework\Page\Handlers\PageObjectHandler;
11+
use Magento\FunctionalTestingFramework\Test\Handlers\TestObjectHandler;
12+
use Magento\FunctionalTestingFramework\Util\ModuleResolver;
13+
use Symfony\Component\Console\Input\InputInterface;
14+
use Symfony\Component\Filesystem\Filesystem;
15+
use Symfony\Component\Finder\Finder;
16+
17+
/**
18+
* Class UpgradePageWithNoUrl
19+
* @package Magento\FunctionalTestingFramework\Upgrade
20+
*/
21+
class UpdatePageWithNoUrl implements UpgradeInterface
22+
{
23+
/**
24+
* Upgrades all test xml files, replacing {{page}} with {{page.url}}
25+
*
26+
* @param InputInterface $input
27+
* @return string
28+
*/
29+
public function execute(InputInterface $input)
30+
{
31+
$testsPath = $input->getArgument('path');
32+
$finder = new Finder();
33+
$finder->files()->in($testsPath)->name("*.xml");
34+
35+
// Safely ensure we can get test materials to check for existing pages later
36+
try {
37+
MftfApplicationConfig::create();
38+
ModuleResolver::getInstance()->getModulesPath();
39+
} catch (\Exception $e) {
40+
//retry with --force
41+
MftfApplicationConfig::create(true);
42+
ModuleResolver::getInstance()->getModulesPath();
43+
}
44+
45+
$fileSystem = new Filesystem();
46+
$testsUpdated = 0;
47+
foreach ($finder->files() as $file) {
48+
$count = 0;
49+
$contents = $file->getContents();
50+
// Find {{page}} but not {{page.url}}
51+
preg_match_all("/{{([^\.}]*)}}/", $contents, $pageReferences);
52+
if (empty($pageReferences[1])) {
53+
continue;
54+
}
55+
foreach ($pageReferences[1] as $index => $potentialReplace) {
56+
$isPage = PageObjectHandler::getInstance()->getObject($potentialReplace);
57+
if ($isPage === null) {
58+
continue;
59+
}
60+
$contents = str_replace($pageReferences[0][$index], "{{" . $potentialReplace . ".url}}", $contents);
61+
$count++;
62+
}
63+
$fileSystem->dumpFile($file->getRealPath(), $contents);
64+
if ($count > 0) {
65+
$testsUpdated++;
66+
}
67+
}
68+
return ("{{Page}} without specified \".url\" updated in {$testsUpdated} file(s).");
69+
}
70+
}

src/Magento/FunctionalTestingFramework/Upgrade/UpgradeScriptList.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ class UpgradeScriptList implements UpgradeScriptListInterface
2828
public function __construct(array $scripts = [])
2929
{
3030
$this->scripts = [
31-
'upgradeTestSchema' => new UpdateTestSchemaPaths(),
31+
'upgradeTestSchema' => new UpgradePageWithNoUrl(),
32+
'upgradeTestUrl' => new UpdatePageWithNoUrl(),
3233
] + $scripts;
3334
}
3435

0 commit comments

Comments
 (0)