wiki.techinc.nl/tests/phpunit/includes/FormOptionsInitializationTest.php
Kunal Mehta 8ff88cc4d2 Use TestingAccessWrapper in FormOptionsInitializationTest
Avoids the need for an extra wrapper class just to make a property
public.

Change-Id: I08ae2fb24604a2bde352525abdcadf6251045f5b
2019-01-29 21:33:42 -08:00

70 lines
1.3 KiB
PHP

<?php
use Wikimedia\TestingAccessWrapper;
/**
* Test class for FormOptions initialization
* Ensure the FormOptions::add() does what we want it to do.
*
* Copyright © 2011, Antoine Musso
*
* @author Antoine Musso
*/
class FormOptionsInitializationTest extends MediaWikiTestCase {
/**
* @var FormOptions
*/
protected $object;
/**
* A new fresh and empty FormOptions object to test initialization
* with.
*/
protected function setUp() {
parent::setUp();
$this->object = TestingAccessWrapper::newFromObject( new FormOptions() );
}
/**
* @covers FormOptions::add
*/
public function testAddStringOption() {
$this->object->add( 'foo', 'string value' );
$this->assertEquals(
[
'foo' => [
'default' => 'string value',
'consumed' => false,
'type' => FormOptions::STRING,
'value' => null,
]
],
$this->object->options
);
}
/**
* @covers FormOptions::add
*/
public function testAddIntegers() {
$this->object->add( 'one', 1 );
$this->object->add( 'negone', -1 );
$this->assertEquals(
[
'negone' => [
'default' => -1,
'value' => null,
'consumed' => false,
'type' => FormOptions::INT,
],
'one' => [
'default' => 1,
'value' => null,
'consumed' => false,
'type' => FormOptions::INT,
]
],
$this->object->options
);
}
}