Skip to content

Commit 31778d5

Browse files
authored
Ajout de tests pour le rendu des articles en front (#1938)
Les anciens articles étaient rédigés en HTML et sont stockés en HTML. Les nouveaux sont en markdown avec un rendu HTML en front. Le test s'assure que les deux formats sont affichés correctement.
1 parent a41a1d8 commit 31778d5

File tree

4 files changed

+110
-3
lines changed

4 files changed

+110
-3
lines changed

db/seeds/Articles.php

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
declare(strict_types=1);
44

5+
use Afup\Site\Corporate\Article;
56
use AppBundle\Site\Model\Rubrique;
67
use Cocur\Slugify\Slugify;
78
use Faker\Factory;
@@ -20,7 +21,6 @@ public function run(): void
2021
<p>Hormis la conf&eacute;rence "Cessons les estimations" de Fr&eacute;d&eacute;ric Legu&eacute;dois, qui n'&eacute;tait pas capt&eacute;e <a href="https://www.leguedois.fr/pourquoi-les-conferences-ne-sont-pas-filmees/">&agrave; sa demande</a>, tous les talks sont disponibles sur notre page "<a href="../../talks/">vid&eacute;os</a>". Faites passer &agrave; vos voisins et coll&egrave;gues, visionnez les sujets que vous avez manqu&eacute;s, revoyez ce talk qui vous a fascin&eacute;, et surtout, surtout, imaginez le plaisir de les voir en live : <strong>venez nous voir en octobre au Forum PHP 2019 ou en mai &agrave; l'AFUP Day !&nbsp;</strong></p>
2122
EOF;
2223

23-
2424
$data = [
2525
[
2626
'titre' => "Les vidéos des talks du Forum PHP 2018 sont disponibles",
@@ -31,9 +31,13 @@ public function run(): void
3131
'date' => 1542150000,
3232
'id_forum' => Event::ID_FORUM,
3333
'etat' => 1,
34+
'type_contenu' => Article::TYPE_CONTENU_HTML,
3435
],
3536
];
3637

38+
$data[] = $this->createMarkdownArticle();
39+
$data[] = $this->createHTMLArticle();
40+
3741
$slugger = Slugify::create();
3842
$faker = Factory::create();
3943
for ($i = 1; $i < 15; $i++) {
@@ -46,6 +50,7 @@ public function run(): void
4650
'id_site_rubrique' => Rubrique::ID_RUBRIQUE_ACTUALITES,
4751
'date' => $faker->unixTime(new DateTime('2017-12-31T23:59:59')),
4852
'etat' => 1,
53+
'type_contenu' => Article::TYPE_CONTENU_HTML,
4954
];
5055
}
5156

@@ -57,4 +62,63 @@ public function run(): void
5762
->save()
5863
;
5964
}
65+
66+
private function createMarkdownArticle(): array
67+
{
68+
$contenu = <<<MARKDOWN
69+
### Un premier titre !
70+
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquam aperiam dolor, eligendi expedita nisi quibusdam repellendus repudiandae!
71+
72+
### Encore un titre
73+
Un peu **de texte en gras**.
74+
<br><br>
75+
Et un peu *de texte en italic*.
76+
77+
### Une dernière section
78+
Un texte avec un lien [commodi delectus](https://afup.org) et encore un peu de texte.
79+
MARKDOWN;
80+
81+
return [
82+
'titre' => "Un article en Markdown",
83+
'chapeau' => "*Un peu* de text **avec de la mise** en forme",
84+
'contenu' => $contenu,
85+
'raccourci' => 'un-article-en-markdown',
86+
'id_site_rubrique' => Rubrique::ID_RUBRIQUE_ACTUALITES,
87+
'date' => 1761859722,
88+
'id_forum' => Event::ID_FORUM,
89+
'etat' => 1,
90+
'type_contenu' => Article::TYPE_CONTENU_MARKDOWN,
91+
];
92+
}
93+
94+
private function createHTMLArticle(): array
95+
{
96+
$contenu = <<<HTML
97+
<h3>Un premier titre !</h3>
98+
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquam aperiam dolor, eligendi expedita nisi quibusdam repellendus repudiandae!</p>
99+
100+
<h3>Encore un titre</h3>
101+
<p>Un peu <strong>de texte en gras</strong>.
102+
<br><br>
103+
Et un peu <em>de texte en italic</em>.</p>
104+
105+
<h3>Une dernière section</h3>
106+
<p>Un texte avec un lien <a href="https://afup.org">commodi delectus</a> et encore un peu de texte.
107+
<br><br>
108+
<strong>Un peu de gras
109+
avec un saut de ligne en base</strong></p>
110+
HTML;
111+
112+
return [
113+
'titre' => "Un article en HTML",
114+
'chapeau' => "<p>Lorem <strong>ipsum</strong> dolor si amet.</p>",
115+
'contenu' => $contenu,
116+
'raccourci' => 'un-article-en-html',
117+
'id_site_rubrique' => Rubrique::ID_RUBRIQUE_ACTUALITES,
118+
'date' => 1761858722,
119+
'id_forum' => Event::ID_FORUM,
120+
'etat' => 1,
121+
'type_contenu' => Article::TYPE_CONTENU_HTML,
122+
];
123+
}
60124
}

tests/behat/bootstrap/FeatureContext.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,19 @@ public function assertResponseHasJsonKeyAndValue(string $key, string $value): vo
232232
$this->minkContext->assertResponseContains(sprintf('"%s":"%s"', $key, $value));
233233
}
234234

235+
/**
236+
* @Then /^the response should contain the html "(?P<text>(?:[^"]|\\")*)"$/
237+
* @Then /^the response should contain the html$/
238+
*/
239+
public function assertResponseHasHtml(PyStringNode|string $html): void
240+
{
241+
if ($html instanceof PyStringNode) {
242+
$html = $html->getRaw();
243+
}
244+
245+
$this->minkContext->assertResponseContains($html);
246+
}
247+
235248
/**
236249
* @Then the current URL should match :arg1
237250
* @throws ExpectationException

tests/behat/features/Admin/Site/AdminSiteArticles.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Feature: Administration - Partie Site
4040
When I should see "Liste des articles"
4141
Then the ".content table" element should contain "Le titre de l'article"
4242
# vérification de l'article sur le site publique
43-
When I go to "/news/16-url-article"
43+
When I go to "/news/18-url-article"
4444
Then I should see "Le titre de l'article"
4545
Then I should see "Le chapeau de l'article"
4646
Then I should see "Le contenu de l'article"

tests/behat/features/PublicSite/News.feature

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,41 @@ Feature: Site Public - News
1616
When I follow "Actualités"
1717
Then I should see "Actualités"
1818
And I should see "Les vidéos des talks du Forum PHP 2018 sont disponibles"
19-
And I check "news_filters_year_0"
19+
And I check "news_filters_year_1"
2020
And I submit the form with name "news_filters"
2121
And I should be on "/news/?news_filters[year][0]=2018"
2222
And I should see "Les vidéos des talks du Forum PHP 2018 sont disponibles"
2323
And I check "news_filters_theme_0"
2424
And I submit the form with name "news_filters"
2525
And I should be on "/news/?news_filters[theme][0]=1"
2626
And I should not see "Les vidéos des talks du Forum PHP 2018 sont disponibles"
27+
28+
@reloadDbWithTestData
29+
Scenario: Affichage d'un article MARKDOWN
30+
Given I am on the homepage
31+
When I follow "Actualités"
32+
And I follow "Lire l'article: Un article en Markdown"
33+
Then I should not see "### Un premier titre !"
34+
And the response should contain the html "<h3>Un premier titre !</h3>"
35+
And I should not see "**de texte en gras**"
36+
And the response should contain the html "<strong>de texte en gras</strong>"
37+
And I should not see "*de texte en italic*"
38+
And the response should contain the html "<em>de texte en italic</em>"
39+
And I should not see "[commodi delectus](https://afup.org)"
40+
And the response should contain the html
41+
"""
42+
<a href="https://afup.org">commodi delectus</a>
43+
"""
44+
45+
@reloadDbWithTestData
46+
Scenario: Affichage d'un article HTML
47+
Given I am on the homepage
48+
When I follow "Actualités"
49+
And I follow "Lire l'article: Un article en HTML"
50+
And the response should contain the html "<h3>Un premier titre !</h3>"
51+
And the response should contain the html "<strong>de texte en gras</strong>"
52+
And the response should contain the html "<em>de texte en italic</em>"
53+
And the response should contain the html
54+
"""
55+
<a href="https://afup.org">commodi delectus</a>
56+
"""

0 commit comments

Comments
 (0)