From 84a8904cfac6191647cfa3af3bfc328341f409a4 Mon Sep 17 00:00:00 2001
From: Norbert Orzechowicz <1921950+norberttech@users.noreply.github.com>
Date: Fri, 16 Aug 2024 17:15:55 +0200
Subject: [PATCH] Landing page functional tests (#1195)
* Added functional tests to landing page
* CS fixes
---
web/landing/.env.test | 7 ++
.../syntax_highlight_controller.js | 1 +
web/landing/composer.json | 3 +-
web/landing/composer.lock | 67 ++++++++++++++++++-
web/landing/importmap.php | 3 +
web/landing/phpunit.xml | 10 ++-
.../Model/Documentation/DSLDefinition.php | 2 +-
.../src/Flow/Website/Service/Github.php | 14 ++++
.../templates/documentation/dsl.html.twig | 50 +++++++-------
.../documentation/dsl/function.html.twig | 20 +++---
web/landing/templates/example/index.html.twig | 4 +-
.../Valid/topics/topic_1/example_1/code.php | 0
.../Valid/topics/topic_1/example_2/code.php | 0
.../Valid/topics/topic_2/example_1/code.php | 0
.../Valid/topics/topic_2/example_2/code.php | 0
.../Valid/topics/topic_3/example_1/code.php | 0
.../Tests/Functional/DocumentationTest.php | 44 ++++++++++++
.../Tests/Integration/ExamplesTest.php | 2 +-
web/landing/tests/autoload.php | 19 ++++++
19 files changed, 205 insertions(+), 41 deletions(-)
create mode 100644 web/landing/.env.test
rename web/landing/tests/Flow/Website/{Service => }/Tests/Fixtures/Valid/topics/topic_1/example_1/code.php (100%)
rename web/landing/tests/Flow/Website/{Service => }/Tests/Fixtures/Valid/topics/topic_1/example_2/code.php (100%)
rename web/landing/tests/Flow/Website/{Service => }/Tests/Fixtures/Valid/topics/topic_2/example_1/code.php (100%)
rename web/landing/tests/Flow/Website/{Service => }/Tests/Fixtures/Valid/topics/topic_2/example_2/code.php (100%)
rename web/landing/tests/Flow/Website/{Service => }/Tests/Fixtures/Valid/topics/topic_3/example_1/code.php (100%)
create mode 100644 web/landing/tests/Flow/Website/Tests/Functional/DocumentationTest.php
rename web/landing/tests/Flow/Website/{Service => }/Tests/Integration/ExamplesTest.php (98%)
create mode 100644 web/landing/tests/autoload.php
diff --git a/web/landing/.env.test b/web/landing/.env.test
new file mode 100644
index 000000000..5fcc062e4
--- /dev/null
+++ b/web/landing/.env.test
@@ -0,0 +1,7 @@
+APP_ENV=test
+GITHUB_TOKEN=test_token
+APP_SECRET=secret
+SCHEME='https'
+DOMAIN='flow-php.wip'
+GOOGLE_ANALYTICS_ID=G-XXXXXXXXXX
+GOOGLE_CONVERSION_TAG=AW-XXXXXXXXXX
diff --git a/web/landing/assets/controllers/syntax_highlight_controller.js b/web/landing/assets/controllers/syntax_highlight_controller.js
index 90078751a..d43619853 100644
--- a/web/landing/assets/controllers/syntax_highlight_controller.js
+++ b/web/landing/assets/controllers/syntax_highlight_controller.js
@@ -6,6 +6,7 @@ import 'prismjs/plugins/autoloader/prism-autoloader.js';
import 'prismjs/components/prism-markup-templating.min.js';
import 'prismjs/components/prism-php.min.js';
import 'prismjs/components/prism-bash.min.js';
+import 'prismjs/components/prism-json.min.js';
/* stimulusFetch: 'lazy' */
export default class extends Controller
diff --git a/web/landing/composer.json b/web/landing/composer.json
index 79c9acd38..afb35eb83 100644
--- a/web/landing/composer.json
+++ b/web/landing/composer.json
@@ -31,7 +31,8 @@
"require-dev": {
"symfony/web-profiler-bundle": "^6.4",
"symfonycasts/tailwind-bundle": "^0.5.0",
- "norberttech/static-content-generator-bundle": "1.x-dev"
+ "norberttech/static-content-generator-bundle": "1.x-dev",
+ "symfony/css-selector": "^6.4"
},
"autoload": {
"psr-4": {
diff --git a/web/landing/composer.lock b/web/landing/composer.lock
index 7229b1d1a..6f8e25ee5 100644
--- a/web/landing/composer.lock
+++ b/web/landing/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "d877356fd982c0941ec477dcceb3b37e",
+ "content-hash": "61474211e42935fbc7058ff05897c378",
"packages": [
{
"name": "aeon-php/calendar",
@@ -5895,6 +5895,71 @@
],
"time": "2024-05-31T14:49:08+00:00"
},
+ {
+ "name": "symfony/css-selector",
+ "version": "v6.4.8",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/css-selector.git",
+ "reference": "4b61b02fe15db48e3687ce1c45ea385d1780fe08"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/symfony/css-selector/zipball/4b61b02fe15db48e3687ce1c45ea385d1780fe08",
+ "reference": "4b61b02fe15db48e3687ce1c45ea385d1780fe08",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=8.1"
+ },
+ "type": "library",
+ "autoload": {
+ "psr-4": {
+ "Symfony\\Component\\CssSelector\\": ""
+ },
+ "exclude-from-classmap": [
+ "/Tests/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
+ },
+ {
+ "name": "Jean-François Simon",
+ "email": "jeanfrancois.simon@sensiolabs.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "https://symfony.com/contributors"
+ }
+ ],
+ "description": "Converts CSS selectors to XPath expressions",
+ "homepage": "https://symfony.com",
+ "support": {
+ "source": "https://github.com/symfony/css-selector/tree/v6.4.8"
+ },
+ "funding": [
+ {
+ "url": "https://symfony.com/sponsor",
+ "type": "custom"
+ },
+ {
+ "url": "https://github.com/fabpot",
+ "type": "github"
+ },
+ {
+ "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
+ "type": "tidelift"
+ }
+ ],
+ "time": "2024-05-31T14:49:08+00:00"
+ },
{
"name": "symfony/dom-crawler",
"version": "v6.4.8",
diff --git a/web/landing/importmap.php b/web/landing/importmap.php
index 2ab616081..71fc7579c 100644
--- a/web/landing/importmap.php
+++ b/web/landing/importmap.php
@@ -58,4 +58,7 @@
'prismjs/components/prism-php.min.js' => [
'version' => '1.29.0',
],
+ 'prismjs/components/prism-json.min.js' => [
+ 'version' => '1.29.0',
+ ],
];
diff --git a/web/landing/phpunit.xml b/web/landing/phpunit.xml
index 355d223eb..96bcd745c 100644
--- a/web/landing/phpunit.xml
+++ b/web/landing/phpunit.xml
@@ -2,16 +2,22 @@
+
+
+
- tests/Flow/Website/**/Tests/Integration
+ tests/Flow/Website/Tests/Integration
+
+
+ tests/Flow/Website/Tests/Functional
{% for type in types %}
{% if definitions.onlyType(type).count %}
-
+
{% for definition in definitions.onlyType(type).all %}
-
-
+
Definition
-
+
source
-
+
{% apply spaceless %}
-
-
+
+
{{- definition.toString | escape('html') -}}
-
-
+
+
{% endapply %}
-
+
+
diff --git a/web/landing/templates/example/index.html.twig b/web/landing/templates/example/index.html.twig
index bdd78ec58..2300879f1 100644
--- a/web/landing/templates/example/index.html.twig
+++ b/web/landing/templates/example/index.html.twig
@@ -54,7 +54,7 @@
-
+
{{- code | escape('html') -}}
@@ -69,7 +69,7 @@
-
+
{{- output | escape('html') -}}
diff --git a/web/landing/tests/Flow/Website/Service/Tests/Fixtures/Valid/topics/topic_1/example_1/code.php b/web/landing/tests/Flow/Website/Tests/Fixtures/Valid/topics/topic_1/example_1/code.php
similarity index 100%
rename from web/landing/tests/Flow/Website/Service/Tests/Fixtures/Valid/topics/topic_1/example_1/code.php
rename to web/landing/tests/Flow/Website/Tests/Fixtures/Valid/topics/topic_1/example_1/code.php
diff --git a/web/landing/tests/Flow/Website/Service/Tests/Fixtures/Valid/topics/topic_1/example_2/code.php b/web/landing/tests/Flow/Website/Tests/Fixtures/Valid/topics/topic_1/example_2/code.php
similarity index 100%
rename from web/landing/tests/Flow/Website/Service/Tests/Fixtures/Valid/topics/topic_1/example_2/code.php
rename to web/landing/tests/Flow/Website/Tests/Fixtures/Valid/topics/topic_1/example_2/code.php
diff --git a/web/landing/tests/Flow/Website/Service/Tests/Fixtures/Valid/topics/topic_2/example_1/code.php b/web/landing/tests/Flow/Website/Tests/Fixtures/Valid/topics/topic_2/example_1/code.php
similarity index 100%
rename from web/landing/tests/Flow/Website/Service/Tests/Fixtures/Valid/topics/topic_2/example_1/code.php
rename to web/landing/tests/Flow/Website/Tests/Fixtures/Valid/topics/topic_2/example_1/code.php
diff --git a/web/landing/tests/Flow/Website/Service/Tests/Fixtures/Valid/topics/topic_2/example_2/code.php b/web/landing/tests/Flow/Website/Tests/Fixtures/Valid/topics/topic_2/example_2/code.php
similarity index 100%
rename from web/landing/tests/Flow/Website/Service/Tests/Fixtures/Valid/topics/topic_2/example_2/code.php
rename to web/landing/tests/Flow/Website/Tests/Fixtures/Valid/topics/topic_2/example_2/code.php
diff --git a/web/landing/tests/Flow/Website/Service/Tests/Fixtures/Valid/topics/topic_3/example_1/code.php b/web/landing/tests/Flow/Website/Tests/Fixtures/Valid/topics/topic_3/example_1/code.php
similarity index 100%
rename from web/landing/tests/Flow/Website/Service/Tests/Fixtures/Valid/topics/topic_3/example_1/code.php
rename to web/landing/tests/Flow/Website/Tests/Fixtures/Valid/topics/topic_3/example_1/code.php
diff --git a/web/landing/tests/Flow/Website/Tests/Functional/DocumentationTest.php b/web/landing/tests/Flow/Website/Tests/Functional/DocumentationTest.php
new file mode 100644
index 000000000..841755fde
--- /dev/null
+++ b/web/landing/tests/Flow/Website/Tests/Functional/DocumentationTest.php
@@ -0,0 +1,44 @@
+request('GET', '/documentation/dsl/core/df');
+
+ self::assertResponseIsSuccessful();
+ self::assertSelectorExists('[data-dsl-function]');
+ self::assertSelectorExists('[data-dsl-source-link]');
+ self::assertStringContainsString('https://github.com', $client->getCrawler()->filter('[data-dsl-source-link]')->attr('href'));
+ self::assertSelectorExists('pre');
+ self::assertSelectorExists('code.language-php');
+ }
+
+ public function test_documentation_dsl_page() : void
+ {
+ $client = self::createClient();
+
+ $client->request('GET', '/documentation/dsl');
+
+ self::assertResponseIsSuccessful();
+ self::assertSelectorTextContains('#dsl-functions', 'DSL Functions');
+ self::assertGreaterThan(0, $client->getCrawler()->filter('[data-dsl-function]')->count());
+ self::assertGreaterThan(0, $client->getCrawler()->filter('[data-dsl-source-link]')->count());
+ self::assertEquals(14, $client->getCrawler()->filter('[data-dsl-module]')->count());
+ self::assertEquals(10, $client->getCrawler()->filter('[data-dsl-type]')->count());
+ }
+
+ protected static function getKernelClass() : string
+ {
+ return Kernel::class;
+ }
+}
diff --git a/web/landing/tests/Flow/Website/Service/Tests/Integration/ExamplesTest.php b/web/landing/tests/Flow/Website/Tests/Integration/ExamplesTest.php
similarity index 98%
rename from web/landing/tests/Flow/Website/Service/Tests/Integration/ExamplesTest.php
rename to web/landing/tests/Flow/Website/Tests/Integration/ExamplesTest.php
index 38cbdf10d..0d872bc62 100644
--- a/web/landing/tests/Flow/Website/Service/Tests/Integration/ExamplesTest.php
+++ b/web/landing/tests/Flow/Website/Tests/Integration/ExamplesTest.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace Flow\Website\Service\Tests\Integration;
+namespace Flow\Website\Tests\Integration;
use Flow\Website\Service\Examples;
use PHPUnit\Framework\TestCase;
diff --git a/web/landing/tests/autoload.php b/web/landing/tests/autoload.php
new file mode 100644
index 000000000..a3212a98a
--- /dev/null
+++ b/web/landing/tests/autoload.php
@@ -0,0 +1,19 @@
+loadEnv(__DIR__ . '/../.env.test');
+
+if (\file_exists(__DIR__ . '/../var/log/')) {
+ $testLogs = glob(__DIR__ . '/../var/log/*test.log');
+
+ foreach ($testLogs as $testLog) {
+ if (\is_file($testLog)) {
+ \unlink($testLog);
+ }
+ }
+}