Skip to content

Commit cd76c61

Browse files
Merge pull request #20083 from MauricioFauth/unit-tests
Extract HTML from some controller tests into a fixture file
2 parents 5f28170 + 852f1b5 commit cd76c61

5 files changed

Lines changed: 433 additions & 89 deletions

tests/unit/Controllers/ChangeLogControllerTest.php

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -43,61 +43,10 @@ private function assertChangelogOutputIsValid(string $changelogPath): void
4343

4444
self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode());
4545
self::assertSame(['text/html; charset=utf-8'], $response->getHeader('Content-Type'));
46-
47-
// phpcs:disable Generic.Files.LineLength.TooLong
48-
$changelog = <<<'HTML'
49-
<h1>Changes in phpMyAdmin 5.2</h1>
50-
51-
All notable changes of the phpMyAdmin 5.2 release series are documented in this file following the Keep a Changelog format.
52-
53-
<h2><a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://github.com/phpmyadmin/phpmyadmin/compare/RELEASE_5_2_1...QA_5_2">5.2.2</a> (not yet released)</h2>
54-
55-
<h3>Fixed</h3>
56-
57-
* <a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://github.com/phpmyadmin/phpmyadmin/issues/17522">#17522</a>: Fix case where the routes cache file is invalid
58-
59-
<h3>Security</h3>
60-
61-
* Upgrade slim/psr7 to 1.4.1 for <a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://www.cve.org/CVERecord?id=CVE-2023-30536">CVE-2023-30536</a> - GHSA-q2qj-628g-vhfw
62-
63-
<h2><a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://github.com/phpmyadmin/phpmyadmin/compare/RELEASE_5_2_0...RELEASE_5_2_1">5.2.1</a> 2023-02-07</h2>
64-
65-
<h3>Added</h3>
66-
67-
* <a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://github.com/phpmyadmin/phpmyadmin/issues/17519">#17519</a>: Fix Export pages not working in certain conditions
68-
* <a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://github.com/phpmyadmin/phpmyadmin/issues/17496">#17496</a>: Fix error in table operation page when partitions are broken
69-
70-
<h3>Changed</h3>
71-
72-
* <a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://github.com/phpmyadmin/phpmyadmin/issues/17519">#17519</a>: Fix Export pages not working in certain conditions
73-
* <a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://github.com/phpmyadmin/phpmyadmin/issues/17496">#17496</a>: Fix error in table operation page when partitions are broken
74-
75-
<h3>Deprecated</h3>
76-
77-
* <a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://github.com/phpmyadmin/phpmyadmin/issues/17519">#17519</a>: Fix Export pages not working in certain conditions
78-
* <a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://github.com/phpmyadmin/phpmyadmin/issues/17496">#17496</a>: Fix error in table operation page when partitions are broken
79-
80-
<h3>Removed</h3>
81-
82-
* <a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://github.com/phpmyadmin/phpmyadmin/issues/17519">#17519</a>: Fix Export pages not working in certain conditions
83-
* <a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://github.com/phpmyadmin/phpmyadmin/issues/17496">#17496</a>: Fix error in table operation page when partitions are broken
84-
85-
<h3>Fixed</h3>
86-
87-
* <a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://github.com/phpmyadmin/phpmyadmin/issues/17519">#17519</a>: Fix Export pages not working in certain conditions
88-
* <a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://github.com/phpmyadmin/phpmyadmin/issues/17496">#17496</a>: Fix error in table operation page when partitions are broken
89-
* <a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://github.com/phpmyadmin/phpmyadmin/issues/16418">#16418</a>: Fix <a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://docs.phpmyadmin.net/en/latest/faq.html#faq1-44">FAQ 1.44</a> about manually removing vendor folders
90-
91-
<h3>Security</h3>
92-
93-
* Fix an XSS attack through the drag-and-drop upload feature (<a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://www.phpmyadmin.net/security/PMASA-2023-01/">PMASA-2023-01</a>)
94-
95-
96-
HTML;
97-
// phpcs:enable
98-
$expected = $template->render('changelog', ['changelog' => $changelog]);
99-
100-
self::assertSame($expected, (string) $response->getBody());
46+
self::assertStringEqualsFile(
47+
__DIR__ . '/Fixtures/ChangeLog-assertChangelogOutputIsValid.html',
48+
(string) $response->getBody(),
49+
);
10150
}
10251

10352
public function testWithInvalidFile(): void

tests/unit/Controllers/CheckRelationsControllerTest.php

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace PhpMyAdmin\Tests\Controllers;
66

7+
use Fig\Http\Message\StatusCodeInterface;
78
use PhpMyAdmin\Config;
89
use PhpMyAdmin\ConfigStorage\Relation;
910
use PhpMyAdmin\ConfigStorage\RelationParameters;
@@ -21,7 +22,7 @@
2122
use ReflectionProperty;
2223

2324
#[CoversClass(CheckRelationsController::class)]
24-
class CheckRelationsControllerTest extends AbstractTestCase
25+
final class CheckRelationsControllerTest extends AbstractTestCase
2526
{
2627
protected DatabaseInterface $dbi;
2728

@@ -43,23 +44,17 @@ public function testCheckRelationsController(): void
4344

4445
$request = self::createStub(ServerRequest::class);
4546

46-
$response = new ResponseRenderer();
47+
$responseRenderer = new ResponseRenderer();
4748
$config = Config::getInstance();
4849
$config->selectedServer['pmadb'] = '';
4950
(new ReflectionProperty(Relation::class, 'cache'))->setValue(null, null);
50-
$controller = new CheckRelationsController($response, new Relation($this->dbi), $config);
51-
$controller($request);
52-
53-
$actual = $response->getHTMLResult();
51+
$controller = new CheckRelationsController($responseRenderer, new Relation($this->dbi), $config);
52+
$response = $controller($request);
5453

55-
self::assertStringContainsString('phpMyAdmin configuration storage', $actual);
56-
self::assertStringContainsString(
57-
'Configuration of pmadb…' . "\n" . ' <span class="text-danger"><strong>not OK</strong></span>',
58-
$actual,
59-
);
60-
self::assertStringContainsString(
61-
'Create</a> a database named &#039;phpmyadmin&#039; and setup the phpMyAdmin configuration storage there.',
62-
$actual,
54+
self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode());
55+
self::assertStringEqualsFile(
56+
__DIR__ . '/Fixtures/CheckRelations-testCheckRelationsController.html',
57+
(string) $response->getBody(),
6358
);
6459
}
6560

@@ -126,31 +121,18 @@ public function createConfigStorage(): void
126121
$dbiDummy->addResult('SELECT NULL FROM `pma__recent` LIMIT 0', []);
127122
$dbiDummy->addResult('SELECT NULL FROM `pma__history` LIMIT 0', []);
128123
$dbiDummy->addResult('SELECT NULL FROM `pma__relation` LIMIT 0', []);
124+
// phpcs:enable
129125

130126
$controller = new CheckRelationsController(new ResponseRenderer(), new Relation($dbi, $config), $config);
131127
$response = $controller($request);
132128

133-
$responseBody = (string) $response->getBody();
134-
self::assertStringContainsString("General relation features:\n <span class=\"text-success\">Enabled</span>", $responseBody);
135-
self::assertStringContainsString("Display features:\n <span class=\"text-success\">Enabled</span>", $responseBody);
136-
self::assertStringContainsString("Designer and creation of PDFs:\n <span class=\"text-success\">Enabled</span>", $responseBody);
137-
self::assertStringContainsString("Displaying column comments:\n <span class=\"text-success\">Enabled</span>", $responseBody);
138-
self::assertStringContainsString("Bookmarked SQL query:\n <span class=\"text-success\">Enabled</span>", $responseBody);
139-
self::assertStringContainsString("SQL history:\n <span class=\"text-success\">Enabled</span>", $responseBody);
140-
self::assertStringContainsString("Persistent recently used tables:\n <span class=\"text-success\">Enabled</span>", $responseBody);
141-
self::assertStringContainsString("Persistent favorite tables:\n <span class=\"text-success\">Enabled</span>", $responseBody);
142-
self::assertStringContainsString("Persistent tables&#039; UI preferences:\n <span class=\"text-success\">Enabled</span>", $responseBody);
143-
self::assertStringContainsString("Tracking:\n <span class=\"text-success\">Enabled</span>", $responseBody);
144-
self::assertStringContainsString("User preferences:\n <span class=\"text-success\">Enabled</span>", $responseBody);
145-
self::assertStringContainsString("Configurable menus:\n <span class=\"text-success\">Enabled</span>", $responseBody);
146-
self::assertStringContainsString("Hide/show navigation items:\n <span class=\"text-success\">Enabled</span>", $responseBody);
147-
self::assertStringContainsString("Saving Query-By-Example searches:\n <span class=\"text-success\">Enabled</span>", $responseBody);
148-
self::assertStringContainsString("Managing central list of columns:\n <span class=\"text-success\">Enabled</span>", $responseBody);
149-
self::assertStringContainsString("Remembering designer settings:\n <span class=\"text-success\">Enabled</span>", $responseBody);
150-
self::assertStringContainsString("Saving export templates:\n <span class=\"text-success\">Enabled</span>", $responseBody);
151-
// phpcs:enable
152-
153129
$dbiDummy->assertAllQueriesConsumed();
154130
$dbiDummy->assertAllSelectsConsumed();
131+
132+
self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode());
133+
self::assertStringEqualsFile(
134+
__DIR__ . '/Fixtures/CheckRelations-createConfigStorage.html',
135+
(string) $response->getBody(),
136+
);
155137
}
156138
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<!doctype html>
2+
<html lang="en" dir="ltr">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<meta name="robots" content="noindex,nofollow">
7+
<link rel="icon" href="favicon.ico" type="image/x-icon">
8+
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
9+
<title>phpMyAdmin - ChangeLog</title>
10+
</head>
11+
<body>
12+
<pre><h1>Changes in phpMyAdmin 5.2</h1>
13+
14+
All notable changes of the phpMyAdmin 5.2 release series are documented in this file following the Keep a Changelog format.
15+
16+
<h2><a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://github.com/phpmyadmin/phpmyadmin/compare/RELEASE_5_2_1...QA_5_2">5.2.2</a> (not yet released)</h2>
17+
18+
<h3>Fixed</h3>
19+
20+
* <a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://github.com/phpmyadmin/phpmyadmin/issues/17522">#17522</a>: Fix case where the routes cache file is invalid
21+
22+
<h3>Security</h3>
23+
24+
* Upgrade slim/psr7 to 1.4.1 for <a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://www.cve.org/CVERecord?id=CVE-2023-30536">CVE-2023-30536</a> - GHSA-q2qj-628g-vhfw
25+
26+
<h2><a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://github.com/phpmyadmin/phpmyadmin/compare/RELEASE_5_2_0...RELEASE_5_2_1">5.2.1</a> 2023-02-07</h2>
27+
28+
<h3>Added</h3>
29+
30+
* <a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://github.com/phpmyadmin/phpmyadmin/issues/17519">#17519</a>: Fix Export pages not working in certain conditions
31+
* <a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://github.com/phpmyadmin/phpmyadmin/issues/17496">#17496</a>: Fix error in table operation page when partitions are broken
32+
33+
<h3>Changed</h3>
34+
35+
* <a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://github.com/phpmyadmin/phpmyadmin/issues/17519">#17519</a>: Fix Export pages not working in certain conditions
36+
* <a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://github.com/phpmyadmin/phpmyadmin/issues/17496">#17496</a>: Fix error in table operation page when partitions are broken
37+
38+
<h3>Deprecated</h3>
39+
40+
* <a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://github.com/phpmyadmin/phpmyadmin/issues/17519">#17519</a>: Fix Export pages not working in certain conditions
41+
* <a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://github.com/phpmyadmin/phpmyadmin/issues/17496">#17496</a>: Fix error in table operation page when partitions are broken
42+
43+
<h3>Removed</h3>
44+
45+
* <a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://github.com/phpmyadmin/phpmyadmin/issues/17519">#17519</a>: Fix Export pages not working in certain conditions
46+
* <a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://github.com/phpmyadmin/phpmyadmin/issues/17496">#17496</a>: Fix error in table operation page when partitions are broken
47+
48+
<h3>Fixed</h3>
49+
50+
* <a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://github.com/phpmyadmin/phpmyadmin/issues/17519">#17519</a>: Fix Export pages not working in certain conditions
51+
* <a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://github.com/phpmyadmin/phpmyadmin/issues/17496">#17496</a>: Fix error in table operation page when partitions are broken
52+
* <a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://github.com/phpmyadmin/phpmyadmin/issues/16418">#16418</a>: Fix <a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://docs.phpmyadmin.net/en/latest/faq.html#faq1-44">FAQ 1.44</a> about manually removing vendor folders
53+
54+
<h3>Security</h3>
55+
56+
* Fix an XSS attack through the drag-and-drop upload feature (<a target="_blank" rel="noopener noreferrer" href="index.php?route=/url&lang=en&url=https://www.phpmyadmin.net/security/PMASA-2023-01/">PMASA-2023-01</a>)
57+
58+
</pre>
59+
</body>
60+
</html>

0 commit comments

Comments
 (0)