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#✓,✕=Label on (✓,✕)',
false,
'Label on (✓,✕)'
];
return $provider;
}
}