summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Utils/StatsFormatterTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Utils/StatsFormatterTest.php')
-rw-r--r--www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Utils/StatsFormatterTest.php98
1 files changed, 98 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Utils/StatsFormatterTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Utils/StatsFormatterTest.php
new file mode 100644
index 00000000..b5ead42a
--- /dev/null
+++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Utils/StatsFormatterTest.php
@@ -0,0 +1,98 @@
+<?php
+
+namespace SMW\Tests\Utils;
+
+use SMW\Utils\StatsFormatter;
+
+/**
+ * @covers \SMW\Utils\StatsFormatter
+ * @group semantic-mediawiki
+ *
+ * @license GNU GPL v2+
+ * @since 2.5
+ *
+ * @author mwjames
+ */
+class StatsFormatterTest extends \PHPUnit_Framework_TestCase {
+
+ /**
+ * @dataProvider statsProvider
+ */
+ public function testGetStatsFromFlatKey( $stats, $expected ) {
+
+ $this->assertEquals(
+ $expected,
+ StatsFormatter::getStatsFromFlatKey( $stats )
+ );
+ }
+
+ /**
+ * @dataProvider formatProvider
+ */
+ public function testFormat( $stats, $format, $expected ) {
+
+ $this->assertInternalType(
+ $expected,
+ StatsFormatter::format( $stats, $format )
+ );
+ }
+
+ public function formatProvider() {
+
+ $provider[] = [
+ [ 'Foo' => 1, 'Bar' => 1 ],
+ StatsFormatter::FORMAT_PLAIN,
+ 'string'
+ ];
+
+ $provider[] = [
+ [ 'Foo' => 1, 'Bar' => 1 ],
+ StatsFormatter::FORMAT_HTML,
+ 'string'
+ ];
+
+ $provider[] = [
+ [ 'Foo' => 1, 'Bar' => 1 ],
+ StatsFormatter::FORMAT_JSON,
+ 'string'
+ ];
+
+ $provider[] = [
+ [ 'Foo' => 1, 'Bar' => 1 ],
+ null,
+ 'array'
+ ];
+
+ return $provider;
+ }
+
+ public function statsProvider() {
+
+ $provider[] = [
+ [ 'Foo' => 1, 'Bar' => 1 ],
+ [
+ 'Foo' => 1,
+ 'Bar' => 1
+ ]
+ ];
+
+ $provider[] = [
+ [ 'Foo.foobar' => 1, 'Bar' => 1 ],
+ [
+ 'Foo' => [ 'foobar' => 1 ],
+ 'Bar' => 1
+ ]
+ ];
+
+ $provider[] = [
+ [ 'Foo.foobar' => 5, 'Bar' => 1, 'Foo.foobar.baz' => 1 ],
+ [
+ 'Foo' => [ 'foobar' => [ 5, 'baz' => 1 ] ],
+ 'Bar' => 1
+ ]
+ ];
+
+ return $provider;
+ }
+
+}