MediaWiki REL1_33
MagicWordFactoryTest.php
Go to the documentation of this file.
1<?php
2
9 private function makeMagicWordFactory( Language $contLang = null ) {
10 if ( $contLang === null ) {
11 return new MagicWordFactory( Language::factory( 'en' ) );
12 }
13 return new MagicWordFactory( $contLang );
14 }
15
16 public function testGetContentLanguage() {
17 $contLang = Language::factory( 'en' );
18
19 $magicWordFactory = $this->makeMagicWordFactory( $contLang );
20 $magicWordContLang = $magicWordFactory->getContentLanguage();
21
22 $this->assertSame( $contLang, $magicWordContLang );
23 }
24
25 public function testGetMagicWord() {
26 $magicWordIdValid = 'pageid';
27 $magicWordFactory = $this->makeMagicWordFactory();
28 $mwActual = $magicWordFactory->get( $magicWordIdValid );
29 $contLang = $magicWordFactory->getContentLanguage();
30 $expected = new MagicWord( $magicWordIdValid, [ 'PAGEID' ], false, $contLang );
31
32 $this->assertEquals( $expected, $mwActual );
33 }
34
35 public function testGetInvalidMagicWord() {
36 $magicWordFactory = $this->makeMagicWordFactory();
37
38 $this->setExpectedException( MWException::class );
40 try {
41 $magicWordFactory->get( 'invalid magic word' );
42 } finally {
44 }
45 }
46
47 public function testGetVariableIDs() {
48 $magicWordFactory = $this->makeMagicWordFactory();
49 $varIds = $magicWordFactory->getVariableIDs();
50
51 $this->assertInternalType( 'array', $varIds );
52 $this->assertNotEmpty( $varIds );
53 $this->assertContainsOnly( 'string', $varIds );
54 }
55
56 public function testGetSubstIDs() {
57 $magicWordFactory = $this->makeMagicWordFactory();
58 $substIds = $magicWordFactory->getSubstIDs();
59
60 $this->assertInternalType( 'array', $substIds );
61 $this->assertNotEmpty( $substIds );
62 $this->assertContainsOnly( 'string', $substIds );
63 }
64
68 public function testGetCacheTTL() {
69 $magicWordFactory = $this->makeMagicWordFactory();
70 $actual = $magicWordFactory->getCacheTTL( 'localday' );
71
72 $this->assertSame( 3600, $actual );
73
74 $actual = $magicWordFactory->getCacheTTL( 'currentmonth' );
75 $this->assertSame( 86400, $actual );
76
77 $actual = $magicWordFactory->getCacheTTL( 'invalid' );
78 $this->assertSame( -1, $actual );
79 }
80
81 public function testGetDoubleUnderscoreArray() {
82 $magicWordFactory = $this->makeMagicWordFactory();
83 $actual = $magicWordFactory->getDoubleUnderscoreArray();
84
85 $this->assertInstanceOf( MagicWordArray::class, $actual );
86 }
87}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
Internationalisation code.
Definition Language.php:36
testGetCacheTTL()
Test both valid and invalid caching hints paths.
makeMagicWordFactory(Language $contLang=null)
A factory that stores information about MagicWords, and creates them on demand with caching.
This class encapsulates "magic words" such as "#redirect", NOTOC, etc.
Definition MagicWord.php:57