summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/DataValues/ValueFormatters/NoValueFormatterTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/DataValues/ValueFormatters/NoValueFormatterTest.php')
-rw-r--r--www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/DataValues/ValueFormatters/NoValueFormatterTest.php82
1 files changed, 82 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/DataValues/ValueFormatters/NoValueFormatterTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/DataValues/ValueFormatters/NoValueFormatterTest.php
new file mode 100644
index 00000000..51ff75f5
--- /dev/null
+++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/DataValues/ValueFormatters/NoValueFormatterTest.php
@@ -0,0 +1,82 @@
+<?php
+
+namespace SMW\Tests\DataValues\ValueFormatters;
+
+use SMW\DataValues\ValueFormatters\NoValueFormatter;
+use SMW\Tests\PHPUnitCompat;
+
+/**
+ * @covers \SMW\DataValues\ValueFormatters\NoValueFormatter
+ * @group semantic-mediawiki
+ *
+ * @license GNU GPL v2+
+ * @since 2.4
+ *
+ * @author mwjames
+ */
+class NoValueFormatterTest extends \PHPUnit_Framework_TestCase {
+
+ use PHPUnitCompat;
+
+ public function testCanConstruct() {
+
+ $this->assertInstanceOf(
+ '\SMW\DataValues\ValueFormatters\NoValueFormatter',
+ new NoValueFormatter()
+ );
+ }
+
+ public function testIsFormatterForValidation() {
+
+ $dataValue = $this->getMockBuilder( '\SMWDataValue' )
+ ->disableOriginalConstructor()
+ ->getMockForAbstractClass();
+
+ $instance = new NoValueFormatter();
+
+ $this->assertTrue(
+ $instance->isFormatterFor( $dataValue )
+ );
+ }
+
+ public function testFormat() {
+
+ $dataItem = $this->getMockBuilder( '\SMWDataItem' )
+ ->disableOriginalConstructor()
+ ->setMethods( [ 'getSerialization' ] )
+ ->getMockForAbstractClass();
+
+ $dataItem->expects( $this->once() )
+ ->method( 'getSerialization' )
+ ->will( $this->returnValue( 'isFromSerializationMethod' ) );
+
+ $dataValue = $this->getMockBuilder( '\SMWDataValue' )
+ ->disableOriginalConstructor()
+ ->setMethods( [ 'isValid', 'getDataItem' ] )
+ ->getMockForAbstractClass();
+
+ $dataValue->expects( $this->any() )
+ ->method( 'isValid' )
+ ->will( $this->returnValue( true ) );
+
+ $dataValue->expects( $this->once() )
+ ->method( 'getDataItem' )
+ ->will( $this->returnValue( $dataItem ) );
+
+ $instance = new NoValueFormatter( $dataValue );
+
+ $this->assertEquals(
+ 'isFromSerializationMethod',
+ $instance->format( NoValueFormatter::VALUE )
+ );
+ }
+
+ public function testTryToFormatOnMissingDataValueThrowsException() {
+
+ $instance = new NoValueFormatter();
+
+ $this->setExpectedException( 'RuntimeException' );
+ $instance->format( NoValueFormatter::VALUE );
+ }
+
+}