|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace SIL\Tests; |
| 4 | + |
| 5 | +use SIL\AnnotatedLanguageParserFunction; |
| 6 | + |
| 7 | +/** |
| 8 | + * @covers \SIL\AnnotatedLanguageParserFunction |
| 9 | + * @group semantic-interlanguage-links |
| 10 | + * |
| 11 | + * @license GNU GPL v2+ |
| 12 | + * @since 1.0 |
| 13 | + * |
| 14 | + * @author mwjames |
| 15 | + */ |
| 16 | +class AnnotatedLanguageParserFunctionTest extends \PHPUnit_Framework_TestCase { |
| 17 | + |
| 18 | + public function testCanConstruct() { |
| 19 | + |
| 20 | + $interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' ) |
| 21 | + ->disableOriginalConstructor() |
| 22 | + ->getMock(); |
| 23 | + |
| 24 | + $this->assertInstanceOf( |
| 25 | + AnnotatedLanguageParserFunction::class, |
| 26 | + new AnnotatedLanguageParserFunction( $interlanguageLinksLookup ) |
| 27 | + ); |
| 28 | + } |
| 29 | + |
| 30 | + public function testParseOnMissingAnnotatedLanguage() { |
| 31 | + |
| 32 | + $interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' ) |
| 33 | + ->disableOriginalConstructor() |
| 34 | + ->getMock(); |
| 35 | + |
| 36 | + $interlanguageLinksLookup->expects( $this->once() ) |
| 37 | + ->method( 'findPageLanguageForTarget' ) |
| 38 | + ->will( $this->returnValue( '' ) ); |
| 39 | + |
| 40 | + $interlanguageLinksLookup->expects( $this->once() ) |
| 41 | + ->method( 'getRedirectTargetFor' ) |
| 42 | + ->will( $this->returnValue( \Title::newFromText( 'Foo' ) ) ); |
| 43 | + |
| 44 | + $instance = new AnnotatedLanguageParserFunction( |
| 45 | + $interlanguageLinksLookup |
| 46 | + ); |
| 47 | + |
| 48 | + $this->assertEquals( |
| 49 | + '', |
| 50 | + $instance->parse( \Title::newFromText( 'Foo' ), 'FakeTemplate' ) |
| 51 | + ); |
| 52 | + } |
| 53 | + |
| 54 | + public function testParseOnAnnotatedLanguageWithoutTemplate() { |
| 55 | + |
| 56 | + $interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' ) |
| 57 | + ->disableOriginalConstructor() |
| 58 | + ->getMock(); |
| 59 | + |
| 60 | + $interlanguageLinksLookup->expects( $this->once() ) |
| 61 | + ->method( 'findPageLanguageForTarget' ) |
| 62 | + ->will( $this->returnValue( 'en' ) ); |
| 63 | + |
| 64 | + $interlanguageLinksLookup->expects( $this->once() ) |
| 65 | + ->method( 'getRedirectTargetFor' ) |
| 66 | + ->will( $this->returnValue( \Title::newFromText( 'Foo' ) ) ); |
| 67 | + |
| 68 | + $instance = new AnnotatedLanguageParserFunction( |
| 69 | + $interlanguageLinksLookup |
| 70 | + ); |
| 71 | + |
| 72 | + $expected = 'en'; |
| 73 | + |
| 74 | + $this->assertEquals( |
| 75 | + $expected, |
| 76 | + $instance->parse( \Title::newFromText( 'Foo' ), '' ) |
| 77 | + ); |
| 78 | + } |
| 79 | + |
| 80 | + public function testParseOnAnnotatedLanguageWithTemplate() { |
| 81 | + |
| 82 | + $interlanguageLinksLookup = $this->getMockBuilder( '\SIL\InterlanguageLinksLookup' ) |
| 83 | + ->disableOriginalConstructor() |
| 84 | + ->getMock(); |
| 85 | + |
| 86 | + $interlanguageLinksLookup->expects( $this->once() ) |
| 87 | + ->method( 'findPageLanguageForTarget' ) |
| 88 | + ->will( $this->returnValue( 'en' ) ); |
| 89 | + |
| 90 | + $interlanguageLinksLookup->expects( $this->once() ) |
| 91 | + ->method( 'getRedirectTargetFor' ) |
| 92 | + ->will( $this->returnValue( \Title::newFromText( 'Foo' ) ) ); |
| 93 | + |
| 94 | + $instance = new AnnotatedLanguageParserFunction( |
| 95 | + $interlanguageLinksLookup |
| 96 | + ); |
| 97 | + |
| 98 | + $expected = '{{FakeTemplate|target-link=Foo|lang-code=en|lang-name=English}}'; |
| 99 | + |
| 100 | + $this->assertEquals( |
| 101 | + array( $expected, "noparse" => false, "isHTML" => false ), |
| 102 | + $instance->parse( \Title::newFromText( 'Foo' ), 'FakeTemplate' ) |
| 103 | + ); |
| 104 | + } |
| 105 | + |
| 106 | +} |
0 commit comments