Skip to content

Commit

Permalink
[TASK] Migrate functional tests to PHPunit v9
Browse files Browse the repository at this point in the history
Rector is used to migrate functional tests to PHPunit v9.

Resolves: #94724
Related: #94706
Releases: master
Change-Id: I378acd4145aacb5448d461eec48c3a1695876d61
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/70238
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Benni Mack <benni@typo3.org>
  • Loading branch information
wouter90 authored and bmack committed Aug 5, 2021
1 parent a9a5a42 commit 9e2f40e
Show file tree
Hide file tree
Showing 28 changed files with 49 additions and 31 deletions.
Expand Up @@ -249,11 +249,11 @@ public function editViewTest(): void
$propertyManager = MfaProviderPropertyManager::create($this->subject, $this->user);
$response = $this->subject->handleRequest($request, $propertyManager, MfaViewType::EDIT)->getBody()->getContents();

self::assertRegExp('/<td>.*Name.*<td>.*some name/s', $response);
self::assertRegExp('/<td>.*Recovery codes left.*<td>.*2/s', $response);
self::assertRegExp('/<td>.*Last updated.*<td>.*18-03-21/s', $response);
self::assertRegExp('/<td>.*Last used.*<td>.*18-03-21/s', $response);
self::assertRegExp('/<input.*id="regenerateCodes"/s', $response);
self::assertMatchesRegularExpression('/<td>.*Name.*<td>.*some name/s', $response);
self::assertMatchesRegularExpression('/<td>.*Recovery codes left.*<td>.*2/s', $response);
self::assertMatchesRegularExpression('/<td>.*Last updated.*<td>.*18-03-21/s', $response);
self::assertMatchesRegularExpression('/<td>.*Last used.*<td>.*18-03-21/s', $response);
self::assertMatchesRegularExpression('/<input.*id="regenerateCodes"/s', $response);
}

/**
Expand All @@ -266,7 +266,7 @@ public function authViewTest(): void
$propertyManager = MfaProviderPropertyManager::create($this->subject, $this->user);
$response = $this->subject->handleRequest($request, $propertyManager, MfaViewType::AUTH)->getBody()->getContents();

self::assertRegExp('/<input.*id="recoveryCode"/s', $response);
self::assertMatchesRegularExpression('/<input.*id="recoveryCode"/s', $response);

// Lock the provider by setting attempts=3
$this->setupUser(['recovery-codes' => ['active' => true, 'codes' => ['some-code'], 'attempts' => 3]]);
Expand Down
Expand Up @@ -243,10 +243,10 @@ public function setupViewTest(): void
$propertyManager = MfaProviderPropertyManager::create($this->subject, $this->user);
$response = $this->subject->handleRequest($request, $propertyManager, MfaViewType::SETUP)->getBody()->getContents();

self::assertRegExp('/<input.*id="totp"/s', $response);
self::assertRegExp('/<input.*id="secret"/s', $response);
self::assertRegExp('/<div.*id="qr-code"/s', $response);
self::assertRegExp('/<typo3-mfa-totp-url-info-button.*url="otpauth:\/\//s', $response);
self::assertMatchesRegularExpression('/<input.*id="totp"/s', $response);
self::assertMatchesRegularExpression('/<input.*id="secret"/s', $response);
self::assertMatchesRegularExpression('/<div.*id="qr-code"/s', $response);
self::assertMatchesRegularExpression('/<typo3-mfa-totp-url-info-button.*url="otpauth:\/\//s', $response);
}

/**
Expand All @@ -259,9 +259,9 @@ public function editViewTest(): void
$propertyManager = MfaProviderPropertyManager::create($this->subject, $this->user);
$response = $this->subject->handleRequest($request, $propertyManager, MfaViewType::EDIT)->getBody()->getContents();

self::assertRegExp('/<td>.*Name.*<td>.*some name/s', $response);
self::assertRegExp('/<td>.*Last updated.*<td>.*18-03-21/s', $response);
self::assertRegExp('/<td>.*Last used.*<td>.*18-03-21/s', $response);
self::assertMatchesRegularExpression('/<td>.*Name.*<td>.*some name/s', $response);
self::assertMatchesRegularExpression('/<td>.*Last updated.*<td>.*18-03-21/s', $response);
self::assertMatchesRegularExpression('/<td>.*Last used.*<td>.*18-03-21/s', $response);
}

/**
Expand All @@ -274,7 +274,7 @@ public function authViewTest(): void
$propertyManager = MfaProviderPropertyManager::create($this->subject, $this->user);
$response = $this->subject->handleRequest($request, $propertyManager, MfaViewType::AUTH)->getBody()->getContents();

self::assertRegExp('/<input.*id="totp"/s', $response);
self::assertMatchesRegularExpression('/<input.*id="totp"/s', $response);

// Lock the provider by setting attempts=3
$this->setupUser(['active' => true, 'secret' => 'KRMVATZTJFZUC53FONXW2ZJB', 'attempts' => 3]);
Expand Down
Expand Up @@ -26,6 +26,7 @@
*/
class MemcachedBackendTest extends FunctionalTestCase
{
use \Prophecy\PhpUnit\ProphecyTrait;
/**
* Sets up this test case
*/
Expand Down
Expand Up @@ -33,6 +33,7 @@
*/
class RedisBackendTest extends FunctionalTestCase
{
use \Prophecy\PhpUnit\ProphecyTrait;
/**
* Set up
*/
Expand Down
Expand Up @@ -26,6 +26,7 @@
*/
class Typo3DatabaseBackendTest extends FunctionalTestCase
{
use \Prophecy\PhpUnit\ProphecyTrait;
/**
* @test
*/
Expand Down
Expand Up @@ -20,6 +20,7 @@

class ClassAliasLoaderTest extends FunctionalTestCase
{
use \Prophecy\PhpUnit\ProphecyTrait;
/**
* @var array Load test fixture extension
*/
Expand Down
Expand Up @@ -33,6 +33,7 @@
*/
class PageRepositoryTest extends FunctionalTestCase
{
use \Prophecy\PhpUnit\ProphecyTrait;
protected function setUp(): void
{
parent::setUp();
Expand Down
11 changes: 6 additions & 5 deletions typo3/sysext/core/Tests/Functional/Page/PageRendererTest.php
Expand Up @@ -33,6 +33,7 @@
*/
class PageRendererTest extends FunctionalTestCase
{
use \Prophecy\PhpUnit\ProphecyTrait;
/**
* @test
*/
Expand Down Expand Up @@ -123,9 +124,9 @@ public function pageRendererRendersInsertsMainContentStringsInOutput()
self::assertStringContainsString($expectedBaseUrlString, $renderedString);
self::assertStringContainsString($expectedInlineCommentString, $renderedString);
self::assertStringContainsString($expectedHeaderData, $renderedString);
self::assertRegExp($expectedJsLibraryRegExp, $renderedString);
self::assertRegExp($expectedJsFileRegExp, $renderedString);
self::assertRegExp($expectedJsFileWithoutTypeRegExp, $renderedString);
self::assertMatchesRegularExpression($expectedJsLibraryRegExp, $renderedString);
self::assertMatchesRegularExpression($expectedJsFileRegExp, $renderedString);
self::assertMatchesRegularExpression($expectedJsFileWithoutTypeRegExp, $renderedString);
self::assertStringContainsString($expectedJsInlineCodeString, $renderedString);
self::assertStringContainsString($expectedCssFileString, $renderedString);
self::assertStringContainsString($expectedCssInlineBlockOnTopString, $renderedString);
Expand Down Expand Up @@ -212,8 +213,8 @@ public function pageRendererRendersFooterValues()
$renderedString = $subject->render();

self::assertStringContainsString($expectedFooterData, $renderedString);
self::assertRegExp($expectedJsFooterLibraryRegExp, $renderedString);
self::assertRegExp($expectedJsFooterRegExp, $renderedString);
self::assertMatchesRegularExpression($expectedJsFooterLibraryRegExp, $renderedString);
self::assertMatchesRegularExpression($expectedJsFooterRegExp, $renderedString);
self::assertStringContainsString($expectedJsFooterInlineCodeString, $renderedString);
self::assertStringContainsString($expectedInlineLabelReturnValue, $renderedString);
self::assertStringContainsString($expectedLanguageLabel1, $renderedString);
Expand Down
Expand Up @@ -67,7 +67,7 @@ public function filesCanNotGetExtractedOutsideTargetDirectory(): void
__DIR__ . '/Fixtures/malicious.zip',
$extensionDirectory
);
self::assertFileNotExists($extensionDirectory . '/../tool.php');
self::assertFileDoesNotExist($extensionDirectory . '/../tool.php');
self::assertFileExists($extensionDirectory . '/tool.php');
// This is a smoke test to verify PHP's zip library is broken regarding symlinks
self::assertFileExists($extensionDirectory . '/passwd');
Expand Down
Expand Up @@ -26,6 +26,7 @@

class IconForRecordViewHelperTest extends FunctionalTestCase
{
use \Prophecy\PhpUnit\ProphecyTrait;
/**
* @test
*/
Expand Down
Expand Up @@ -27,6 +27,7 @@

class IconViewHelperTest extends FunctionalTestCase
{
use \Prophecy\PhpUnit\ProphecyTrait;
/**
* @test
*/
Expand Down
Expand Up @@ -30,6 +30,7 @@

class ExtensionServiceTest extends FunctionalTestCase
{
use \Prophecy\PhpUnit\ProphecyTrait;
/**
* @var array
*/
Expand Down
Expand Up @@ -24,6 +24,7 @@

class ScriptViewHelperTest extends FunctionalTestCase
{
use \Prophecy\PhpUnit\ProphecyTrait;
public function valueDataProvider(): array
{
return [
Expand Down
Expand Up @@ -75,6 +75,6 @@ public function renderReturnsExpectedMarkup(string $template, string $expected):
{
$view = new StandaloneView();
$view->setTemplateSource($template);
self::assertRegExp($expected, $view->render());
self::assertMatchesRegularExpression($expected, $view->render());
}
}
Expand Up @@ -41,6 +41,7 @@
*/
class ConditionMatcherTest extends FunctionalTestCase
{
use \Prophecy\PhpUnit\ProphecyTrait;
/**
* Sets up this test case.
*/
Expand Down
Expand Up @@ -37,6 +37,7 @@
*/
class ContentObjectRendererTest extends FunctionalTestCase
{
use \Prophecy\PhpUnit\ProphecyTrait;
use SiteBasedTestTrait;

/**
Expand Down
Expand Up @@ -28,6 +28,7 @@
*/
class FluidTemplateContentObjectTest extends FunctionalTestCase
{
use \Prophecy\PhpUnit\ProphecyTrait;
/**
* @var array
*/
Expand Down
Expand Up @@ -233,10 +233,10 @@ public function checkIfCorrectTitleTagIsRendered($pageConfig, $expectations): vo
);
$content = (string)$response->getBody();
if ($expectations['assertRegExp']) {
self::assertRegExp($expectations['assertRegExp'], $content);
self::assertMatchesRegularExpression($expectations['assertRegExp'], $content);
}
if ($expectations['assertNotRegExp']) {
self::assertNotRegExp($expectations['assertNotRegExp'], $content);
self::assertDoesNotMatchRegularExpression($expectations['assertNotRegExp'], $content);
}
}
}
Expand Up @@ -353,12 +353,12 @@ function (string $candidateKey) use ($type) {
);

if ($shallExist) {
self::assertRegExp(
self::assertMatchesRegularExpression(
'#' . $pattern . '#',
$content
);
} else {
self::assertNotRegExp(
self::assertDoesNotMatchRegularExpression(
'#' . $pattern . '#',
$content
);
Expand Down
Expand Up @@ -51,7 +51,7 @@ public function importPagesAndRelatedTtContentWithRteImagesAndFileLink()

$this->assertCSVDataSet('EXT:impexp/Tests/Functional/Fixtures/DatabaseAssertions/importPagesAndRelatedTtContentWithRteImagesAndFileLink.csv');

self::assertFileNotExists(Environment::getPublicPath() . '/fileadmin/_processed_/csm_typo3_image2_5c2670fd59.jpg');
self::assertFileDoesNotExist(Environment::getPublicPath() . '/fileadmin/_processed_/csm_typo3_image2_5c2670fd59.jpg');

self::assertFileEquals(__DIR__ . '/../Fixtures/Folders/fileadmin/user_upload/typo3_image2.jpg', Environment::getPublicPath() . '/fileadmin/user_upload/typo3_image2.jpg');
self::assertFileEquals(__DIR__ . '/../Fixtures/Folders/fileadmin/user_upload/typo3_image3.jpg', Environment::getPublicPath() . '/fileadmin/user_upload/typo3_image3.jpg');
Expand Down
Expand Up @@ -29,6 +29,7 @@
*/
class Typo3tempFileServiceTest extends FunctionalTestCase
{
use \Prophecy\PhpUnit\ProphecyTrait;
/**
* @var string
*/
Expand Down Expand Up @@ -82,8 +83,8 @@ public function clearAssetsFolderClearsFolder()
$subject = new Typo3tempFileService($processedFileRepository->reveal(), $storageRepository->reveal());
$subject->clearAssetsFolder('/typo3temp/assets/' . $this->directoryName);

self::assertDirectoryNotExists($this->directoryPath . '/a');
self::assertDirectoryDoesNotExist($this->directoryPath . '/a');
self::assertDirectoryExists($this->directoryPath);
self::assertFileNotExists($this->directoryPath . '/c.css');
self::assertFileDoesNotExist($this->directoryPath . '/c.css');
}
}
Expand Up @@ -25,6 +25,7 @@

class LinkAnalyzerTest extends FunctionalTestCase
{
use \Prophecy\PhpUnit\ProphecyTrait;
protected $coreExtensionsToLoad = [
'seo',
'linkvalidator',
Expand Down
Expand Up @@ -25,6 +25,7 @@

class BrokenLinkRepositoryTest extends FunctionalTestCase
{
use \Prophecy\PhpUnit\ProphecyTrait;
/**
* @var array
*/
Expand Down
Expand Up @@ -29,6 +29,7 @@

class IntegrityServiceTest extends FunctionalTestCase
{
use \Prophecy\PhpUnit\ProphecyTrait;
/**
* @var bool Reset singletons created by subject
*/
Expand Down
Expand Up @@ -34,6 +34,7 @@

class RedirectServiceTest extends FunctionalTestCase
{
use \Prophecy\PhpUnit\ProphecyTrait;
use SiteBasedTestTrait;

/**
Expand Down
Expand Up @@ -70,6 +70,6 @@ public function checkIfSiteMapIndexContainsPagesSitemap(): void
self::assertEquals('application/xml;charset=utf-8', $response->getHeader('Content-Type')[0]);
self::assertArrayHasKey('X-Robots-Tag', $response->getHeaders());
self::assertEquals('noindex', $response->getHeader('X-Robots-Tag')[0]);
self::assertRegExp('/<loc>http:\/\/localhost\/\?sitemap=pages&amp;type=1533906435&amp;cHash=[^<]+<\/loc>/', (string)$response->getBody());
self::assertMatchesRegularExpression('/<loc>http:\/\/localhost\/\?sitemap=pages&amp;type=1533906435&amp;cHash=[^<]+<\/loc>/', (string)$response->getBody());
}
}
Expand Up @@ -39,7 +39,7 @@ public function checkIfPagesSiteMapContainsExpectedEntries($urlPattern): void
self::assertArrayHasKey('X-Robots-Tag', $response->getHeaders());
self::assertEquals('noindex', $response->getHeader('X-Robots-Tag')[0]);

self::assertRegExp($urlPattern, (string)$response->getBody());
self::assertMatchesRegularExpression($urlPattern, (string)$response->getBody());
}

/**
Expand Down
Expand Up @@ -68,7 +68,7 @@ public function checkIfDefaultSitemapReturnsDefaultXsl($typoscriptSetupFiles, $s
(new InternalRequest('http://localhost/'))->withQueryParameters($config)
);

self::assertRegExp('/<\?xml-stylesheet type="text\/xsl" href="' . $xslFilePath . '"\?>/', (string)$response->getBody());
self::assertMatchesRegularExpression('/<\?xml-stylesheet type="text\/xsl" href="' . $xslFilePath . '"\?>/', (string)$response->getBody());
}

public function getXslFilePathsDataProvider(): array
Expand Down

0 comments on commit 9e2f40e

Please sign in to comment.