Skip to content

Commit

Permalink
Landing page functional tests (#1195)
Browse files Browse the repository at this point in the history
* Added functional tests to landing page

* CS fixes
  • Loading branch information
norberttech authored Aug 16, 2024
1 parent 5d7bf16 commit 84a8904
Show file tree
Hide file tree
Showing 19 changed files with 205 additions and 41 deletions.
7 changes: 7 additions & 0 deletions web/landing/.env.test
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion web/landing/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
67 changes: 66 additions & 1 deletion web/landing/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions web/landing/importmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,7 @@
'prismjs/components/prism-php.min.js' => [
'version' => '1.29.0',
],
'prismjs/components/prism-json.min.js' => [
'version' => '1.29.0',
],
];
10 changes: 8 additions & 2 deletions web/landing/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="tools/phpunit/vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
bootstrap="tests/autoload.php"
colors="true"
cacheResultFile="./var/phpunit/phpunit.cache"
displayDetailsOnTestsThatTriggerWarnings="true"
displayDetailsOnTestsThatTriggerErrors="true"
executionOrder="random"
>
<php>
<env name="APP_ENV" value="test"/>
</php>
<testsuites>
<testsuite name="integration">
<directory>tests/Flow/Website/**/Tests/Integration</directory>
<directory>tests/Flow/Website/Tests/Integration</directory>
</testsuite>
<testsuite name="functional">
<directory>tests/Flow/Website/Tests/Functional</directory>
</testsuite>
</testsuites>
<source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function toString() : string
public function type() : ?string
{
foreach ($this->data['attributes'] as $attribute) {
if ($attribute['name'] === 'DSL') {
if ($attribute['name'] === 'DocumentationDSL') {
foreach ($attribute['arguments'] as $name => $argument) {
if ($name === 'type') {
return $argument;
Expand Down
14 changes: 14 additions & 0 deletions web/landing/src/Flow/Website/Service/Github.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ public function __construct(

public function contributors() : array
{
if ($this->parameters->get('kernel.environment') === 'test') {
return [
[
'login' => 'norberttech',
'avatar_url' => 'https://avatars.githubusercontent.com/u/1921950?v=4&s=128',
'html_url' => 'https://github.com/norberttech',
],
];
}

$factory = new Psr17Factory();
$client = new Client($factory, $factory);

Expand Down Expand Up @@ -63,6 +73,10 @@ public function contributors() : array

public function version(string $project) : string
{
if ($this->parameters->get('kernel.environment') === 'test') {
return 'v0.0.0';
}

$cache = $this->cache('flow-github-version');

if ($cache->has('version')) {
Expand Down
50 changes: 26 additions & 24 deletions web/landing/templates/documentation/dsl.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
<h1 class="font-bold text-4xl mb-4">Modules</h1>
<ul class="mb-10 mr-6">
{% for module in modules %}
<li class="mb-1">
<li class="mb-1" data-dsl-module="{{ module_name | slugify | lower }}">
<a
href="{{ path('documentation_dsl', {module: module|lower, _fragment:"dsl-functions"}) }}"
class="{% if module| slugify |lower == module_name | slugify |lower %}text-white {% endif %}"
class="{% if module | slugify | lower == module_name | slugify |lower %}text-white {% endif %}"

>{{ module }}</a>
{% if module | slugify |lower == module_name | slugify |lower %}
Expand Down Expand Up @@ -47,37 +47,39 @@
</p>
{% for type in types %}
{% if definitions.onlyType(type).count %}
<h2 id="type-{{ type }}" class="font-bold text-2xl mb-2">
<h2 id="type-{{ type }}" class="font-bold text-2xl mb-2" data-dsl-type="{{ type }}">
<a href="#type-{{ type }}" class="text-white">
{{ type|humanize }}
</a>
</h2>
<hr class="text-blue-100 my-4 border-t-2 rounded" />
{% for definition in definitions.onlyType(type).all %}
<div class="grid grid-cols-2 mb-2">
<div class="text-left">
<h4 class="mb-2 inline" id="dsl-{{ definition.name }}">
<a href="{{ path('documentation_dsl_function', {module: definition.module | slugify | lower, function: definition.name | slugify | lower, _fragment: "dsl-function"}) }}" class="text-white">
<img src="{{ asset('images/icons/link.svg') }}" width="16" height="16" alt="feature" class="inline">
{{ definition.name }}
<article data-dsl-function>
<div class="grid grid-cols-2 mb-2">
<div class="text-left">
<h4 class="mb-2 inline" id="dsl-{{ definition.name }}">
<a href="{{ path('documentation_dsl_function', {module: definition.module | slugify | lower, function: definition.name | slugify | lower, _fragment: "dsl-function"}) }}" class="text-white">
<img src="{{ asset('images/icons/link.svg') }}" width="16" height="16" alt="feature" class="inline">
{{ definition.name }}
</a>
</h4>
</div>
<div class="text-right">
<a href="{{ definition.githubUrl }}" target="_blank" class="text-blue-500 ml-4 inline" title="View on GitHub" data-dsl-source-link>
<img src="{{ asset('images/icons/github.svg') }}" width="16" height="16" alt="feature" class="inline">
source
</a>
</h4>
</div>
</div>
<div class="text-right">
<a href="{{ definition.githubUrl }}" target="_blank" class="text-blue-500 ml-4 inline" title="View on GitHub">
<img src="{{ asset('images/icons/github.svg') }}" width="16" height="16" alt="feature" class="inline">
source
</a>
<div class="rounded shadow-2xl shadow-gray rounded border-gray border-2 mb-4">
{% apply spaceless %}
<pre class="overflow-auto !m-0">
<code id="code" class="language-php" data-prismjs-no-auto-linker {{ stimulus_controller('syntax_highlight') }}>
{{- definition.toString | escape('html') -}}
</code>
</pre>
{% endapply %}
</div>
</div>
<article class="rounded shadow-2xl shadow-gray rounded border-gray border-2 mb-4">
{% apply spaceless %}
<pre class="overflow-auto !m-0">
<code id="code" class="language-php !bg-transparent" data-prismjs-no-auto-linker {{ stimulus_controller('syntax_highlight') }}>
{{- definition.toString | escape('html') -}}
</code>
</pre>
{% endapply %}
</article>
{% endfor %}
{% endif %}
Expand Down
20 changes: 11 additions & 9 deletions web/landing/templates/documentation/dsl/function.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,32 @@
{% for module in modules %}
<li class="mb-1">
<a
href="{{ path('documentation_dsl', {module: module|lower, _fragment:"dsl-functions"}) }}"
class="{% if module| slugify |lower == module_name | slugify |lower %}text-white {% endif %}"
href="{{ path('documentation_dsl', {module: module|lower, _fragment:"dsl-functions"}) }}"
class="{% if module| slugify |lower == module_name | slugify |lower %}text-white {% endif %}"

>{{ module }}</a>
</li>
{% endfor %}
</ul>
</div>
<div class="sm:col-span-5">
<article data-dsl-function>
<h1 id="dsl-function" class="font-bold text-4xl mb-4">Definition</h1>
<hr class="text-blue-100 my-4 border-t-2 rounded" />
<a href="{{ definition.githubUrl }}" target="_blank" class="text-blue-500 block mb-2" title="View on GitHub">
<a href="{{ definition.githubUrl }}" target="_blank" class="text-blue-500 block mb-2" title="View on GitHub" data-dsl-source-link>
<img src="{{ asset('images/icons/github.svg') }}" width="16" height="16" alt="feature" class="inline">
source
</a>
<article class="rounded shadow-2xl shadow-gray rounded border-gray border-2 mb-4">
<div class="rounded shadow-2xl shadow-gray rounded border-gray border-2 mb-4">
{% apply spaceless %}
<pre class="overflow-auto !m-0">
<code id="code" class="language-php !bg-transparent" data-prismjs-no-auto-linker {{ stimulus_controller('syntax_highlight') }}>
<pre class="overflow-auto !m-0">
<code id="code" class="language-php" data-prismjs-no-auto-linker {{ stimulus_controller('syntax_highlight') }}>
{{- definition.toString | escape('html') -}}
</code>
</pre>
</code>
</pre>
{% endapply %}
</article>
</div>
</article>
</div>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions web/landing/templates/example/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<button class="absolute top-0 right-0 bg-orange-100 rounded px-4 leading-9 [&.copied]:before:content-['Copied!'] before:absolute before:-translate-x-24" title="copy code" data-clipboard-target="#code" {{ stimulus_controller('clipboard') }}>
<img src="{{ asset('images/icons/copy.svg') }}" alt="copy code" width="20" height="20" class="inline">
</button>
<code id="code" class="!p-0 !bg-transparent language-php" data-controller="syntax-highlight" >
<code id="code" class="language-php" data-controller="syntax-highlight" >
{{- code | escape('html') -}}
</code>
</pre>
Expand All @@ -69,7 +69,7 @@
<button class="absolute top-0 right-0 bg-orange-100 rounded px-4 leading-9 [&.copied]:before:content-['Copied!'] before:absolute before:-translate-x-24" title="copy code" data-clipboard-target="#output" {{ stimulus_controller('clipboard') }}>
<img src="{{ asset('images/icons/copy.svg') }}" alt="copy code" width="20" height="20" class="inline">
</button>
<code id="output" class="language-bash !p-0 !bg-transparent" {{ stimulus_controller('syntax_highlight') }}>
<code id="output" class="language-bash" {{ stimulus_controller('syntax_highlight') }}>
{{- output | escape('html') -}}
</code>
</pre>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace Flow\Website\Tests\Functional;

use Flow\Website\Kernel;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

final class DocumentationTest extends WebTestCase
{
public function test_documentation_dsl_function_page() : void
{
$client = self::createClient();

$client->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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 19 additions & 0 deletions web/landing/tests/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

use Symfony\Component\Dotenv\Dotenv;

require_once __DIR__ . '/../vendor/autoload.php';

(new Dotenv())->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);
}
}
}

0 comments on commit 84a8904

Please sign in to comment.