MediaWiki  1.30.2
ExternalStoreTest.php
Go to the documentation of this file.
1 <?php
7 
11  public function testExternalFetchFromURL() {
12  $this->setMwGlobals( 'wgExternalStores', false );
13 
14  $this->assertFalse(
15  ExternalStore::fetchFromURL( 'FOO://cluster1/200' ),
16  'Deny if wgExternalStores is not set to a non-empty array'
17  );
18 
19  $this->setMwGlobals( 'wgExternalStores', [ 'FOO' ] );
20 
21  $this->assertEquals(
22  ExternalStore::fetchFromURL( 'FOO://cluster1/200' ),
23  'Hello',
24  'Allow FOO://cluster1/200'
25  );
26  $this->assertEquals(
27  ExternalStore::fetchFromURL( 'FOO://cluster1/300/0' ),
28  'Hello',
29  'Allow FOO://cluster1/300/0'
30  );
31  # Assertions for r68900
32  $this->assertFalse(
33  ExternalStore::fetchFromURL( 'ftp.example.org' ),
34  'Deny domain ftp.example.org'
35  );
36  $this->assertFalse(
37  ExternalStore::fetchFromURL( '/example.txt' ),
38  'Deny path /example.txt'
39  );
40  $this->assertFalse(
41  ExternalStore::fetchFromURL( 'http://' ),
42  'Deny protocol http://'
43  );
44  }
45 }
46 
48 
49  protected $data = [
50  'cluster1' => [
51  '200' => 'Hello',
52  '300' => [
53  'Hello', 'World',
54  ],
55  ],
56  ];
57 
63  function fetchFromURL( $url ) {
64  // Based on ExternalStoreDB
65  $path = explode( '/', $url );
66  $cluster = $path[2];
67  $id = $path[3];
68  if ( isset( $path[4] ) ) {
69  $itemID = $path[4];
70  } else {
71  $itemID = false;
72  }
73 
74  if ( !isset( $this->data[$cluster][$id] ) ) {
75  return null;
76  }
77 
78  if ( $itemID !== false
79  && is_array( $this->data[$cluster][$id] )
80  && isset( $this->data[$cluster][$id][$itemID] )
81  ) {
82  return $this->data[$cluster][$id][$itemID];
83  }
84 
85  return $this->data[$cluster][$id];
86  }
87 }
ExternalStoreTest\testExternalFetchFromURL
testExternalFetchFromURL()
ExternalStore::fetchFromURL.
Definition: ExternalStoreTest.php:11
ExternalStore\fetchFromURL
static fetchFromURL( $url, array $params=[])
Fetch data from given URL.
Definition: ExternalStore.php:75
php
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
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Definition: MediaWikiTestCase.php:672
MediaWikiTestCase
Definition: MediaWikiTestCase.php:15
ExternalStoreFOO
Definition: ExternalStoreTest.php:47
ExternalStoreTest
External Store tests.
Definition: ExternalStoreTest.php:6
ExternalStoreFOO\$data
$data
Definition: ExternalStoreTest.php:49
$path
$path
Definition: NoLocalSettings.php:26
ExternalStoreFOO\fetchFromURL
fetchFromURL( $url)
Fetch data from given URL.
Definition: ExternalStoreTest.php:63
data
and how to run hooks for an and one after Each event has a preferably in CamelCase For ArticleDelete hook A clump of code and data that should be run when an event happens This can be either a function and a chunk of data
Definition: hooks.txt:6