forked from movabletype/movabletype
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04-config.t
75 lines (59 loc) · 1.96 KB
/
04-config.t
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
#!/usr/bin/perl
# $Id: 04-config.t 2562 2008-06-12 05:12:23Z bchoate $
use strict;
use warnings;
use lib 'lib';
use lib 'extlib';
use lib 't/lib';
use MT::Test;
use Cwd;
use File::Spec;
use File::Temp qw( tempfile );
use Test::More tests => 16;
use MT;
use MT::ConfigMgr;
use vars qw( $BASE );
require 't/test-common.pl';
my($cfg_file, $cfg, $mt);
my $db_dir = cwd() . '/t/db/';
(my($fh), $cfg_file) = tempfile();
print $fh <<CFG;
Database $db_dir/mt.db
ObjectDriver DBI::SQLite
AltTemplate foo bar
AltTemplate baz quux
CFG
close $fh;
$cfg = MT->config;
isa_ok($cfg, 'MT::ConfigMgr');
ok( $cfg->read_config($cfg_file), "read '$cfg_file'" );
## Test standard get/set
is($cfg->get('Database'), $db_dir . '/mt.db', "get(DataSource)=$db_dir");
$cfg->set('DataSource', './db2');
is($cfg->get('DataSource'), './db2', 'get(DataSource)=./db2');
## Test autoloaded methods
is($cfg->DataSource, './db2', 'autoloaded DataSource=./db2');
$cfg->DataSource('./db');
is($cfg->DataSource, './db', 'autoloaded DataSource=./db2');
## Test defaults
is($cfg->Serializer, 'MT', 'Serializer=MT');
is($cfg->TimeOffset, 0, 'TimeOffset=0');
## Test that multiple settings (AltTemplate) work.
my @paths = $cfg->AltTemplate;
is($cfg->type('AltTemplate'), 'ARRAY', 'AltTemplate=ARRAY');
is(@paths, 2, 'paths=2');
is(($cfg->AltTemplate)[0], 'foo bar', 'foo bar');
is(($cfg->AltTemplate)[1], 'baz quux', 'baz quux');
## Test bug in early version of ConfigMgr where space was not
## stripped from the ends of values
is($cfg->ObjectDriver, 'DBI::SQLite', 'ObjectDriver=SQLite');
mkdir $db_dir;
undef $MT::ConfigMgr::cfg;
## Test that config file gets read correctly when passed to
## constructor.
$mt = MT->new( Config => $cfg_file, Directory => "." ) or die MT->errstr;
if (!$mt) { print "# MT constructor returned error: ", MT->errstr(); }
isa_ok($mt, 'MT');
isa_ok($mt->{cfg}, 'MT::ConfigMgr');
is($mt->{cfg}->Database, $db_dir . '/mt.db', "DataSource=$db_dir");
unlink $cfg_file or die "Can't unlink '$cfg_file': $!";