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