MediaWiki  1.29.1
Go to the documentation of this file.
1 <?php
3 class HTMLRestrictionsFieldTest extends PHPUnit_Framework_TestCase {
4  public function testConstruct() {
5  $field = new HTMLRestrictionsField( [ 'fieldname' => 'restrictions' ] );
6  $this->assertNotEmpty( $field->getLabel(), 'has a default label' );
7  $this->assertNotEmpty( $field->getHelpText(), 'has a default help text' );
8  $this->assertEquals( MWRestrictions::newDefault(), $field->getDefault(),
9  'defaults to the default MWRestrictions object' );
11  $field = new HTMLRestrictionsField( [
12  'fieldname' => 'restrictions',
13  'label' => 'foo',
14  'help' => 'bar',
15  'default' => 'baz',
16  ] );
17  $this->assertEquals( 'foo', $field->getLabel(), 'label can be customized' );
18  $this->assertEquals( 'bar', $field->getHelpText(), 'help text can be customized' );
19  $this->assertEquals( 'baz', $field->getDefault(), 'default can be customized' );
20  }
25  public function testForm( $text, $value ) {
26  $form = HTMLForm::factory( 'ooui', [
27  'restrictions' => [ 'class' => HTMLRestrictionsField::class ],
28  ] );
29  $request = new FauxRequest( [ 'wprestrictions' => $text ], true );
31  $context->setRequest( $request );
32  $form->setContext( $context );
33  $form->setTitle( Title::newFromText( 'Main Page' ) )->setSubmitCallback( function () {
34  return true;
35  } )->prepareForm();
36  $status = $form->trySubmit();
38  if ( $status instanceof StatusValue ) {
39  $this->assertEquals( $value !== false, $status->isGood() );
40  } elseif ( $value === false ) {
41  $this->assertNotSame( true, $status );
42  } else {
43  $this->assertSame( true, $status );
44  }
46  if ( $value !== false ) {
47  $restrictions = $form->mFieldData['restrictions'];
48  $this->assertInstanceOf( MWRestrictions::class, $restrictions );
49  $this->assertEquals( $value, $restrictions->toArray()['IPAddresses'] );
50  }
52  // sanity
53  $form->getHTML( $status );
54  }
56  public function provideValidate() {
57  return [
58  // submitted text, value of 'IPAddresses' key or false for validation error
59  [ null, [ '', '::/0' ] ],
60  [ '', [] ],
61  [ "\n::/0", [ '', '::/0' ] ],
62  [ "\n::/x", false ],
63  ];
64  }
65 }
error also a ContextSource you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition: hooks.txt:2612
WebRequest clone which takes values from a provided array.
Definition: FauxRequest.php:33
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:265
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: StatusValue.php:42
error also a ContextSource you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2612
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
Definition: hooks.txt:1049
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
An IContextSource implementation which will inherit context from another source but allow individual ...
Definition: DerivativeContext.php:31
Definition: HTMLRestrictionsFieldTest.php:4
Class for updating an MWRestrictions value (which is, currently, basically just an IP address list).
Definition: HTMLRestrictionsField.php:13
static factory( $displayFormat)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:277
Definition: HTMLRestrictionsFieldTest.php:56
testForm( $text, $value)
Definition: HTMLRestrictionsFieldTest.php:25
setContext(IContextSource $context)
Set the IContextSource object.
Definition: ContextSource.php:58
static newDefault()
Definition: MWRestrictions.php:41
Definition: styleTest.css.php:45
static getMain()
Static methods.
Definition: RequestContext.php:468
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
Definition: HTMLRestrictionsFieldTest.php:3