|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Tests of the language parsing methods within mf2\Parser |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Mf2\Parser\Test; |
| 8 | + |
| 9 | +use Mf2\Parser; |
| 10 | +use Mf2; |
| 11 | +use PHPUnit_Framework_TestCase; |
| 12 | + |
| 13 | +class ParseLanguageTest extends PHPUnit_Framework_TestCase { |
| 14 | + |
| 15 | + public function setUp() { |
| 16 | + date_default_timezone_set('Europe/London'); |
| 17 | + } |
| 18 | + |
| 19 | + /** |
| 20 | + * Test with only <html lang> |
| 21 | + */ |
| 22 | + public function testHtmlLangOnly() |
| 23 | + { |
| 24 | + $input = '<html lang="en"> <div class="h-entry">This test is in English.</div> </html>'; |
| 25 | + $parser = new Parser($input); |
| 26 | + $result = $parser->parse(); |
| 27 | + |
| 28 | + $this->assertEquals('en', $result['items'][0]['properties']['html-lang']); |
| 29 | + } # end method testHtmlLangOnly() |
| 30 | + |
| 31 | + /** |
| 32 | + * Test with only h-entry lang |
| 33 | + */ |
| 34 | + public function testHEntryLangOnly() |
| 35 | + { |
| 36 | + $input = '<html> <div class="h-entry" lang="en">This test is in English.</div> </html>'; |
| 37 | + $parser = new Parser($input); |
| 38 | + $result = $parser->parse(); |
| 39 | + |
| 40 | + $this->assertEquals('en', $result['items'][0]['properties']['html-lang']); |
| 41 | + } # end method testHEntryLangOnly() |
| 42 | + |
| 43 | + /** |
| 44 | + * Test with different <html lang> and h-entry lang |
| 45 | + */ |
| 46 | + public function testHtmlAndHEntryLang() |
| 47 | + { |
| 48 | + $input = '<html lang="en"> <div class="h-entry" lang="es">Esta prueba está en español.</div> </html>'; |
| 49 | + $parser = new Parser($input); |
| 50 | + $result = $parser->parse(); |
| 51 | + |
| 52 | + $this->assertEquals('es', $result['items'][0]['properties']['html-lang']); |
| 53 | + } # end method testHtmlAndHEntryLang() |
| 54 | + |
| 55 | + /** |
| 56 | + * Test with different <html lang>, h-entry lang, and h-entry without lang, |
| 57 | + * which should inherit from the <html lang> |
| 58 | + */ |
| 59 | + public function testMultiLanguageInheritance() |
| 60 | + { |
| 61 | + $input = '<html lang="en"> <div class="h-entry">This test is in English.</div> <div class="h-entry" lang="es">Esta prueba está en español.</div> </html>'; |
| 62 | + $parser = new Parser($input); |
| 63 | + $result = $parser->parse(); |
| 64 | + |
| 65 | + $this->assertEquals('en', $result['items'][0]['properties']['html-lang']); |
| 66 | + $this->assertEquals('es', $result['items'][1]['properties']['html-lang']); |
| 67 | + } # end method testMultiLanguageInheritance() |
| 68 | + |
| 69 | + /** |
| 70 | + * Test feed with .h-feed lang which contains multiple h-entries of different languages |
| 71 | + * (or none specified), which should inherit from the .h-feed lang. |
| 72 | + */ |
| 73 | + public function testMultiLanguageFeed() |
| 74 | + { |
| 75 | + $input = '<html> <div class="h-feed" lang="en"> <h1 class="p-name">Test Feed</h1> <div class="h-entry">This test is in English.</div> <div class="h-entry" lang="es">Esta prueba está en español.</div> <div class="h-entry" lang="fr">Ce test est en français.</div> </html>'; |
| 76 | + $parser = new Parser($input); |
| 77 | + $result = $parser->parse(); |
| 78 | + |
| 79 | + $this->assertEquals('en', $result['items'][0]['properties']['html-lang']); |
| 80 | + $this->assertEquals('en', $result['items'][0]['children'][0]['properties']['html-lang']); |
| 81 | + $this->assertEquals('es', $result['items'][0]['children'][1]['properties']['html-lang']); |
| 82 | + $this->assertEquals('fr', $result['items'][0]['children'][2]['properties']['html-lang']); |
| 83 | + } # end method testMultiLanguageFeed() |
| 84 | + |
| 85 | + /** |
| 86 | + * Test with language specified in <meta> http-equiv Content-Language |
| 87 | + */ |
| 88 | + public function testMetaContentLanguage() |
| 89 | + { |
| 90 | + $input = '<html> <meta http-equiv="Content-Language" content="es"/> <div class="h-entry">Esta prueba está en español.</div> </html>'; |
| 91 | + $parser = new Parser($input); |
| 92 | + $result = $parser->parse(); |
| 93 | + |
| 94 | + $this->assertEquals('es', $result['items'][0]['properties']['html-lang']); |
| 95 | + } # end method testMetaContentLanguage() |
| 96 | + |
| 97 | +} |
0 commit comments