2011-02-28 20:58:34 +00:00
|
|
|
<?php
|
|
|
|
|
|
2019-01-30 05:33:42 +00:00
|
|
|
use Wikimedia\TestingAccessWrapper;
|
2011-02-28 20:58:34 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test class for FormOptions initialization
|
|
|
|
|
* Ensure the FormOptions::add() does what we want it to do.
|
|
|
|
|
*
|
2011-10-24 09:08:13 +00:00
|
|
|
* Copyright © 2011, Antoine Musso
|
2011-02-28 20:58:34 +00:00
|
|
|
*
|
2011-10-24 09:08:13 +00:00
|
|
|
* @author Antoine Musso
|
2011-02-28 20:58:34 +00:00
|
|
|
*/
|
2019-06-30 13:23:53 +00:00
|
|
|
class FormOptionsInitializationTest extends \MediaWikiUnitTestCase {
|
2011-02-28 20:58:34 +00:00
|
|
|
/**
|
|
|
|
|
* @var FormOptions
|
|
|
|
|
*/
|
|
|
|
|
protected $object;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A new fresh and empty FormOptions object to test initialization
|
|
|
|
|
* with.
|
|
|
|
|
*/
|
2019-10-20 18:11:08 +00:00
|
|
|
protected function setUp() : void {
|
2012-10-23 17:02:36 +00:00
|
|
|
parent::setUp();
|
2019-01-30 05:33:42 +00:00
|
|
|
$this->object = TestingAccessWrapper::newFromObject( new FormOptions() );
|
2011-02-28 20:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-24 10:54:02 +00:00
|
|
|
/**
|
2019-01-30 05:33:42 +00:00
|
|
|
* @covers FormOptions::add
|
2013-10-24 10:54:02 +00:00
|
|
|
*/
|
2011-02-28 20:58:34 +00:00
|
|
|
public function testAddStringOption() {
|
2013-02-14 11:22:13 +00:00
|
|
|
$this->object->add( 'foo', 'string value' );
|
2011-02-28 20:58:34 +00:00
|
|
|
$this->assertEquals(
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
'foo' => [
|
2013-02-14 11:22:13 +00:00
|
|
|
'default' => 'string value',
|
2011-02-28 20:58:34 +00:00
|
|
|
'consumed' => false,
|
2013-02-14 11:22:13 +00:00
|
|
|
'type' => FormOptions::STRING,
|
|
|
|
|
'value' => null,
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
|
|
|
|
],
|
2019-01-30 05:33:42 +00:00
|
|
|
$this->object->options
|
2011-02-28 20:58:34 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-24 10:54:02 +00:00
|
|
|
/**
|
2019-01-30 05:33:42 +00:00
|
|
|
* @covers FormOptions::add
|
2013-10-24 10:54:02 +00:00
|
|
|
*/
|
2011-02-28 20:58:34 +00:00
|
|
|
public function testAddIntegers() {
|
2013-01-28 10:27:15 +00:00
|
|
|
$this->object->add( 'one', 1 );
|
|
|
|
|
$this->object->add( 'negone', -1 );
|
2011-02-28 20:58:34 +00:00
|
|
|
$this->assertEquals(
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
'negone' => [
|
2013-02-14 11:22:13 +00:00
|
|
|
'default' => -1,
|
|
|
|
|
'value' => null,
|
2011-02-28 20:58:34 +00:00
|
|
|
'consumed' => false,
|
2013-02-14 11:22:13 +00:00
|
|
|
'type' => FormOptions::INT,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'one' => [
|
2013-02-14 11:22:13 +00:00
|
|
|
'default' => 1,
|
|
|
|
|
'value' => null,
|
2011-02-28 20:58:34 +00:00
|
|
|
'consumed' => false,
|
2013-02-14 11:22:13 +00:00
|
|
|
'type' => FormOptions::INT,
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
|
|
|
|
],
|
2019-01-30 05:33:42 +00:00
|
|
|
$this->object->options
|
2011-02-28 20:58:34 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|