@@ -13,202 +13,202 @@ |
||
| 13 | 13 | |
| 14 | 14 | class LiensTest extends TestCase |
| 15 | 15 | { |
| 16 | - public static function setUpBeforeClass(): void { |
|
| 17 | - include_spip('inc/texte'); |
|
| 18 | - include_spip('inc/lang'); |
|
| 19 | - } |
|
| 20 | - |
|
| 21 | - public function testLiensHrefLangAutomatique() { |
|
| 22 | - $article = sql_fetsel( |
|
| 23 | - ['id_article', 'lang'], |
|
| 24 | - 'spip_articles', |
|
| 25 | - [ |
|
| 26 | - 'statut = ' . sql_quote('publie'), |
|
| 27 | - 'lang != ' . sql_quote('') |
|
| 28 | - ], |
|
| 29 | - limit: '0,1', |
|
| 30 | - ); |
|
| 31 | - |
|
| 32 | - $id_article = $article['id_article']; |
|
| 33 | - $lang = $article['lang']; |
|
| 34 | - |
|
| 35 | - // on se met dans une autre langue que celle de l'article |
|
| 36 | - lang_select($lang === 'eo' ? 'fa' : 'eo'); |
|
| 37 | - |
|
| 38 | - $case = '[->' . $id_article . ']'; |
|
| 39 | - $propre = propre($case); |
|
| 40 | - $this->assertEquals( |
|
| 41 | - $lang, |
|
| 42 | - extraire_attribut($propre, 'hreflang'), |
|
| 43 | - sprintf('hreflang automatique errone dans "%s". Propre: "%s"', $case, $propre) |
|
| 44 | - ); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - #[DataProvider('providerLiensClassCss')] |
|
| 48 | - public function testLiensClassCss(string $table, ?string $short, bool $in) { |
|
| 49 | - $id = sql_getfetsel(id_table_objet($table), $table, "statut='publie'", limit: '0,1'); |
|
| 50 | - $type = objet_type($table); |
|
| 51 | - if (!$id) { |
|
| 52 | - $this->markTestSkipped(sprintf('Necessite un·e %s publié', $type)); |
|
| 53 | - } |
|
| 54 | - $cases = ["[->$type{$id}]"]; |
|
| 55 | - if ($short) { |
|
| 56 | - $cases[] = "[->$short{$id}]"; |
|
| 57 | - } |
|
| 58 | - foreach ($cases as $case) { |
|
| 59 | - $propre = propre($case); |
|
| 60 | - $classes = extraire_attribut($propre, 'class'); |
|
| 61 | - $err = sprintf('Classe CSS "%s" errone dans "%s". Propre: "%s"', (string) $classes, $case, $propre); |
|
| 62 | - $this->assertNotNull($classes, $err); |
|
| 63 | - if ($in) { |
|
| 64 | - $this->assertStringContainsString('spip_in', $classes, $err); |
|
| 65 | - $this->assertStringNotContainsString('spip_out', $classes, $err); |
|
| 66 | - } else { |
|
| 67 | - $this->assertStringContainsString('spip_out', $classes, $err); |
|
| 68 | - $this->assertStringNotContainsString('spip_in', $classes, $err); |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - public static function providerLiensClassCss(): array { |
|
| 74 | - return [ |
|
| 75 | - 'article' => [ |
|
| 76 | - 'table' => 'spip_articles', |
|
| 77 | - 'short' => 'art', |
|
| 78 | - 'in' => true |
|
| 79 | - ], |
|
| 80 | - 'rubrique' => [ |
|
| 81 | - 'table' => 'spip_rubriques', |
|
| 82 | - 'short' => 'rub', |
|
| 83 | - 'in' => true |
|
| 84 | - ], |
|
| 85 | - 'site' => [ |
|
| 86 | - 'table' => 'spip_syndic', |
|
| 87 | - 'short' => null, |
|
| 88 | - 'in' => false |
|
| 89 | - ], |
|
| 90 | - ]; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - #[DataProvider('providerLiens')] |
|
| 94 | - public function testLiens($case, $url, $hreflang, $title, $text) { |
|
| 95 | - lang_select('eo'); |
|
| 96 | - $propre = propre($case); |
|
| 97 | - $this->assertEquals( |
|
| 98 | - $url, |
|
| 99 | - extraire_attribut($propre, 'href'), |
|
| 100 | - sprintf('URL mal extraite de "%s". Propre: "%s"', $case, $propre) |
|
| 101 | - ); |
|
| 102 | - $this->assertEquals( |
|
| 103 | - $hreflang, |
|
| 104 | - extraire_attribut($propre, 'hreflang'), |
|
| 105 | - sprintf('Hreflang erroné dans "%s". Propre: "%s"', $case, $propre) |
|
| 106 | - ); |
|
| 107 | - $this->assertEquals( |
|
| 108 | - $title, |
|
| 109 | - extraire_attribut($propre, 'title'), |
|
| 110 | - sprintf('Title erroné dans "%s". Propre: "%s"', $case, $propre) |
|
| 111 | - ); |
|
| 112 | - $this->assertEquals( |
|
| 113 | - $text, |
|
| 114 | - supprimer_tags($propre), |
|
| 115 | - sprintf('Texte du lien abîmé dans "%s". Propre: "%s"', $case, $propre) |
|
| 116 | - ); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - public static function providerLiens(): array { |
|
| 120 | - return [ |
|
| 121 | - 'hreflang incorrect spécifié ignoré' => [ |
|
| 122 | - 'case' => '[bla {blabla}->url]', |
|
| 123 | - 'url' => 'url', |
|
| 124 | - 'hreflang' => null, |
|
| 125 | - 'title' => null, |
|
| 126 | - 'text' => 'bla blabla' |
|
| 127 | - ], |
|
| 128 | - 'hreflang correct spécifié pris en compte' => [ |
|
| 129 | - 'case' => '[bla{en}->url]', |
|
| 130 | - 'url' => 'url', |
|
| 131 | - 'hreflang' => 'en', |
|
| 132 | - 'title' => null, |
|
| 133 | - 'text' => 'bla' |
|
| 134 | - ], |
|
| 135 | - 'title spécifié pris en compte' => [ |
|
| 136 | - 'case' => '[bla|bulle de savon{eo}->url]', |
|
| 137 | - 'url' => 'url', |
|
| 138 | - 'hreflang' => 'eo', |
|
| 139 | - 'title' => 'bulle de savon', |
|
| 140 | - 'text' => 'bla' |
|
| 141 | - ], |
|
| 142 | - 'title comme une langue devient hreflang aussi' => [ |
|
| 143 | - 'case' => '[bla|fa->url]', |
|
| 144 | - 'url' => 'url', |
|
| 145 | - 'hreflang' => 'fa', |
|
| 146 | - 'title' => 'fa', |
|
| 147 | - 'text' => 'bla' |
|
| 148 | - ], |
|
| 149 | - 'title autre qu’une langue ne contamine pas hreflang' => [ |
|
| 150 | - 'case' => '[bla|bulle de savon->url]', |
|
| 151 | - 'url' => 'url', |
|
| 152 | - 'hreflang' => null, |
|
| 153 | - 'title' => 'bulle de savon', |
|
| 154 | - 'text' => 'bla' |
|
| 155 | - ], |
|
| 156 | - 'multi dans liens' => [ |
|
| 157 | - 'case' => '[<multi>[fr]X[eo]Y[fa]Z</multi>->url]', |
|
| 158 | - 'url' => 'url', |
|
| 159 | - 'hreflang' => null, |
|
| 160 | - 'title' => null, |
|
| 161 | - 'text' => 'Y' |
|
| 162 | - ], |
|
| 163 | - ]; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - #[DataProvider('providerLiensAutomatiques')] |
|
| 167 | - public function testLiensAutomatiques($case, $url) { |
|
| 168 | - $propre = propre($case); |
|
| 169 | - $this->assertEquals( |
|
| 170 | - $url, |
|
| 171 | - extraire_attribut(extraire_balise($propre, 'a'), 'href'), |
|
| 172 | - sprintf('Erreur lien dans "%s". Propre: "%s"', $case, $propre) |
|
| 173 | - ); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - public static function providerLiensAutomatiques(): array { |
|
| 177 | - return [ |
|
| 178 | - 'sans protocole' => [ |
|
| 179 | - 'case' => 'un superbe www.monsite.tld, pas mal', |
|
| 180 | - 'url' => 'http://www.monsite.tld', |
|
| 181 | - ], |
|
| 182 | - 'protocole http' => [ |
|
| 183 | - 'case' => 'un superbe http://www.monsite.tld, pas mal', |
|
| 184 | - 'url' => 'http://www.monsite.tld', |
|
| 185 | - ], |
|
| 186 | - 'protocole https' => [ |
|
| 187 | - 'case' => 'un superbe https://www.monsite.tld, pas mal', |
|
| 188 | - 'url' => 'https://www.monsite.tld', |
|
| 189 | - ], |
|
| 190 | - ]; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - public function testLiensAvecAncre() { |
|
| 194 | - $case = '[uneancre<-] a [->www.monsite.tld]'; |
|
| 195 | - $url = 'http://www.monsite.tld'; |
|
| 196 | - $propre = propre($case); |
|
| 197 | - $this->assertEquals( |
|
| 198 | - $url, |
|
| 199 | - extraire_attribut(extraire_balises($propre, 'a')[1], 'href'), |
|
| 200 | - sprintf('Erreur lien dans "%s". Propre: "%s"', $case, $propre) |
|
| 201 | - ); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - public function testLienModele() { |
|
| 205 | - $case = '<flv|url=http://rezo.net/>'; |
|
| 206 | - $propre = propre($case); |
|
| 207 | - $expected = '<p><tt><flv|url=http://rezo.net/></tt></p>'; |
|
| 208 | - $this->assertEquals( |
|
| 209 | - $expected, |
|
| 210 | - $propre, |
|
| 211 | - sprintf('Erreur lien dans "%s". Propre: "%s"', $case, $propre) |
|
| 212 | - ); |
|
| 213 | - } |
|
| 16 | + public static function setUpBeforeClass(): void { |
|
| 17 | + include_spip('inc/texte'); |
|
| 18 | + include_spip('inc/lang'); |
|
| 19 | + } |
|
| 20 | + |
|
| 21 | + public function testLiensHrefLangAutomatique() { |
|
| 22 | + $article = sql_fetsel( |
|
| 23 | + ['id_article', 'lang'], |
|
| 24 | + 'spip_articles', |
|
| 25 | + [ |
|
| 26 | + 'statut = ' . sql_quote('publie'), |
|
| 27 | + 'lang != ' . sql_quote('') |
|
| 28 | + ], |
|
| 29 | + limit: '0,1', |
|
| 30 | + ); |
|
| 31 | + |
|
| 32 | + $id_article = $article['id_article']; |
|
| 33 | + $lang = $article['lang']; |
|
| 34 | + |
|
| 35 | + // on se met dans une autre langue que celle de l'article |
|
| 36 | + lang_select($lang === 'eo' ? 'fa' : 'eo'); |
|
| 37 | + |
|
| 38 | + $case = '[->' . $id_article . ']'; |
|
| 39 | + $propre = propre($case); |
|
| 40 | + $this->assertEquals( |
|
| 41 | + $lang, |
|
| 42 | + extraire_attribut($propre, 'hreflang'), |
|
| 43 | + sprintf('hreflang automatique errone dans "%s". Propre: "%s"', $case, $propre) |
|
| 44 | + ); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + #[DataProvider('providerLiensClassCss')] |
|
| 48 | + public function testLiensClassCss(string $table, ?string $short, bool $in) { |
|
| 49 | + $id = sql_getfetsel(id_table_objet($table), $table, "statut='publie'", limit: '0,1'); |
|
| 50 | + $type = objet_type($table); |
|
| 51 | + if (!$id) { |
|
| 52 | + $this->markTestSkipped(sprintf('Necessite un·e %s publié', $type)); |
|
| 53 | + } |
|
| 54 | + $cases = ["[->$type{$id}]"]; |
|
| 55 | + if ($short) { |
|
| 56 | + $cases[] = "[->$short{$id}]"; |
|
| 57 | + } |
|
| 58 | + foreach ($cases as $case) { |
|
| 59 | + $propre = propre($case); |
|
| 60 | + $classes = extraire_attribut($propre, 'class'); |
|
| 61 | + $err = sprintf('Classe CSS "%s" errone dans "%s". Propre: "%s"', (string) $classes, $case, $propre); |
|
| 62 | + $this->assertNotNull($classes, $err); |
|
| 63 | + if ($in) { |
|
| 64 | + $this->assertStringContainsString('spip_in', $classes, $err); |
|
| 65 | + $this->assertStringNotContainsString('spip_out', $classes, $err); |
|
| 66 | + } else { |
|
| 67 | + $this->assertStringContainsString('spip_out', $classes, $err); |
|
| 68 | + $this->assertStringNotContainsString('spip_in', $classes, $err); |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + public static function providerLiensClassCss(): array { |
|
| 74 | + return [ |
|
| 75 | + 'article' => [ |
|
| 76 | + 'table' => 'spip_articles', |
|
| 77 | + 'short' => 'art', |
|
| 78 | + 'in' => true |
|
| 79 | + ], |
|
| 80 | + 'rubrique' => [ |
|
| 81 | + 'table' => 'spip_rubriques', |
|
| 82 | + 'short' => 'rub', |
|
| 83 | + 'in' => true |
|
| 84 | + ], |
|
| 85 | + 'site' => [ |
|
| 86 | + 'table' => 'spip_syndic', |
|
| 87 | + 'short' => null, |
|
| 88 | + 'in' => false |
|
| 89 | + ], |
|
| 90 | + ]; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + #[DataProvider('providerLiens')] |
|
| 94 | + public function testLiens($case, $url, $hreflang, $title, $text) { |
|
| 95 | + lang_select('eo'); |
|
| 96 | + $propre = propre($case); |
|
| 97 | + $this->assertEquals( |
|
| 98 | + $url, |
|
| 99 | + extraire_attribut($propre, 'href'), |
|
| 100 | + sprintf('URL mal extraite de "%s". Propre: "%s"', $case, $propre) |
|
| 101 | + ); |
|
| 102 | + $this->assertEquals( |
|
| 103 | + $hreflang, |
|
| 104 | + extraire_attribut($propre, 'hreflang'), |
|
| 105 | + sprintf('Hreflang erroné dans "%s". Propre: "%s"', $case, $propre) |
|
| 106 | + ); |
|
| 107 | + $this->assertEquals( |
|
| 108 | + $title, |
|
| 109 | + extraire_attribut($propre, 'title'), |
|
| 110 | + sprintf('Title erroné dans "%s". Propre: "%s"', $case, $propre) |
|
| 111 | + ); |
|
| 112 | + $this->assertEquals( |
|
| 113 | + $text, |
|
| 114 | + supprimer_tags($propre), |
|
| 115 | + sprintf('Texte du lien abîmé dans "%s". Propre: "%s"', $case, $propre) |
|
| 116 | + ); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + public static function providerLiens(): array { |
|
| 120 | + return [ |
|
| 121 | + 'hreflang incorrect spécifié ignoré' => [ |
|
| 122 | + 'case' => '[bla {blabla}->url]', |
|
| 123 | + 'url' => 'url', |
|
| 124 | + 'hreflang' => null, |
|
| 125 | + 'title' => null, |
|
| 126 | + 'text' => 'bla blabla' |
|
| 127 | + ], |
|
| 128 | + 'hreflang correct spécifié pris en compte' => [ |
|
| 129 | + 'case' => '[bla{en}->url]', |
|
| 130 | + 'url' => 'url', |
|
| 131 | + 'hreflang' => 'en', |
|
| 132 | + 'title' => null, |
|
| 133 | + 'text' => 'bla' |
|
| 134 | + ], |
|
| 135 | + 'title spécifié pris en compte' => [ |
|
| 136 | + 'case' => '[bla|bulle de savon{eo}->url]', |
|
| 137 | + 'url' => 'url', |
|
| 138 | + 'hreflang' => 'eo', |
|
| 139 | + 'title' => 'bulle de savon', |
|
| 140 | + 'text' => 'bla' |
|
| 141 | + ], |
|
| 142 | + 'title comme une langue devient hreflang aussi' => [ |
|
| 143 | + 'case' => '[bla|fa->url]', |
|
| 144 | + 'url' => 'url', |
|
| 145 | + 'hreflang' => 'fa', |
|
| 146 | + 'title' => 'fa', |
|
| 147 | + 'text' => 'bla' |
|
| 148 | + ], |
|
| 149 | + 'title autre qu’une langue ne contamine pas hreflang' => [ |
|
| 150 | + 'case' => '[bla|bulle de savon->url]', |
|
| 151 | + 'url' => 'url', |
|
| 152 | + 'hreflang' => null, |
|
| 153 | + 'title' => 'bulle de savon', |
|
| 154 | + 'text' => 'bla' |
|
| 155 | + ], |
|
| 156 | + 'multi dans liens' => [ |
|
| 157 | + 'case' => '[<multi>[fr]X[eo]Y[fa]Z</multi>->url]', |
|
| 158 | + 'url' => 'url', |
|
| 159 | + 'hreflang' => null, |
|
| 160 | + 'title' => null, |
|
| 161 | + 'text' => 'Y' |
|
| 162 | + ], |
|
| 163 | + ]; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + #[DataProvider('providerLiensAutomatiques')] |
|
| 167 | + public function testLiensAutomatiques($case, $url) { |
|
| 168 | + $propre = propre($case); |
|
| 169 | + $this->assertEquals( |
|
| 170 | + $url, |
|
| 171 | + extraire_attribut(extraire_balise($propre, 'a'), 'href'), |
|
| 172 | + sprintf('Erreur lien dans "%s". Propre: "%s"', $case, $propre) |
|
| 173 | + ); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + public static function providerLiensAutomatiques(): array { |
|
| 177 | + return [ |
|
| 178 | + 'sans protocole' => [ |
|
| 179 | + 'case' => 'un superbe www.monsite.tld, pas mal', |
|
| 180 | + 'url' => 'http://www.monsite.tld', |
|
| 181 | + ], |
|
| 182 | + 'protocole http' => [ |
|
| 183 | + 'case' => 'un superbe http://www.monsite.tld, pas mal', |
|
| 184 | + 'url' => 'http://www.monsite.tld', |
|
| 185 | + ], |
|
| 186 | + 'protocole https' => [ |
|
| 187 | + 'case' => 'un superbe https://www.monsite.tld, pas mal', |
|
| 188 | + 'url' => 'https://www.monsite.tld', |
|
| 189 | + ], |
|
| 190 | + ]; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + public function testLiensAvecAncre() { |
|
| 194 | + $case = '[uneancre<-] a [->www.monsite.tld]'; |
|
| 195 | + $url = 'http://www.monsite.tld'; |
|
| 196 | + $propre = propre($case); |
|
| 197 | + $this->assertEquals( |
|
| 198 | + $url, |
|
| 199 | + extraire_attribut(extraire_balises($propre, 'a')[1], 'href'), |
|
| 200 | + sprintf('Erreur lien dans "%s". Propre: "%s"', $case, $propre) |
|
| 201 | + ); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + public function testLienModele() { |
|
| 205 | + $case = '<flv|url=http://rezo.net/>'; |
|
| 206 | + $propre = propre($case); |
|
| 207 | + $expected = '<p><tt><flv|url=http://rezo.net/></tt></p>'; |
|
| 208 | + $this->assertEquals( |
|
| 209 | + $expected, |
|
| 210 | + $propre, |
|
| 211 | + sprintf('Erreur lien dans "%s". Propre: "%s"', $case, $propre) |
|
| 212 | + ); |
|
| 213 | + } |
|
| 214 | 214 | } |
@@ -23,8 +23,8 @@ discard block |
||
| 23 | 23 | ['id_article', 'lang'], |
| 24 | 24 | 'spip_articles', |
| 25 | 25 | [ |
| 26 | - 'statut = ' . sql_quote('publie'), |
|
| 27 | - 'lang != ' . sql_quote('') |
|
| 26 | + 'statut = '.sql_quote('publie'), |
|
| 27 | + 'lang != '.sql_quote('') |
|
| 28 | 28 | ], |
| 29 | 29 | limit: '0,1', |
| 30 | 30 | ); |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | // on se met dans une autre langue que celle de l'article |
| 36 | 36 | lang_select($lang === 'eo' ? 'fa' : 'eo'); |
| 37 | 37 | |
| 38 | - $case = '[->' . $id_article . ']'; |
|
| 38 | + $case = '[->'.$id_article.']'; |
|
| 39 | 39 | $propre = propre($case); |
| 40 | 40 | $this->assertEquals( |
| 41 | 41 | $lang, |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | |
| 47 | 47 | #[DataProvider('providerLiensClassCss')] |
| 48 | 48 | public function testLiensClassCss(string $table, ?string $short, bool $in) { |
| 49 | - $id = sql_getfetsel(id_table_objet($table), $table, "statut='publie'", limit: '0,1'); |
|
| 49 | + $id = sql_getfetsel(id_table_objet($table), $table, "statut='publie'", limit : '0,1'); |
|
| 50 | 50 | $type = objet_type($table); |
| 51 | 51 | if (!$id) { |
| 52 | 52 | $this->markTestSkipped(sprintf('Necessite un·e %s publié', $type)); |