diff options
author | Máté Szabó <mszabo@wikia-inc.com> | 2019-06-01 16:10:15 +0200 |
---|---|---|
committer | Máté Szabó <mszabo@wikia-inc.com> | 2019-06-13 22:56:31 +0200 |
commit | 0a2b996278e57a8b8c5377cd3a3eaa54f993d4a9 (patch) | |
tree | cde53a6eeb2d94ceece63322ffcd107cedbd553d /tests/phpunit/includes/XmlSelectTest.php | |
parent | 15c27d356b5e6760024ac0653279a76d94d78b1f (diff) | |
download | mediawikicore-0a2b996278e57a8b8c5377cd3a3eaa54f993d4a9.tar.gz mediawikicore-0a2b996278e57a8b8c5377cd3a3eaa54f993d4a9.zip |
Separate MediaWiki unit and integration tests
This changeset implements T89432 and related tickets and is based on exploration
done at the Prague Hackathon. The goal is to identify tests in MediaWiki core
that can be run without having to install & configure MediaWiki and its dependencies,
and provide a way to execute these tests via the standard phpunit entry point,
allowing for faster development and integration with existing tooling like IDEs.
The initial set of tests that met these criteria were identified using the work Amir did in
I88822667693d9e00ac3d4639c87bc24e5083e5e8. These tests were then moved into a new subdirectory
under phpunit/ and organized into a separate test suite. The environment for this suite
is set up via a PHPUnit bootstrap file without a custom entry point.
You can execute these tests by running:
$ vendor/bin/phpunit -d memory_limit=512M -c tests/phpunit/unit-tests.xml
Bug: T89432
Bug: T87781
Bug: T84948
Change-Id: Iad01033a0548afd4d2a6f2c1ef6fcc9debf72c0d
Diffstat (limited to 'tests/phpunit/includes/XmlSelectTest.php')
-rw-r--r-- | tests/phpunit/includes/XmlSelectTest.php | 182 |
1 files changed, 0 insertions, 182 deletions
diff --git a/tests/phpunit/includes/XmlSelectTest.php b/tests/phpunit/includes/XmlSelectTest.php deleted file mode 100644 index 52e20bdb99d1..000000000000 --- a/tests/phpunit/includes/XmlSelectTest.php +++ /dev/null @@ -1,182 +0,0 @@ -<?php - -/** - * @group Xml - */ -class XmlSelectTest extends MediaWikiTestCase { - - /** - * @var XmlSelect - */ - protected $select; - - protected function setUp() { - parent::setUp(); - $this->select = new XmlSelect(); - } - - protected function tearDown() { - parent::tearDown(); - $this->select = null; - } - - /** - * @covers XmlSelect::__construct - */ - public function testConstructWithoutParameters() { - $this->assertEquals( '<select></select>', $this->select->getHTML() ); - } - - /** - * Parameters are $name (false), $id (false), $default (false) - * @dataProvider provideConstructionParameters - * @covers XmlSelect::__construct - */ - public function testConstructParameters( $name, $id, $default, $expected ) { - $this->select = new XmlSelect( $name, $id, $default ); - $this->assertEquals( $expected, $this->select->getHTML() ); - } - - /** - * Provide parameters for testConstructParameters() which use three - * parameters: - * - $name (default: false) - * - $id (default: false) - * - $default (default: false) - * Provides a fourth parameters representing the expected HTML output - */ - public static function provideConstructionParameters() { - return [ - /** - * Values are set following a 3-bit Gray code where two successive - * values differ by only one value. - * See https://en.wikipedia.org/wiki/Gray_code - */ - # $name $id $default - [ false, false, false, '<select></select>' ], - [ false, false, 'foo', '<select></select>' ], - [ false, 'id', 'foo', '<select id="id"></select>' ], - [ false, 'id', false, '<select id="id"></select>' ], - [ 'name', 'id', false, '<select name="name" id="id"></select>' ], - [ 'name', 'id', 'foo', '<select name="name" id="id"></select>' ], - [ 'name', false, 'foo', '<select name="name"></select>' ], - [ 'name', false, false, '<select name="name"></select>' ], - ]; - } - - /** - * @covers XmlSelect::addOption - */ - public function testAddOption() { - $this->select->addOption( 'foo' ); - $this->assertEquals( - '<select><option value="foo">foo</option></select>', - $this->select->getHTML() - ); - } - - /** - * @covers XmlSelect::addOption - */ - public function testAddOptionWithDefault() { - $this->select->addOption( 'foo', true ); - $this->assertEquals( - '<select><option value="1">foo</option></select>', - $this->select->getHTML() - ); - } - - /** - * @covers XmlSelect::addOption - */ - public function testAddOptionWithFalse() { - $this->select->addOption( 'foo', false ); - $this->assertEquals( - '<select><option value="foo">foo</option></select>', - $this->select->getHTML() - ); - } - - /** - * @covers XmlSelect::addOption - */ - public function testAddOptionWithValueZero() { - $this->select->addOption( 'foo', 0 ); - $this->assertEquals( - '<select><option value="0">foo</option></select>', - $this->select->getHTML() - ); - } - - /** - * @covers XmlSelect::setDefault - */ - public function testSetDefault() { - $this->select->setDefault( 'bar1' ); - $this->select->addOption( 'foo1' ); - $this->select->addOption( 'bar1' ); - $this->select->addOption( 'foo2' ); - $this->assertEquals( - '<select><option value="foo1">foo1</option>' . "\n" . - '<option value="bar1" selected="">bar1</option>' . "\n" . - '<option value="foo2">foo2</option></select>', $this->select->getHTML() ); - } - - /** - * Adding default later on should set the correct selection or - * raise an exception. - * To handle this, we need to render the options in getHtml() - * @covers XmlSelect::setDefault - */ - public function testSetDefaultAfterAddingOptions() { - $this->select->addOption( 'foo1' ); - $this->select->addOption( 'bar1' ); - $this->select->addOption( 'foo2' ); - $this->select->setDefault( 'bar1' ); # setting default after adding options - $this->assertEquals( - '<select><option value="foo1">foo1</option>' . "\n" . - '<option value="bar1" selected="">bar1</option>' . "\n" . - '<option value="foo2">foo2</option></select>', $this->select->getHTML() ); - } - - /** - * @covers XmlSelect::setAttribute - * @covers XmlSelect::getAttribute - */ - public function testGetAttributes() { - # create some attributes - $this->select->setAttribute( 'dummy', 0x777 ); - $this->select->setAttribute( 'string', 'euro €' ); - $this->select->setAttribute( 1911, 'razor' ); - - # verify we can retrieve them - $this->assertEquals( - $this->select->getAttribute( 'dummy' ), - 0x777 - ); - $this->assertEquals( - $this->select->getAttribute( 'string' ), - 'euro €' - ); - $this->assertEquals( - $this->select->getAttribute( 1911 ), - 'razor' - ); - - # inexistent keys should give us 'null' - $this->assertEquals( - $this->select->getAttribute( 'I DO NOT EXIT' ), - null - ); - - # verify string / integer - $this->assertEquals( - $this->select->getAttribute( '1911' ), - 'razor' - ); - $this->assertEquals( - $this->select->getAttribute( 'dummy' ), - 0x777 - ); - } -} |