PortableInfobox/tests/PortableInfoboxBuilderServiceTest.php

37 lines
1.5 KiB
PHP
Raw Normal View History

2015-08-31 15:42:38 +00:00
<?php
class PortableInfoboxBuilderServiceTest extends WikiaBaseTest {
protected function setUp() {
$this->setupFile = dirname( __FILE__ ) . '/../PortableInfobox.setup.php';
parent::setUp();
}
/**
* @dataProvider translationsDataProvider
*/
2015-09-01 07:42:51 +00:00
public function testTranslation( $data, $expected ) {
2015-08-31 15:42:38 +00:00
$service = new PortableInfoboxBuilderService();
$this->assertEquals( $expected, $service->translate( $data ) );
}
public function translationsDataProvider() {
return [
[ "", "" ],
[ "[]", "" ],
[ '{"data":[{"type":"data", "source":"asdf"}]}', '<infobox><data source="asdf"/></infobox>' ],
[ '{"data":[{"type":"data", "source":"asdf", "data": {"label": "asdfsda"}}]}',
'<infobox><data source="asdf"><label>asdfsda</label></data></infobox>' ],
[ '{"data":[{"type":"title", "source":"title", "data": {"defaultValue": "{{PAGENAME}}"}}]}',
2015-08-31 15:42:38 +00:00
'<infobox><title source="title"><default>{{PAGENAME}}</default></title></infobox>' ],
[ '{"data":[{"type":"group", "data": [{"type": "data", "source": "asdf"}]}]}',
'<infobox><group><data source="asdf"/></group></infobox>' ],
[ '{"theme": "asdf", "data": [{"type": "image", "source": "image", "data": { "alt": {"source": "title", "data": {"default": "asdf"}}}}]}',
'<infobox theme="asdf"><image source="image"><alt source="title"><default>asdf</default></alt></image></infobox>' ],
[ '{"theme": "adsf", "data": [{"type": "group", "data": [{"type":"header", "data":"asdf"}]}]}',
'<infobox theme="adsf"><group><header>asdf</header></group></infobox>' ]
];
}
}