184 lines
2.9 KiB
PHP
184 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace SMW\Tests\Query;
|
|
|
|
use SMW\DataValues\PropertyValue;
|
|
use SMW\DIProperty;
|
|
use SMW\Query\PrintRequest;
|
|
|
|
/**
|
|
* @covers SMW\Query\PrintRequest
|
|
* @group semantic-mediawiki
|
|
*
|
|
* @license GPL-2.0-or-later
|
|
* @since 2.1
|
|
*
|
|
* @author mwjames
|
|
*/
|
|
class PrintRequestTest extends \PHPUnit\Framework\TestCase {
|
|
|
|
public function testCanConstructPropertyPrintRequest() {
|
|
$propertyValue = $this->getMockBuilder( '\SMW\DataValues\PropertyValue' )
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
$propertyValue->expects( $this->once() )
|
|
->method( 'isValid' )
|
|
->willReturn( true );
|
|
|
|
$this->assertInstanceOf(
|
|
'SMW\Query\PrintRequest',
|
|
new PrintRequest( PrintRequest::PRINT_PROP, null, $propertyValue )
|
|
);
|
|
}
|
|
|
|
public function testSetLabel() {
|
|
$propertyValue = new PropertyValue( '__pro' );
|
|
$propertyValue->setDataItem( new DIProperty( 'Foo' ) );
|
|
|
|
$instance = new PrintRequest( PrintRequest::PRINT_PROP, null, $propertyValue );
|
|
|
|
$this->assertEquals(
|
|
'Foo',
|
|
$instance->getCanonicalLabel()
|
|
);
|
|
|
|
$this->assertNull(
|
|
$instance->getLabel()
|
|
);
|
|
|
|
$this->assertNull(
|
|
$instance->getWikiText()
|
|
);
|
|
|
|
$instance->setLabel( 'Bar' );
|
|
|
|
$this->assertEquals(
|
|
'Bar',
|
|
$instance->getLabel()
|
|
);
|
|
|
|
$this->assertEquals(
|
|
'Bar',
|
|
$instance->getWikiText()
|
|
);
|
|
|
|
$this->assertEquals(
|
|
'Foo',
|
|
$instance->getCanonicalLabel()
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider textProvider
|
|
*/
|
|
public function testFromText( $text, $showMode, $expectedLabel ) {
|
|
$instance = PrintRequest::newFromText( $text, $showMode );
|
|
|
|
$this->assertInstanceOf(
|
|
'\SMW\Query\PrintRequest',
|
|
$instance
|
|
);
|
|
|
|
$this->assertEquals(
|
|
$expectedLabel,
|
|
$instance->getLabel()
|
|
);
|
|
}
|
|
|
|
public function testFromTextToReturnNullOnInvalidText() {
|
|
$instance = PrintRequest::newFromText( '--[[Foo' );
|
|
|
|
$this->assertNull(
|
|
$instance
|
|
);
|
|
}
|
|
|
|
public function testRemoveParameter() {
|
|
$instance = PrintRequest::newFromText( 'Foo' );
|
|
$instance->setParameter( 'foo', 123 );
|
|
|
|
$this->assertEquals(
|
|
[
|
|
'foo' => 123
|
|
],
|
|
$instance->getParameters()
|
|
);
|
|
|
|
$instance->removeParameter( 'foo' );
|
|
|
|
$this->assertEquals(
|
|
[],
|
|
$instance->getParameters()
|
|
);
|
|
}
|
|
|
|
public function textProvider() {
|
|
# 0
|
|
$provider[] = [
|
|
'Foo',
|
|
false,
|
|
'Foo'
|
|
];
|
|
|
|
# 1
|
|
$provider[] = [
|
|
'Foo',
|
|
true,
|
|
''
|
|
];
|
|
|
|
# 2
|
|
$provider[] = [
|
|
'Foo=Bar',
|
|
false,
|
|
'Bar'
|
|
];
|
|
|
|
# 3
|
|
$provider[] = [
|
|
'Foo=Bar#123',
|
|
false,
|
|
'Bar#123'
|
|
];
|
|
|
|
# 4
|
|
$provider[] = [
|
|
'Foo#123=Bar',
|
|
false,
|
|
'Bar'
|
|
];
|
|
|
|
# 5
|
|
$provider[] = [
|
|
'Category=Foo',
|
|
false,
|
|
'Foo'
|
|
];
|
|
|
|
# 6
|
|
$provider[] = [
|
|
'-Foo',
|
|
false,
|
|
'-Foo'
|
|
];
|
|
|
|
# 7
|
|
$provider[] = [
|
|
'-Foo=Bar',
|
|
false,
|
|
'Bar'
|
|
];
|
|
|
|
# 8, 1464
|
|
$provider[] = [
|
|
'Has boolean#<span style="color: green; font-size: 120%;">✓</span>,<span style="color: #AA0000; font-size: 120%;">✕</span>=Label on (✓,✕)',
|
|
false,
|
|
'Label on (✓,✕)'
|
|
];
|
|
|
|
return $provider;
|
|
}
|
|
|
|
}
|