Merge "HTMLForm: Add OOUI support for 'multiselect' with 'dropdown' => true"
[lhc/web/wiklou.git] / tests / phpunit / ResourceLoaderTestCase.php
1 <?php
2
3 use Psr\Log\LoggerInterface;
4 use Psr\Log\NullLogger;
5
6 abstract class ResourceLoaderTestCase extends MediaWikiTestCase {
7 // Version hash for a blank file module.
8 // Result of ResourceLoader::makeHash(), ResourceLoaderTestModule
9 // and ResourceLoaderFileModule::getDefinitionSummary().
10 const BLANK_VERSION = '09p30q0';
11
12 /**
13 * @param string $lang
14 * @param string $dir
15 * @return ResourceLoaderContext
16 */
17 protected function getResourceLoaderContext( $lang = 'en', $dir = 'ltr' ) {
18 $resourceLoader = new ResourceLoader();
19 $request = new FauxRequest( [
20 'lang' => $lang,
21 'modules' => 'startup',
22 'only' => 'scripts',
23 'skin' => 'vector',
24 'target' => 'phpunit',
25 ] );
26 $ctx = $this->getMockBuilder( 'ResourceLoaderContext' )
27 ->setConstructorArgs( [ $resourceLoader, $request ] )
28 ->setMethods( [ 'getDirection' ] )
29 ->getMock();
30 $ctx->method( 'getDirection' )->willReturn( $dir );
31 return $ctx;
32 }
33
34 public static function getSettings() {
35 return [
36 // For ResourceLoader::inDebugMode since it doesn't have context
37 'ResourceLoaderDebug' => true,
38
39 // Avoid influence from wgInvalidateCacheOnLocalSettingsChange
40 'CacheEpoch' => '20140101000000',
41
42 // For ResourceLoader::__construct()
43 'ResourceLoaderSources' => [],
44
45 // For wfScript()
46 'ScriptPath' => '/w',
47 'ScriptExtension' => '.php',
48 'Script' => '/w/index.php',
49 'LoadScript' => '/w/load.php',
50 ];
51 }
52
53 protected function setUp() {
54 parent::setUp();
55
56 ResourceLoader::clearCache();
57
58 $globals = [];
59 foreach ( self::getSettings() as $key => $value ) {
60 $globals['wg' . $key] = $value;
61 }
62 $this->setMwGlobals( $globals );
63 }
64 }
65
66 /* Stubs */
67
68 class ResourceLoaderTestModule extends ResourceLoaderModule {
69 protected $messages = [];
70 protected $dependencies = [];
71 protected $group = null;
72 protected $source = 'local';
73 protected $position = 'bottom';
74 protected $script = '';
75 protected $styles = '';
76 protected $skipFunction = null;
77 protected $isRaw = false;
78 protected $isKnownEmpty = false;
79 protected $type = ResourceLoaderModule::LOAD_GENERAL;
80 protected $targets = [ 'phpunit' ];
81
82 public function __construct( $options = [] ) {
83 foreach ( $options as $key => $value ) {
84 $this->$key = $value;
85 }
86 }
87
88 public function getScript( ResourceLoaderContext $context ) {
89 return $this->validateScriptFile( 'input', $this->script );
90 }
91
92 public function getStyles( ResourceLoaderContext $context ) {
93 return [ '' => $this->styles ];
94 }
95
96 public function getMessages() {
97 return $this->messages;
98 }
99
100 public function getDependencies( ResourceLoaderContext $context = null ) {
101 return $this->dependencies;
102 }
103
104 public function getGroup() {
105 return $this->group;
106 }
107
108 public function getSource() {
109 return $this->source;
110 }
111 public function getPosition() {
112 return $this->position;
113 }
114
115 public function getType() {
116 return $this->type;
117 }
118
119 public function getSkipFunction() {
120 return $this->skipFunction;
121 }
122
123 public function isRaw() {
124 return $this->isRaw;
125 }
126 public function isKnownEmpty( ResourceLoaderContext $context ) {
127 return $this->isKnownEmpty;
128 }
129
130 public function enableModuleContentVersion() {
131 return true;
132 }
133 }
134
135 class ResourceLoaderFileModuleTestModule extends ResourceLoaderFileModule {
136 }
137
138 class EmptyResourceLoader extends ResourceLoader {
139 // TODO: This won't be needed once ResourceLoader is empty by default
140 // and default registrations are done from ServiceWiring instead.
141 public function __construct( Config $config = null, LoggerInterface $logger = null ) {
142 $this->setLogger( $logger ?: new NullLogger() );
143 $this->config = $config ?: ConfigFactory::getDefaultInstance()->makeConfig( 'main' );
144 $this->setMessageBlobStore( new MessageBlobStore( $this, $this->getLogger() ) );
145 }
146 }