2010-12-14 16:26:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
2013-10-21 21:09:13 +00:00
|
|
|
/**
|
|
|
|
|
* @group Xml
|
|
|
|
|
*/
|
2010-12-28 18:17:16 +00:00
|
|
|
class XmlTest extends MediaWikiTestCase {
|
2011-05-01 19:32:49 +00:00
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
protected function setUp() {
|
2012-10-08 10:59:55 +00:00
|
|
|
parent::setUp();
|
2011-12-01 00:40:56 +00:00
|
|
|
|
2012-10-08 10:59:55 +00:00
|
|
|
$langObj = Language::factory( 'en' );
|
2016-02-17 09:09:32 +00:00
|
|
|
$langObj->setNamespaces( [
|
2012-01-21 22:26:14 +00:00
|
|
|
-2 => 'Media',
|
|
|
|
|
-1 => 'Special',
|
2013-02-14 11:56:23 +00:00
|
|
|
0 => '',
|
|
|
|
|
1 => 'Talk',
|
|
|
|
|
2 => 'User',
|
|
|
|
|
3 => 'User_talk',
|
|
|
|
|
4 => 'MyWiki',
|
|
|
|
|
5 => 'MyWiki_Talk',
|
|
|
|
|
6 => 'File',
|
|
|
|
|
7 => 'File_talk',
|
|
|
|
|
8 => 'MediaWiki',
|
|
|
|
|
9 => 'MediaWiki_talk',
|
|
|
|
|
10 => 'Template',
|
|
|
|
|
11 => 'Template_talk',
|
|
|
|
|
100 => 'Custom',
|
|
|
|
|
101 => 'Custom_talk',
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2011-12-01 00:40:56 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->setMwGlobals( [
|
2012-10-08 10:59:55 +00:00
|
|
|
'wgLang' => $langObj,
|
2016-03-24 14:51:13 +00:00
|
|
|
'wgUseMediaWikiUIEverywhere' => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2011-05-01 19:32:49 +00:00
|
|
|
}
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2017-09-11 20:37:18 +00:00
|
|
|
protected function tearDown() {
|
|
|
|
|
Language::factory( 'en' )->resetNamespaces();
|
|
|
|
|
parent::tearDown();
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-21 08:46:11 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Xml::expandAttributes
|
|
|
|
|
*/
|
2010-12-14 16:26:35 +00:00
|
|
|
public function testExpandAttributes() {
|
2013-02-14 11:56:23 +00:00
|
|
|
$this->assertNull( Xml::expandAttributes( null ),
|
2010-12-14 16:26:35 +00:00
|
|
|
'Converting a null list of attributes'
|
|
|
|
|
);
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertEquals( '', Xml::expandAttributes( [] ),
|
2010-12-14 16:26:35 +00:00
|
|
|
'Converting an empty list of attributes'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-21 08:46:11 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Xml::expandAttributes
|
|
|
|
|
*/
|
2010-12-14 16:26:35 +00:00
|
|
|
public function testExpandAttributesException() {
|
2013-02-14 11:56:23 +00:00
|
|
|
$this->setExpectedException( 'MWException' );
|
|
|
|
|
Xml::expandAttributes( 'string' );
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-21 08:46:11 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Xml::element
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testElementOpen() {
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
'<element>',
|
|
|
|
|
Xml::element( 'element', null, null ),
|
|
|
|
|
'Opening element with no attributes'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-21 08:46:11 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Xml::element
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testElementEmpty() {
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
'<element />',
|
|
|
|
|
Xml::element( 'element', null, '' ),
|
|
|
|
|
'Terminated empty element'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-21 08:46:11 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Xml::input
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testElementInputCanHaveAValueOfZero() {
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals(
|
2015-03-13 18:49:15 +00:00
|
|
|
'<input name="name" value="0" />',
|
2010-12-14 16:26:35 +00:00
|
|
|
Xml::input( 'name', false, 0 ),
|
2017-02-20 23:45:58 +00:00
|
|
|
'Input with a value of 0 (T25797)'
|
2010-12-14 16:26:35 +00:00
|
|
|
);
|
|
|
|
|
}
|
2013-02-14 11:56:23 +00:00
|
|
|
|
2013-10-21 08:46:11 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Xml::element
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testElementEscaping() {
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
'<element>hello <there> you & you</element>',
|
|
|
|
|
Xml::element( 'element', null, 'hello <there> you & you' ),
|
|
|
|
|
'Element with no attributes and content that needs escaping'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-21 08:46:11 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Xml::escapeTagsOnly
|
|
|
|
|
*/
|
2010-12-14 16:26:35 +00:00
|
|
|
public function testEscapeTagsOnly() {
|
|
|
|
|
$this->assertEquals( '"><', Xml::escapeTagsOnly( '"><' ),
|
|
|
|
|
'replace " > and < with their HTML entitites'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-21 08:46:11 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Xml::element
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testElementAttributes() {
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
'<element key="value" <>="<>">',
|
2016-02-17 09:09:32 +00:00
|
|
|
Xml::element( 'element', [ 'key' => 'value', '<>' => '<>' ], null ),
|
2010-12-14 16:26:35 +00:00
|
|
|
'Element attributes, keys are not escaped'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-21 08:46:11 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Xml::openElement
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testOpenElement() {
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
'<element k="v">',
|
2016-02-17 09:09:32 +00:00
|
|
|
Xml::openElement( 'element', [ 'k' => 'v' ] ),
|
2010-12-14 16:26:35 +00:00
|
|
|
'openElement() shortcut'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-21 08:46:11 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Xml::closeElement
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testCloseElement() {
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals( '</element>', Xml::closeElement( 'element' ), 'closeElement() shortcut' );
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-21 08:46:11 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Xml::dateMenu
|
|
|
|
|
*/
|
2013-02-14 11:56:23 +00:00
|
|
|
public function testDateMenu() {
|
|
|
|
|
$curYear = intval( gmdate( 'Y' ) );
|
|
|
|
|
$prevYear = $curYear - 1;
|
2011-02-06 22:10:48 +00:00
|
|
|
|
2013-02-14 11:56:23 +00:00
|
|
|
$curMonth = intval( gmdate( 'n' ) );
|
2014-01-25 13:26:03 +00:00
|
|
|
|
2011-02-06 22:10:48 +00:00
|
|
|
$nextMonth = $curMonth + 1;
|
2013-02-14 11:56:23 +00:00
|
|
|
if ( $nextMonth == 13 ) {
|
|
|
|
|
$nextMonth = 1;
|
|
|
|
|
}
|
2011-02-06 22:10:48 +00:00
|
|
|
|
2011-02-06 21:23:12 +00:00
|
|
|
$this->assertEquals(
|
2014-04-24 15:05:10 +00:00
|
|
|
'<label for="year">From year (and earlier):</label> ' .
|
2016-02-18 16:33:15 +00:00
|
|
|
'<input id="year" maxlength="4" size="7" type="number" value="2011" name="year"/> ' .
|
2014-04-24 15:05:10 +00:00
|
|
|
'<label for="month">From month (and earlier):</label> ' .
|
2015-06-07 00:26:57 +00:00
|
|
|
'<select name="month" id="month" class="mw-month-selector">' .
|
2014-04-24 15:05:10 +00:00
|
|
|
'<option value="-1">all</option>' . "\n" .
|
2013-02-14 11:56:23 +00:00
|
|
|
'<option value="1">January</option>' . "\n" .
|
|
|
|
|
'<option value="2" selected="">February</option>' . "\n" .
|
|
|
|
|
'<option value="3">March</option>' . "\n" .
|
|
|
|
|
'<option value="4">April</option>' . "\n" .
|
|
|
|
|
'<option value="5">May</option>' . "\n" .
|
|
|
|
|
'<option value="6">June</option>' . "\n" .
|
|
|
|
|
'<option value="7">July</option>' . "\n" .
|
|
|
|
|
'<option value="8">August</option>' . "\n" .
|
|
|
|
|
'<option value="9">September</option>' . "\n" .
|
|
|
|
|
'<option value="10">October</option>' . "\n" .
|
|
|
|
|
'<option value="11">November</option>' . "\n" .
|
|
|
|
|
'<option value="12">December</option></select>',
|
2011-02-06 21:23:12 +00:00
|
|
|
Xml::dateMenu( 2011, 02 ),
|
|
|
|
|
"Date menu for february 2011"
|
|
|
|
|
);
|
|
|
|
|
$this->assertEquals(
|
2014-04-24 15:05:10 +00:00
|
|
|
'<label for="year">From year (and earlier):</label> ' .
|
2016-02-18 16:33:15 +00:00
|
|
|
'<input id="year" maxlength="4" size="7" type="number" value="2011" name="year"/> ' .
|
2014-04-24 15:05:10 +00:00
|
|
|
'<label for="month">From month (and earlier):</label> ' .
|
2015-06-07 00:26:57 +00:00
|
|
|
'<select name="month" id="month" class="mw-month-selector">' .
|
2014-04-24 15:05:10 +00:00
|
|
|
'<option value="-1">all</option>' . "\n" .
|
2013-02-14 11:56:23 +00:00
|
|
|
'<option value="1">January</option>' . "\n" .
|
|
|
|
|
'<option value="2">February</option>' . "\n" .
|
|
|
|
|
'<option value="3">March</option>' . "\n" .
|
|
|
|
|
'<option value="4">April</option>' . "\n" .
|
|
|
|
|
'<option value="5">May</option>' . "\n" .
|
|
|
|
|
'<option value="6">June</option>' . "\n" .
|
|
|
|
|
'<option value="7">July</option>' . "\n" .
|
|
|
|
|
'<option value="8">August</option>' . "\n" .
|
|
|
|
|
'<option value="9">September</option>' . "\n" .
|
|
|
|
|
'<option value="10">October</option>' . "\n" .
|
|
|
|
|
'<option value="11">November</option>' . "\n" .
|
|
|
|
|
'<option value="12">December</option></select>',
|
|
|
|
|
Xml::dateMenu( 2011, -1 ),
|
2011-02-06 21:23:12 +00:00
|
|
|
"Date menu with negative month for 'All'"
|
|
|
|
|
);
|
2011-02-06 22:10:48 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
Xml::dateMenu( $curYear, $curMonth ),
|
2013-02-14 11:56:23 +00:00
|
|
|
Xml::dateMenu( '', $curMonth ),
|
2011-02-06 22:10:48 +00:00
|
|
|
"Date menu year is the current one when not specified"
|
|
|
|
|
);
|
2011-12-01 00:40:56 +00:00
|
|
|
|
2012-09-23 08:15:20 +00:00
|
|
|
$wantedYear = $nextMonth == 1 ? $curYear : $prevYear;
|
2011-12-01 14:40:11 +00:00
|
|
|
$this->assertEquals(
|
2012-09-23 08:15:20 +00:00
|
|
|
Xml::dateMenu( $wantedYear, $nextMonth ),
|
2011-02-06 22:10:48 +00:00
|
|
|
Xml::dateMenu( '', $nextMonth ),
|
|
|
|
|
"Date menu next month is 11 months ago"
|
2011-12-01 14:40:11 +00:00
|
|
|
);
|
2011-02-06 22:10:48 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals(
|
2014-04-24 15:05:10 +00:00
|
|
|
'<label for="year">From year (and earlier):</label> ' .
|
2016-02-18 16:33:15 +00:00
|
|
|
'<input id="year" maxlength="4" size="7" type="number" name="year"/> ' .
|
2014-04-24 15:05:10 +00:00
|
|
|
'<label for="month">From month (and earlier):</label> ' .
|
2015-06-07 00:26:57 +00:00
|
|
|
'<select name="month" id="month" class="mw-month-selector">' .
|
2014-04-24 17:51:33 +00:00
|
|
|
'<option value="-1">all</option>' . "\n" .
|
2013-02-14 11:56:23 +00:00
|
|
|
'<option value="1">January</option>' . "\n" .
|
|
|
|
|
'<option value="2">February</option>' . "\n" .
|
|
|
|
|
'<option value="3">March</option>' . "\n" .
|
|
|
|
|
'<option value="4">April</option>' . "\n" .
|
|
|
|
|
'<option value="5">May</option>' . "\n" .
|
|
|
|
|
'<option value="6">June</option>' . "\n" .
|
|
|
|
|
'<option value="7">July</option>' . "\n" .
|
|
|
|
|
'<option value="8">August</option>' . "\n" .
|
|
|
|
|
'<option value="9">September</option>' . "\n" .
|
|
|
|
|
'<option value="10">October</option>' . "\n" .
|
|
|
|
|
'<option value="11">November</option>' . "\n" .
|
|
|
|
|
'<option value="12">December</option></select>',
|
2011-12-01 00:40:56 +00:00
|
|
|
Xml::dateMenu( '', '' ),
|
2011-02-06 22:10:48 +00:00
|
|
|
"Date menu with neither year or month"
|
|
|
|
|
);
|
2011-02-06 21:23:12 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-21 08:46:11 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Xml::textarea
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testTextareaNoContent() {
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals(
|
2015-03-13 18:49:15 +00:00
|
|
|
'<textarea name="name" id="name" cols="40" rows="5"></textarea>',
|
2010-12-14 16:26:35 +00:00
|
|
|
Xml::textarea( 'name', '' ),
|
|
|
|
|
'textarea() with not content'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-21 08:46:11 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Xml::textarea
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testTextareaAttribs() {
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals(
|
2015-03-13 18:49:15 +00:00
|
|
|
'<textarea name="name" id="name" cols="20" rows="10"><txt></textarea>',
|
2010-12-14 16:26:35 +00:00
|
|
|
Xml::textarea( 'name', '<txt>', 20, 10 ),
|
|
|
|
|
'textarea() with custom attribs'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-21 08:46:11 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Xml::label
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testLabelCreation() {
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
'<label for="id">name</label>',
|
|
|
|
|
Xml::label( 'name', 'id' ),
|
|
|
|
|
'label() with no attribs'
|
|
|
|
|
);
|
|
|
|
|
}
|
2013-02-14 11:56:23 +00:00
|
|
|
|
2013-10-21 08:46:11 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Xml::label
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testLabelAttributeCanOnlyBeClassOrTitle() {
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
'<label for="id">name</label>',
|
2016-02-17 09:09:32 +00:00
|
|
|
Xml::label( 'name', 'id', [ 'generated' => true ] ),
|
2010-12-14 16:26:35 +00:00
|
|
|
'label() can not be given a generated attribute'
|
|
|
|
|
);
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
'<label for="id" class="nice">name</label>',
|
2016-02-17 09:09:32 +00:00
|
|
|
Xml::label( 'name', 'id', [ 'class' => 'nice' ] ),
|
2010-12-14 16:26:35 +00:00
|
|
|
'label() can get a class attribute'
|
|
|
|
|
);
|
|
|
|
|
$this->assertEquals(
|
2011-06-23 20:05:32 +00:00
|
|
|
'<label for="id" title="nice tooltip">name</label>',
|
2016-02-17 09:09:32 +00:00
|
|
|
Xml::label( 'name', 'id', [ 'title' => 'nice tooltip' ] ),
|
2011-06-23 20:05:32 +00:00
|
|
|
'label() can get a title attribute'
|
|
|
|
|
);
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
'<label for="id" class="nice" title="nice tooltip">name</label>',
|
2016-02-17 09:09:32 +00:00
|
|
|
Xml::label( 'name', 'id', [
|
2013-02-14 11:56:23 +00:00
|
|
|
'generated' => true,
|
|
|
|
|
'class' => 'nice',
|
|
|
|
|
'title' => 'nice tooltip',
|
|
|
|
|
'anotherattr' => 'value',
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
2010-12-14 16:26:35 +00:00
|
|
|
),
|
2011-06-23 20:05:32 +00:00
|
|
|
'label() skip all attributes but "class" and "title"'
|
2010-12-14 16:26:35 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-21 08:46:11 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Xml::languageSelector
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testLanguageSelector() {
|
2012-05-10 19:46:14 +00:00
|
|
|
$select = Xml::languageSelector( 'en', true, null,
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'id' => 'testlang' ], wfMessage( 'yourlanguage' ) );
|
2012-05-10 19:46:14 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
'<label for="testlang">Language:</label>',
|
|
|
|
|
$select[0]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-21 08:46:11 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Xml::encodeJsVar
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testEncodeJsVarBoolean() {
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
'true',
|
|
|
|
|
Xml::encodeJsVar( true ),
|
|
|
|
|
'encodeJsVar() with boolean'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-21 08:46:11 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Xml::encodeJsVar
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testEncodeJsVarNull() {
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
'null',
|
|
|
|
|
Xml::encodeJsVar( null ),
|
|
|
|
|
'encodeJsVar() with null'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-21 08:46:11 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Xml::encodeJsVar
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testEncodeJsVarArray() {
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals(
|
2012-01-30 19:40:20 +00:00
|
|
|
'["a",1]',
|
2016-02-17 09:09:32 +00:00
|
|
|
Xml::encodeJsVar( [ 'a', 1 ] ),
|
2010-12-14 16:26:35 +00:00
|
|
|
'encodeJsVar() with array'
|
|
|
|
|
);
|
|
|
|
|
$this->assertEquals(
|
2012-01-30 19:40:20 +00:00
|
|
|
'{"a":"a","b":1}',
|
2016-02-17 09:09:32 +00:00
|
|
|
Xml::encodeJsVar( [ 'a' => 'a', 'b' => 1 ] ),
|
2010-12-14 16:26:35 +00:00
|
|
|
'encodeJsVar() with associative array'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-21 08:46:11 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Xml::encodeJsVar
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testEncodeJsVarObject() {
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertEquals(
|
2012-01-30 19:40:20 +00:00
|
|
|
'{"a":"a","b":1}',
|
2016-02-17 09:09:32 +00:00
|
|
|
Xml::encodeJsVar( (object)[ 'a' => 'a', 'b' => 1 ] ),
|
2010-12-14 16:26:35 +00:00
|
|
|
'encodeJsVar() with object'
|
|
|
|
|
);
|
|
|
|
|
}
|
2011-02-14 00:54:40 +00:00
|
|
|
|
2013-10-21 08:46:11 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Xml::encodeJsVar
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testEncodeJsVarInt() {
|
2011-02-14 00:54:40 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
'123456',
|
|
|
|
|
Xml::encodeJsVar( 123456 ),
|
|
|
|
|
'encodeJsVar() with int'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-21 08:46:11 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Xml::encodeJsVar
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testEncodeJsVarFloat() {
|
2011-02-14 00:54:40 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
'1.23456',
|
|
|
|
|
Xml::encodeJsVar( 1.23456 ),
|
|
|
|
|
'encodeJsVar() with float'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-21 08:46:11 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Xml::encodeJsVar
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testEncodeJsVarIntString() {
|
2011-02-14 00:54:40 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
'"123456"',
|
|
|
|
|
Xml::encodeJsVar( '123456' ),
|
|
|
|
|
'encodeJsVar() with int-like string'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-21 08:46:11 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Xml::encodeJsVar
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testEncodeJsVarFloatString() {
|
2011-02-14 00:54:40 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
'"1.23456"',
|
|
|
|
|
Xml::encodeJsVar( '1.23456' ),
|
|
|
|
|
'encodeJsVar() with float-like string'
|
|
|
|
|
);
|
|
|
|
|
}
|
2017-03-18 01:25:12 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers Xml::listDropDown
|
|
|
|
|
*/
|
|
|
|
|
public function testListDropDown() {
|
|
|
|
|
$this->assertEquals(
|
2017-07-12 19:31:33 +00:00
|
|
|
'<select name="test-name" id="test-name" class="test-css" tabindex="2">' .
|
|
|
|
|
'<option value="other">other reasons</option>' . "\n" .
|
|
|
|
|
'<optgroup label="Foo">' .
|
|
|
|
|
'<option value="Foo 1">Foo 1</option>' . "\n" .
|
|
|
|
|
'<option value="Example" selected="">Example</option>' . "\n" .
|
|
|
|
|
'</optgroup>' . "\n" .
|
|
|
|
|
'<optgroup label="Bar">' .
|
|
|
|
|
'<option value="Bar 1">Bar 1</option>' . "\n" .
|
|
|
|
|
'</optgroup>' .
|
2017-03-18 01:25:12 +00:00
|
|
|
'</select>',
|
|
|
|
|
Xml::listDropDown(
|
|
|
|
|
// name
|
|
|
|
|
'test-name',
|
|
|
|
|
// source list
|
|
|
|
|
"* Foo\n** Foo 1\n** Example\n* Bar\n** Bar 1",
|
|
|
|
|
// other
|
|
|
|
|
'other reasons',
|
|
|
|
|
// selected
|
|
|
|
|
'Example',
|
|
|
|
|
// class
|
|
|
|
|
'test-css',
|
|
|
|
|
// tabindex
|
|
|
|
|
2
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
2017-07-12 19:31:33 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers Xml::listDropDownOptions
|
|
|
|
|
*/
|
|
|
|
|
public function testListDropDownOptions() {
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
[
|
|
|
|
|
'other reasons' => 'other',
|
|
|
|
|
'Foo' => [
|
|
|
|
|
'Foo 1' => 'Foo 1',
|
|
|
|
|
'Example' => 'Example',
|
|
|
|
|
],
|
|
|
|
|
'Bar' => [
|
|
|
|
|
'Bar 1' => 'Bar 1',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
Xml::listDropDownOptions(
|
|
|
|
|
"* Foo\n** Foo 1\n** Example\n* Bar\n** Bar 1",
|
|
|
|
|
[ 'other' => 'other reasons' ]
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers Xml::listDropDownOptionsOoui
|
|
|
|
|
*/
|
|
|
|
|
public function testListDropDownOptionsOoui() {
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
[
|
|
|
|
|
[ 'data' => 'other', 'label' => 'other reasons' ],
|
|
|
|
|
[ 'optgroup' => 'Foo' ],
|
|
|
|
|
[ 'data' => 'Foo 1', 'label' => 'Foo 1' ],
|
|
|
|
|
[ 'data' => 'Example', 'label' => 'Example' ],
|
|
|
|
|
[ 'optgroup' => 'Bar' ],
|
|
|
|
|
[ 'data' => 'Bar 1', 'label' => 'Bar 1' ],
|
|
|
|
|
],
|
|
|
|
|
Xml::listDropDownOptionsOoui( [
|
|
|
|
|
'other reasons' => 'other',
|
|
|
|
|
'Foo' => [
|
|
|
|
|
'Foo 1' => 'Foo 1',
|
|
|
|
|
'Example' => 'Example',
|
|
|
|
|
],
|
|
|
|
|
'Bar' => [
|
|
|
|
|
'Bar 1' => 'Bar 1',
|
|
|
|
|
],
|
|
|
|
|
] )
|
|
|
|
|
);
|
|
|
|
|
}
|
2017-09-17 17:05:40 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers Xml::fieldset
|
|
|
|
|
*/
|
|
|
|
|
public function testFieldset() {
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
"<fieldset>\n",
|
|
|
|
|
Xml::fieldset(),
|
|
|
|
|
'Opening tag'
|
|
|
|
|
);
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
"<fieldset>\n",
|
|
|
|
|
Xml::fieldset( false ),
|
|
|
|
|
'Opening tag (false means no legend)'
|
|
|
|
|
);
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
"<fieldset>\n",
|
|
|
|
|
Xml::fieldset( '' ),
|
|
|
|
|
'Opening tag (empty string also means no legend)'
|
|
|
|
|
);
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
"<fieldset>\n<legend>Foo</legend>\n",
|
|
|
|
|
Xml::fieldset( 'Foo' ),
|
|
|
|
|
'Opening tag with legend'
|
|
|
|
|
);
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
"<fieldset>\n<legend>Foo</legend>\nBar\n</fieldset>\n",
|
|
|
|
|
Xml::fieldset( 'Foo', 'Bar' ),
|
|
|
|
|
'Entire element with legend'
|
|
|
|
|
);
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
"<fieldset>\n<legend>Foo</legend>\n",
|
|
|
|
|
Xml::fieldset( 'Foo', false ),
|
|
|
|
|
'Opening tag with legend (false means no content and no closing tag)'
|
|
|
|
|
);
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
"<fieldset>\n<legend>Foo</legend>\n\n</fieldset>\n",
|
|
|
|
|
Xml::fieldset( 'Foo', '' ),
|
|
|
|
|
'Entire element with legend but no content (empty string generates a closing tag)'
|
|
|
|
|
);
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
"<fieldset class=\"bar\">\n<legend>Foo</legend>\nBar\n</fieldset>\n",
|
|
|
|
|
Xml::fieldset( 'Foo', 'Bar', [ 'class' => 'bar' ] ),
|
|
|
|
|
'Opening tag with legend and attributes'
|
|
|
|
|
);
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
"<fieldset class=\"bar\">\n<legend>Foo</legend>\n",
|
|
|
|
|
Xml::fieldset( 'Foo', false, [ 'class' => 'bar' ] ),
|
|
|
|
|
'Entire element with legend and attributes'
|
|
|
|
|
);
|
|
|
|
|
}
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|