Debian Codegraph @

tests/phpunit/unit/includes/cache/HTMLCacheUpdaterTest.php

raw symbols SCIP
1 <?php
2
3 use MediaWiki\Cache\HTMLCacheUpdater;
4 use MediaWiki\Title\Title;
5 use MediaWiki\Title\TitleFactory;
6 use PHPUnit\Framework\MockObject\MockObject;
7
8 /**
9 * @group Cache
10 * @covers \MediaWiki\Cache\HTMLCacheUpdater
11 */
12 class HTMLCacheUpdaterTest extends MediaWikiUnitTestCase {
13
14 public function testGetCdnUrls() {
15 $htmlCache = new HTMLCacheUpdater(
16 $this->createHookContainer(),
17 $this->createTitleFactory(),
18 0, false, 86400 );
19 $title = $this->createMock( Title::class );
20 $title->method( 'canExist' )->willReturn( true );
21 $title->method( 'getInternalURL' )->willReturnCallback( static function ( $query = '' ) {
22 return 'https://test/?title=Example' . ( $query !== '' ? "&$query" : '' );
23 } );
24
25 $this->assertEquals(
26 [
27 'https://test/?title=Example',
28 'https://test/?title=Example&action=history',
29 ],
30 $htmlCache->getUrls( $title ),
31 'all urls for an article'
32 );
33 $this->assertEquals(
34 [
35 'https://test/?title=Example',
36 ],
37 $htmlCache->getUrls( $title, $htmlCache::PURGE_URLS_LINKSUPDATE_ONLY ),
38 'linkupdate urls for an article'
39 );
40
41 $title = $this->createMock( Title::class );
42 $title->method( 'canExist' )->willReturn( true );
43 $title->method( 'getInternalURL' )->willReturnCallback( static function ( $query = '' ) {
44 return 'https://test/?title=User:Example/foo.js' . ( $query !== '' ? "&$query" : '' );
45 } );
46 $title->method( 'isUserJsConfigPage' )->willReturn( true );
47 $this->assertEquals(
48 [
49 'https://test/?title=User:Example/foo.js',
50 'https://test/?title=User:Example/foo.js&action=history',
51 'https://test/?title=User:Example/foo.js&action=raw&ctype=text/javascript',
52 ],
53 $htmlCache->getUrls( $title ),
54 'all urls for a user js page'
55 );
56
57 $title = $this->createMock( Title::class );
58 $title->method( 'canExist' )->willReturn( true );
59 $title->method( 'getInternalURL' )->willReturnCallback( static function ( $query = '' ) {
60 return 'https://test/?title=MediaWiki:Example.js' . ( $query !== '' ? "&$query" : '' );
61 } );
62 $title->method( 'isSiteJsConfigPage' )->willReturn( true );
63 $this->assertEquals(
64 [
65 'https://test/?title=MediaWiki:Example.js',
66 'https://test/?title=MediaWiki:Example.js&action=history',
67 'https://test/?title=MediaWiki:Example.js&action=raw&ctype=text/javascript',
68 ],
69 $htmlCache->getUrls( $title ),
70 'all urls for a site js page'
71 );
72 }
73
74 /**
75 * @return MockObject|TitleFactory
76 */
77 private function createTitleFactory() {
78 $factory = $this->createNoOpMock( TitleFactory::class, [ 'newFromPageReference' ] );
79
80 $factory->method( 'newFromPageReference' )->willReturnArgument( 0 );
81
82 return $factory;
83 }
84 }