diff options
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/DataValues/ValueFormatters/CodeStringValueFormatterTest.php')
-rw-r--r-- | www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/DataValues/ValueFormatters/CodeStringValueFormatterTest.php | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/DataValues/ValueFormatters/CodeStringValueFormatterTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/DataValues/ValueFormatters/CodeStringValueFormatterTest.php new file mode 100644 index 00000000..b3221f9c --- /dev/null +++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/DataValues/ValueFormatters/CodeStringValueFormatterTest.php @@ -0,0 +1,153 @@ +<?php + +namespace SMW\Tests\DataValues\ValueFormatters; + +use SMW\DataValueFactory; +use SMW\DataValues\ValueFormatters\CodeStringValueFormatter; + +/** + * @covers \SMW\DataValues\ValueFormatters\CodeStringValueFormatter + * @group semantic-mediawiki + * + * @license GNU GPL v2+ + * @since 2.4 + * + * @author mwjames + */ +class CodeStringValueFormatterTest extends \PHPUnit_Framework_TestCase { + + public function testCanConstruct() { + + $this->assertInstanceOf( + CodeStringValueFormatter::class, + new CodeStringValueFormatter() + ); + } + + /** + * @dataProvider stringValueProvider + */ + public function testFormat( $userValue, $type, $linker, $expected ) { + + $codeStringValue = DataValueFactory::getInstance()->newDataValueByType( '_cod' ); + $codeStringValue->setUserValue( $userValue ); + + $instance = new CodeStringValueFormatter(); + + $this->assertEquals( + $expected, + $instance->format( $codeStringValue, [ $type, $linker ] ) + ); + } + + public function stringValueProvider() { + + $provider[] = [ + 'foo', + CodeStringValueFormatter::VALUE, + null, + 'foo' + ]; + + $provider[] = [ + 'foo', + CodeStringValueFormatter::WIKI_SHORT, + null, + '<div class="smwpre">foo</div>' + ]; + + $provider[] = [ + 'foo', + CodeStringValueFormatter::HTML_SHORT, + null, + '<div class="smwpre">foo</div>' + ]; + + $provider[] = [ + 'foo', + CodeStringValueFormatter::WIKI_LONG, + null, + '<div class="smwpre"><div style="min-height:5em; overflow:auto;">foo</div></div>' + ]; + + $provider[] = [ + 'foo', + CodeStringValueFormatter::HTML_LONG, + null, + '<div class="smwpre"><div style="min-height:5em; overflow:auto;">foo</div></div>' + ]; + + $provider[] = [ + '<code><nowiki>[[Foo]]</nowiki></code>', + CodeStringValueFormatter::HTML_LONG, + null, + '<div class="smwpre"><div style="min-height:5em; overflow:auto;">[[Foo]]</div></div>' + ]; + + $provider[] = [ + '<code><nowiki>[[Foo]]</nowiki></code>', + CodeStringValueFormatter::HTML_LONG, + null, + '<div class="smwpre"><div style="min-height:5em; overflow:auto;">[[Foo]]</div></div>' + ]; + + // > 255 + $text = 'Lorem ipsum dolor sit amet consectetuer justo Nam quis lobortis vel. Sapien nulla enim Lorem enim pede ' . + 'lorem nulla justo diam wisi. Libero Nam turpis neque leo scelerisque nec habitasse a lacus mattis. Accumsan ' . + 'tincidunt Sed adipiscing nec facilisis tortor Nunc Sed ipsum tellus'; + + $expected = '<div class="smwpre"><div style="min-height:5em; overflow:auto;">Lorem ipsum dolor sit amet ' . + 'consectetuer justo Nam quis lobortis vel. Sapien nulla enim Lorem enim ' . + 'pede lorem nulla justo diam wisi. Libero Nam turpis neque leo ' . + 'scelerisque nec habitasse a lacus mattis. Accumsan tincidunt Sed adipiscing ' . + 'nec facilisis tortor Nunc Sed ipsum tellus</div></div>'; + + $provider[] = [ + $text, + CodeStringValueFormatter::HTML_LONG, + null, + $expected + ]; + + $provider[] = [ + $text, + CodeStringValueFormatter::WIKI_LONG, + null, + $expected + ]; + + // XMLContentEncode + $provider[] = [ + '<foo>', + CodeStringValueFormatter::HTML_LONG, + null, + '<div class="smwpre"><div style="min-height:5em; overflow:auto;"><foo></div></div>' + ]; + + $provider[] = [ + '<foo>', + CodeStringValueFormatter::HTML_SHORT, + null, + '<div class="smwpre"><foo></div>' + ]; + + $provider[] = [ + '*Foo', + CodeStringValueFormatter::WIKI_LONG, + null, + '<div class="smwpre"><div style="min-height:5em; overflow:auto;">*Foo</div></div>' + ]; + + // JSON + $jsonString = '{"limit": 50,"offset": 0,"sort": [],"order": [],"mode": 1}'; + $provider[] = [ + $jsonString, + CodeStringValueFormatter::WIKI_LONG, + null, + '<div class="smwpre"><div style="min-height:5em; overflow:auto;">' . CodeStringValueFormatter::asJson( $jsonString ) . '</div></div>' + ]; + + return $provider; + } + +} |