diff options
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Query/DebugFormatterTest.php')
-rw-r--r-- | www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Query/DebugFormatterTest.php | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Query/DebugFormatterTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Query/DebugFormatterTest.php new file mode 100644 index 00000000..4e0fc750 --- /dev/null +++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Query/DebugFormatterTest.php @@ -0,0 +1,149 @@ +<?php + +namespace SMW\Tests\Query; + +use SMW\Query\DebugFormatter; + +/** + * @covers \SMW\Query\DebugFormatter + * @group semantic-mediawiki + * + * @license GNU GPL v2+ + * @since 2.0 + * + * @author mwjames + */ +class DebugFormatterTest extends \PHPUnit_Framework_TestCase { + + public function testFormatDebugOutputWithoutQuery() { + + $instance = new DebugFormatter(); + + $this->assertInternalType( + 'string', + $instance->getStringFrom( 'foo', [], null ) + ); + } + + public function testExplainFormat() { + + DebugFormatter::setExplainFormat( DebugFormatter::JSON_FORMAT ); + + $this->assertEquals( + 'FORMAT=json', + DebugFormatter::getFormat( 'mysql' ) + ); + } + + public function testFormatDebugOutputWithQuery() { + + $description = $this->getMockBuilder( '\SMW\Query\Language\Description' ) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + + $query = $this->getMockBuilder( '\SMWQuery' ) + ->disableOriginalConstructor() + ->getMock(); + + $query->expects( $this->any() ) + ->method( 'getDescription' ) + ->will( $this->returnValue( $description ) ); + + $query->expects( $this->any() ) + ->method( 'getErrors' ) + ->will( $this->returnValue( [] ) ); + + $instance = new DebugFormatter(); + + $this->assertInternalType( + 'string', + $instance->getStringFrom( 'foo', [], $query ) + ); + } + + /** + * @dataProvider sqlExplainFormatProvider + */ + public function testFormatSQLExplainOutput( $type, $res ) { + + $instance = new DebugFormatter(); + + $this->assertInternalType( + 'string', + $instance->prettifyExplain( $type, $res ) + ); + } + + public function testFormatSPARQLStatement() { + + $instance = new DebugFormatter(); + + $sparql = ''; + + $this->assertInternalType( + 'string', + $instance->prettifySparql( $sparql ) + ); + + $this->assertEquals( + '<div class="smwpre">[: <Foo> ]</div>', + $instance->prettifySparql( '[: <Foo> ]' ) + ); + } + + public function testFormatSQLStatement() { + + $instance = new DebugFormatter(); + + $sql = ''; + $alias = ''; + + $this->assertInternalType( + 'string', + $instance->prettifySql( $sql, $alias ) + ); + } + + public function sqlExplainFormatProvider() { + + $row = [ + 'id' => '', + 'select_type' => '', + 'table' => '', + 'type' => '', + 'possible_keys' => '', + 'key' => '', + 'key_len' => '', + 'ref' => '', + 'rows' => '', + 'Extra' => '' + ]; + + $provider[] = [ + 'mysql', + [ (object)$row ] + ]; + + $provider[] = [ + 'postgres', + [ [ 'QUERY PLAN' => '' ] ] + ]; + + $provider[] = [ + 'sqlite', + '' + ]; + + $row = [ + 'EXPLAIN' => 'Foooooooo' + ]; + + $provider[] = [ + 'mysql', + [ (object)$row ] + ]; + + return $provider; + } + +} |