summaryrefslogtreecommitdiff
path: root/t/inc/LocalFile.t
blob: 09df9e19c473398efd0f22c85ecd9ed55c24bba3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env php
<?php

define( 'MEDIAWIKI', true );
require 't/Test.php';

require 'includes/Defines.php';
require 'includes/ProfilerStub.php';
require 'LocalSettings.php';
require 'includes/Setup.php';

/**
 * These tests should work regardless of $wgCapitalLinks
 */

$info = array(
	'name' => 'test',
	'directory' => '/testdir',
	'url' => '/testurl',
	'hashLevels' => 2,
	'transformVia404' => false,
);

plan( 35 );

$repo_hl0 = new LocalRepo( array( 'hashLevels' => 0 ) + $info );
$repo_hl2 = new LocalRepo( array( 'hashLevels' => 2 ) + $info );
$repo_lc = new LocalRepo( array( 'initialCapital' => false ) + $info );

$file_hl0 = $repo_hl0->newFile( 'test!' );
$file_hl2 = $repo_hl2->newFile( 'test!' );
$file_lc = $repo_lc->newFile( 'test!' );

is( $file_hl0->getHashPath(), '', 'Get hash path, hasLev 0' );
is( $file_hl2->getHashPath(), 'a/a2/', 'Get hash path, hasLev 2' );
is( $file_lc->getHashPath(), 'c/c4/', 'Get hash path, lc first' );

is( $file_hl0->getRel(), 'Test!', 'Get rel path, hasLev 0' );
is( $file_hl2->getRel(), 'a/a2/Test!', 'Get rel path, hasLev 2' );
is( $file_lc->getRel(), 'c/c4/test!', 'Get rel path, lc first' );

is( $file_hl0->getUrlRel(), 'Test%21', 'Get rel url, hasLev 0' );
is( $file_hl2->getUrlRel(), 'a/a2/Test%21', 'Get rel url, hasLev 2' );
is( $file_lc->getUrlRel(), 'c/c4/test%21', 'Get rel url, lc first' );

is( $file_hl0->getArchivePath(), '/testdir/archive', 'Get archive path, hasLev 0' );
is( $file_hl2->getArchivePath(), '/testdir/archive/a/a2', 'Get archive path, hasLev 2' );
is( $file_hl0->getArchivePath( '!' ), '/testdir/archive/!', 'Get archive path, hasLev 0' );
is( $file_hl2->getArchivePath( '!' ), '/testdir/archive/a/a2/!', 'Get archive path, hasLev 2' );

is( $file_hl0->getThumbPath(), '/testdir/thumb/Test!', 'Get thumb path, hasLev 0' );
is( $file_hl2->getThumbPath(), '/testdir/thumb/a/a2/Test!', 'Get thumb path, hasLev 2' );
is( $file_hl0->getThumbPath( 'x' ), '/testdir/thumb/Test!/x', 'Get thumb path, hasLev 0' );
is( $file_hl2->getThumbPath( 'x' ), '/testdir/thumb/a/a2/Test!/x', 'Get thumb path, hasLev 2' );

is( $file_hl0->getArchiveUrl(), '/testurl/archive', 'Get archive url, hasLev 0' );
is( $file_hl2->getArchiveUrl(), '/testurl/archive/a/a2', 'Get archive url, hasLev 2' );
is( $file_hl0->getArchiveUrl( '!' ), '/testurl/archive/%21', 'Get archive url, hasLev 0' );
is( $file_hl2->getArchiveUrl( '!' ), '/testurl/archive/a/a2/%21', 'Get archive url, hasLev 2' );

is( $file_hl0->getThumbUrl(), '/testurl/thumb/Test%21', 'Get thumb url, hasLev 0' );
is( $file_hl2->getThumbUrl(), '/testurl/thumb/a/a2/Test%21', 'Get thumb url, hasLev 2' );
is( $file_hl0->getThumbUrl( 'x' ), '/testurl/thumb/Test%21/x', 'Get thumb url, hasLev 0' );
is( $file_hl2->getThumbUrl( 'x' ), '/testurl/thumb/a/a2/Test%21/x', 'Get thumb url, hasLev 2' );

is( $file_hl0->getArchiveVirtualUrl(), 'mwrepo://test/public/archive', 'Get archive virtual url, hasLev 0' );
is( $file_hl2->getArchiveVirtualUrl(), 'mwrepo://test/public/archive/a/a2', 'Get archive virtual url, hasLev 2' );
is( $file_hl0->getArchiveVirtualUrl( '!' ), 'mwrepo://test/public/archive/%21', 'Get archive virtual url, hasLev 0' );
is( $file_hl2->getArchiveVirtualUrl( '!' ), 'mwrepo://test/public/archive/a/a2/%21', 'Get archive virtual url, hasLev 2' );

is( $file_hl0->getThumbVirtualUrl(), 'mwrepo://test/public/thumb/Test%21', 'Get thumb virtual url, hasLev 0' );
is( $file_hl2->getThumbVirtualUrl(), 'mwrepo://test/public/thumb/a/a2/Test%21', 'Get thumb virtual url, hasLev 2' );
is( $file_hl0->getThumbVirtualUrl( '!' ), 'mwrepo://test/public/thumb/Test%21/%21', 'Get thumb virtual url, hasLev 0' );
is( $file_hl2->getThumbVirtualUrl( '!' ), 'mwrepo://test/public/thumb/a/a2/Test%21/%21', 'Get thumb virtual url, hasLev 2' );

is( $file_hl0->getUrl(), '/testurl/Test%21', 'Get url, hasLev 0' );
is( $file_hl2->getUrl(), '/testurl/a/a2/Test%21', 'Get url, hasLev 2' );