-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE] Add command 'make:testing:acceptance' #28
Open
ochorocho
wants to merge
7
commits into
main
Choose a base branch
from
feature/make-acceptance-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8d63d75
[FEATURE] Add command 'make:runtests'.
ochorocho 13a34b5
[FEATURE] Add command 'make:acceptance'
ochorocho ee7ad45
[TASK] Add PHP 7.2 compatability
ochorocho fc58c33
[TASK] Ask for permission to modify if composer property already exists.
ochorocho 48a344b
[TASK] Use methods from abstract command.
ochorocho 3b651e4
[TASK] Use newly introduced extension selection and cleanup old code
ochorocho 86abbe7
[TASK] Rename 'make:acceptance' to 'make:testing:acceptance'
ochorocho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of TYPO3 CMS-based extension "b13/make" by b13. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
*/ | ||
|
||
namespace B13\Make\Command; | ||
|
||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Filesystem\Exception\IOException; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
use Symfony\Component\Finder\Finder; | ||
use TYPO3\CMS\Core\Package\PackageInterface; | ||
use TYPO3\CMS\Core\Service\MarkerBasedTemplateService; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
/** | ||
* Command for creating a new backend controller component | ||
*/ | ||
class AcceptanceTestsCommand extends AbstractCommand | ||
{ | ||
/** | ||
* @var Filesystem $filesystem | ||
*/ | ||
protected $filesystem; | ||
|
||
/** | ||
* @var PackageInterface $package | ||
*/ | ||
protected $package; | ||
|
||
protected function configure(): void | ||
{ | ||
parent::configure(); | ||
$this->setDescription('Prepare extensions to run acceptance tests'); | ||
$this->filesystem = GeneralUtility::makeInstance(Filesystem::class); | ||
} | ||
|
||
/** | ||
* @throws \JsonException | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$this->package = $this->packageResolver->resolvePackage($this->askForExtensionKey()); | ||
|
||
$packageKey = $this->package->getPackageKey(); | ||
$targetPackagePath = $this->package->getPackagePath(); | ||
|
||
if ($this->updateComposerFile($targetPackagePath)) { | ||
$this->io->writeln('<info>Updated composer.json for EXT:' . $packageKey . '</info>'); | ||
} else { | ||
$this->io->writeln('<comment>Failed to update composer.json for EXT:' . $packageKey . '</comment>'); | ||
} | ||
|
||
$this->io->writeln('Selected package: ' . $packageKey); | ||
$finder = GeneralUtility::makeInstance(Finder::class); | ||
|
||
$codeTemplatePath = '/Resources/Private/CodeTemplates/AcceptanceTests'; | ||
$templatePath = $this->packageResolver->resolvePackage('b13/make')->getPackagePath() . $codeTemplatePath; | ||
|
||
$this->filesystem->mkdir([ | ||
$targetPackagePath . '/Tests/Acceptance/Fixtures', | ||
$targetPackagePath . '/Tests/Acceptance/Application', | ||
$targetPackagePath . '/Tests/Acceptance/Support/Extension' | ||
]); | ||
|
||
// Create public folder which is required for e.g. acceptance tests to work | ||
$publicFolderPath = $targetPackagePath . '/Resources/Public'; | ||
if (!is_dir($publicFolderPath)) { | ||
$createPublic = $this->io->confirm( | ||
'Resource/Public is necessary e.g. for acceptance tests. Do you want to create it now?', | ||
true | ||
); | ||
|
||
if ($createPublic) { | ||
$this->filesystem->mkdir([$publicFolderPath]); | ||
// Ensure the folder will be detected by git and committed | ||
$this->filesystem->touch([$publicFolderPath . '/.gitkeep']); | ||
} | ||
} | ||
|
||
$files = $finder->in($templatePath)->files(); | ||
|
||
foreach ($files as $file) { | ||
$target = $targetPackagePath . 'Tests' . explode('AcceptanceTests', $file->getRealPath())[1]; | ||
|
||
if (!is_file($target)) { | ||
$content = $file->getContents(); | ||
$this->substituteMarkersAndSave($content, $target); | ||
} else { | ||
$overwrite = $this->io->confirm('File exists ' . basename($target) . '. Do you want to overwrite it?'); | ||
if ($overwrite) { | ||
$content = $file->getContents(); | ||
$this->substituteMarkersAndSave($content, $target); | ||
} | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
/** | ||
* Extend/prepare composer.json of the extension | ||
* for acceptance tests | ||
* | ||
* @throws \JsonException | ||
*/ | ||
protected function updateComposerFile(string $packagePath): bool | ||
{ | ||
$composerFile = $packagePath . '/composer.json'; | ||
$composerJson = file_get_contents($composerFile); | ||
$composer = json_decode($composerJson, true); | ||
if (json_last_error() !== JSON_ERROR_NONE) { | ||
throw new \JsonException('Could not parse ' . $composerFile); | ||
} | ||
|
||
$namespace = rtrim($this->getNamespace(), '\\'); | ||
|
||
$addToComposerFile = [ | ||
'require-dev' => [ | ||
'codeception/codeception' => '^4.1', | ||
'codeception/module-asserts' => '^1.2', | ||
'codeception/module-webdriver' => '^1.1', | ||
'typo3/testing-framework' => '^6.16.2' | ||
], | ||
'autoload-dev' => [ | ||
'psr-4' => [ | ||
$namespace . '\\Tests\\' => 'Tests/' | ||
] | ||
], | ||
'config' => [ | ||
'vendor-dir' => '.Build/vendor', | ||
'bin-dir' => '.Build/bin', | ||
], | ||
'extra' => [ | ||
'typo3/cms' => [ | ||
'app-dir' => '.Build', | ||
'web-dir' => '.Build/Web', | ||
] | ||
] | ||
]; | ||
|
||
$enhancedComposer = $this->enhanceComposerFile($composer, $addToComposerFile); | ||
|
||
return GeneralUtility::writeFile($composerFile, json_encode($enhancedComposer, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), true); | ||
} | ||
|
||
/** | ||
* Substitute marker values and save file to extension_key/Tests/ | ||
* | ||
* @param string $content | ||
* @param string $target | ||
*/ | ||
protected function substituteMarkersAndSave(string $content, string $target): void | ||
{ | ||
$markerService = GeneralUtility::makeInstance(MarkerBasedTemplateService::class); | ||
$templateContent = $markerService->substituteMarker( | ||
$content, | ||
'{{NAMESPACE}}', | ||
rtrim($this->getNamespace(), '\\') | ||
); | ||
$templateContent = $markerService->substituteMarker( | ||
$templateContent, | ||
'{{EXTENSION_KEY}}', | ||
$this->package->getPackageKey() | ||
); | ||
|
||
try { | ||
$this->filesystem->dumpFile($target, $templateContent); | ||
} catch (IOException $exception) { | ||
$this->io->writeln('<error>Failed to save file in ' . $target . '</error>'); | ||
} | ||
} | ||
|
||
protected function getNamespace(): string | ||
{ | ||
return (string)key((array)($this->package->getValueFromComposerManifest('autoload')->{'psr-4'} ?? [])); | ||
} | ||
|
||
private function enhanceComposerFile(array &$composer, array &$addToComposerFile): array | ||
{ | ||
foreach ($addToComposerFile as $key => $value) { | ||
if (is_array($value) && isset($composer[$key])) { | ||
$this->enhanceComposerFile($composer[$key], $value); | ||
} else { | ||
$composer[$key] = $value; | ||
} | ||
} | ||
|
||
return $composer; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
Resources/Private/CodeTemplates/AcceptanceTests/Acceptance/Application.suite.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class_name: ApplicationTester | ||
modules: | ||
enabled: | ||
- WebDriver: | ||
url: http://web:8000/typo3temp/var/tests/acceptance | ||
browser: chrome | ||
wait: 1 | ||
host: chrome | ||
window_size: 1400x800 | ||
- \TYPO3\TestingFramework\Core\Acceptance\Helper\Acceptance | ||
- \TYPO3\TestingFramework\Core\Acceptance\Helper\Login: | ||
sessions: | ||
# This sessions must exist in the database fixture to get a logged in state. | ||
editor: ff83dfd81e20b34c27d3e97771a4525a | ||
admin: 886526ce72b86870739cc41991144ec1 | ||
- Asserts | ||
|
||
extensions: | ||
enabled: | ||
- {{NAMESPACE}}\Tests\Acceptance\Support\Extension\ExtensionEnvironment | ||
|
||
groups: | ||
AcceptanceTests-Job-*: AcceptanceTests-Job-* |
30 changes: 30 additions & 0 deletions
30
Resources/Private/CodeTemplates/AcceptanceTests/Acceptance/Application/ExampleCest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace {{NAMESPACE}}\Tests\Acceptance\Backend; | ||
|
||
use {{NAMESPACE}}\Tests\Acceptance\Support\ApplicationTester; | ||
|
||
class ExampleCest | ||
{ | ||
/** | ||
* @param ApplicationTester $I | ||
*/ | ||
public function _before(ApplicationTester $I) | ||
{ | ||
$I->useExistingSession('admin'); | ||
$I->switchToMainFrame(); | ||
} | ||
|
||
/** | ||
* @param ApplicationTester $I | ||
* @throws \Exception | ||
*/ | ||
public function seeTestExample(ApplicationTester $I): void | ||
{ | ||
$I->click('Page'); | ||
$I->switchToContentFrame(); | ||
$I->see('Web>Page module', '.callout-info'); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
Resources/Private/CodeTemplates/AcceptanceTests/Acceptance/Fixtures/be_sessions.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<dataset> | ||
<be_sessions> | ||
<!-- hash_hmac('sha256', '886526ce72b86870739cc41991144ec1', sha1('iAmInvalid' . 'core-session-backend')) --> | ||
<ses_id>9869d429fc72742a476d5073d006d45dfb732962d9c024423efafef537e1c5bd</ses_id> | ||
<ses_iplock>[DISABLED]</ses_iplock> | ||
<ses_userid>1</ses_userid> | ||
<ses_tstamp>1777777777</ses_tstamp> | ||
<ses_data></ses_data> | ||
</be_sessions> | ||
<be_sessions> | ||
<!-- hash_hmac('sha256', 'ff83dfd81e20b34c27d3e97771a4525a', sha1('iAmInvalid' . 'core-session-backend')) --> | ||
<ses_id>f4c02f70058e79a8e7b523a266d4291007deacba6b2ca2536dd72d2fbb23696a</ses_id> | ||
<ses_iplock>[DISABLED]</ses_iplock> | ||
<ses_userid>2</ses_userid> | ||
<ses_tstamp>1777777777</ses_tstamp> | ||
<ses_data></ses_data> | ||
</be_sessions> | ||
</dataset> |
24 changes: 24 additions & 0 deletions
24
Resources/Private/CodeTemplates/AcceptanceTests/Acceptance/Fixtures/pages.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<dataset> | ||
<!-- Creates a page + subpage --> | ||
<pages> | ||
<uid>1</uid> | ||
<pid>0</pid> | ||
<title>Home</title> | ||
<slug></slug> | ||
<doktype>1</doktype> | ||
<deleted>0</deleted> | ||
<is_siteroot>1</is_siteroot> | ||
<perms_everybody>15</perms_everybody> | ||
</pages> | ||
<pages> | ||
<uid>2</uid> | ||
<pid>1</pid> | ||
<sorting>128</sorting> | ||
<title>Subpage</title> | ||
<slug>subpage</slug> | ||
<deleted>0</deleted> | ||
<doktype>1</doktype> | ||
<perms_everybody>15</perms_everybody> | ||
</pages> | ||
</dataset> |
16 changes: 16 additions & 0 deletions
16
Resources/Private/CodeTemplates/AcceptanceTests/Acceptance/Fixtures/sys_template.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<dataset> | ||
<sys_template> | ||
<uid>1</uid> | ||
<pid>1</pid> | ||
<title>Root Template</title> | ||
<deleted>0</deleted> | ||
<root>1</root> | ||
<clear>3</clear> | ||
<config> | ||
page = PAGE | ||
page.10 = TEXT | ||
page.10.data = page:title | ||
</config> | ||
</sys_template> | ||
</dataset> |
17 changes: 17 additions & 0 deletions
17
Resources/Private/CodeTemplates/AcceptanceTests/Acceptance/Support/ApplicationTester.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace {{NAMESPACE}}\Tests\Acceptance\Support; | ||
|
||
use {{NAMESPACE}}\Tests\Acceptance\Support\_generated\ApplicationTesterActions; | ||
use TYPO3\TestingFramework\Core\Acceptance\Step\FrameSteps; | ||
|
||
/** | ||
* Default backend admin or editor actor in the backend | ||
*/ | ||
class ApplicationTester extends \Codeception\Actor | ||
{ | ||
use ApplicationTesterActions; | ||
use FrameSteps; | ||
} |
52 changes: 52 additions & 0 deletions
52
...ivate/CodeTemplates/AcceptanceTests/Acceptance/Support/Extension/ExtensionEnvironment.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace {{NAMESPACE}}\Tests\Acceptance\Support\Extension; | ||
|
||
use Symfony\Component\Mailer\Transport\NullTransport; | ||
use TYPO3\TestingFramework\Core\Acceptance\Extension\BackendEnvironment; | ||
|
||
/** | ||
* Load various core extensions and styleguide and call styleguide generator | ||
*/ | ||
class ExtensionEnvironment extends BackendEnvironment | ||
{ | ||
/** | ||
* Load a list of core extensions | ||
* | ||
* @var array | ||
*/ | ||
protected $localConfig = [ | ||
'coreExtensionsToLoad' => [ | ||
'core', | ||
'extbase', | ||
'filelist', | ||
'setup', | ||
'frontend', | ||
'fluid', | ||
'recordlist', | ||
'backend', | ||
'install', | ||
], | ||
'testExtensionsToLoad' => [ | ||
'typo3conf/ext/{{EXTENSION_KEY}}', | ||
], | ||
'xmlDatabaseFixtures' => [ | ||
'PACKAGE:typo3/testing-framework/Resources/Core/Acceptance/Fixtures/be_users.xml', | ||
'PACKAGE:../Web/typo3conf/ext/{{EXTENSION_KEY}}/Tests/Acceptance/Fixtures/pages.xml', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
'PACKAGE:../Web/typo3conf/ext/{{EXTENSION_KEY}}/Tests/Acceptance/Fixtures/be_sessions.xml', | ||
'PACKAGE:../Web/typo3conf/ext/{{EXTENSION_KEY}}/Tests/Acceptance/Fixtures/sys_template.xml', | ||
], | ||
'configurationToUseInTestInstance' => [ | ||
'MAIL' => [ | ||
'transport' => NullTransport::class, | ||
], | ||
], | ||
|
||
// Link files/folders required for your acceptance tests to run | ||
// 'pathsToLinkInTestInstance' => [ | ||
// 'typo3conf/ext/{{EXTENSION_KEY}}/Tests/Acceptance/Fixtures/sites' => 'typo3conf/sites', | ||
// ] | ||
]; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use
public
here asWeb
dates back to TYPO3 Flow times and should not be used in TYPO3 world.