Skip to content

Commit

Permalink
Update composer.json to use DataTypes 1.0.0
Browse files Browse the repository at this point in the history
This requires a 1.0.0 release of the DataTypes component, including
these two patches:
wmde/DataTypes#63
wmde/DataTypes#62

Change-Id: Id95bdc6f12014f6b50c103debb3257b6907008e6
  • Loading branch information
thiemowmde authored and bekh6ex committed Jan 2, 2017
1 parent 316b20d commit 86b3943
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"data-values/number": "~0.8.2",
"data-values/time": "~0.8.4",
"data-values/validators": "~0.1.0",
"data-values/data-types": "~0.5.0",
"data-values/data-types": "~1.0.0",
"data-values/serialization": "~1.1",
"data-values/javascript": "~0.8.3",
"data-values/value-view": "~0.18.0",
Expand Down
3 changes: 2 additions & 1 deletion repo/includes/DataTypeSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public function getOptionsArray() {
$byId = [];

foreach ( $this->dataTypes as $dataType ) {
$label = $dataType->getLabel( $this->languageCode );
$label = wfMessage( $dataType->getMessageKey() )->inLanguage( $this->languageCode )
->text();
$id = $dataType->getId();

$byLabel[$label] = $id;
Expand Down
24 changes: 13 additions & 11 deletions repo/tests/phpunit/includes/DataTypeSelectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@
*/
class DataTypeSelectorTest extends PHPUnit_Framework_TestCase {

/** @see \LanguageQqx */
const DUMMY_LANGUAGE = 'qqx';

/**
* @param string $propertyType
* @param string $label
* @param string $messageKey
*
* @return DataType
*/
private function newDataType( $propertyType, $label ) {
private function newDataType( $propertyType, $messageKey ) {
$dataType = $this->getMockBuilder( DataType::class )
->disableOriginalConstructor()
->getMock();
Expand All @@ -34,9 +37,8 @@ private function newDataType( $propertyType, $label ) {
->will( $this->returnValue( $propertyType ) );

$dataType->expects( $this->any() )
->method( 'getLabel' )
->with( 'en' )
->will( $this->returnValue( $label ) );
->method( 'getMessageKey' )
->will( $this->returnValue( $messageKey ) );

return $dataType;
}
Expand All @@ -62,10 +64,10 @@ public function invalidConstructorArgumentsProvider() {
public function testGetOptionsArrayWithOneElement() {
$selector = new DataTypeSelector( [
$this->newDataType( '<PROPERTY-TYPE>', '<LABEL>' ),
], 'en' );
], self::DUMMY_LANGUAGE );

$expected = [
'<LABEL>' => '<PROPERTY-TYPE>',
'(<LABEL>)' => '<PROPERTY-TYPE>',
];
$this->assertSame( $expected, $selector->getOptionsArray() );
}
Expand All @@ -74,7 +76,7 @@ public function testGetOptionsArrayWithDuplicateLabels() {
$selector = new DataTypeSelector( [
$this->newDataType( '<PROPERTY-TYPE-B>', '<LABEL>' ),
$this->newDataType( '<PROPERTY-TYPE-A>', '<LABEL>' ),
], 'en' );
], self::DUMMY_LANGUAGE );

$expected = [
'<PROPERTY-TYPE-A>' => '<PROPERTY-TYPE-A>',
Expand All @@ -87,11 +89,11 @@ public function testGetOptionsArraySortsLabelsInNaturalOrder() {
$selector = new DataTypeSelector( [
$this->newDataType( '<PROPERTY-TYPE-A>', '<LABEL-10>' ),
$this->newDataType( '<PROPERTY-TYPE-B>', '<label-2>' ),
], 'en' );
], self::DUMMY_LANGUAGE );

$expected = [
'<label-2>' => '<PROPERTY-TYPE-B>',
'<LABEL-10>' => '<PROPERTY-TYPE-A>',
'(<label-2>)' => '<PROPERTY-TYPE-B>',
'(<LABEL-10>)' => '<PROPERTY-TYPE-A>',
];
$this->assertSame( $expected, $selector->getOptionsArray() );
}
Expand Down
6 changes: 2 additions & 4 deletions view/src/PropertyView.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,17 @@ protected function getMainHtml( EntityDocument $property ) {
* @return string HTML
*/
private function getHtmlForDataType( $propertyType ) {

$html = $this->templateFactory->render( 'wb-section-heading',
htmlspecialchars( $this->textProvider->get( 'wikibase-propertypage-datatype' ) ),
'datatype',
'wikibase-propertypage-datatype'
);

$dataTypeLabelHtml = '';
try {
$dataType = $this->dataTypeFactory->getType( $propertyType );
$dataTypeLabelHtml = htmlspecialchars( $dataType->getLabel( $this->languageCode ) );
$dataTypeLabelHtml = htmlspecialchars( $this->textProvider->get( $dataType->getMessageKey() ) );
} catch ( OutOfBoundsException $ex ) {
$dataTypeLabelHtml .= '<span class="error">' .
$dataTypeLabelHtml = '<span class="error">' .
htmlspecialchars( $this->textProvider->get( 'wikibase-propertypage-bad-datatype', [ $propertyType ] ) ) .
'</span>';
}
Expand Down

0 comments on commit 86b3943

Please sign in to comment.