root/trunk/t/04-config.t

Revision 4196, 2.0 kB (checked in by takayama, 3 months ago)

* Set svn keywords

  • Property svn:mime-type set to text/plain
Line 
1#!/usr/bin/perl
2# $Id: 04-config.t 2562 2008-06-12 05:12:23Z bchoate $
3use strict;
4use warnings;
5
6use lib 'lib';
7use lib 'extlib';
8use lib 't/lib';
9
10use MT::Test;
11
12use Cwd;
13use File::Spec;
14use File::Temp qw( tempfile );
15use Test::More tests => 16;
16
17use MT;
18use MT::ConfigMgr;
19
20use vars qw( $BASE );
21require 't/test-common.pl';
22
23my($cfg_file, $cfg, $mt);
24
25my $db_dir = cwd() . '/t/db/';
26(my($fh), $cfg_file) = tempfile();
27print $fh <<CFG;
28Database $db_dir/mt.db
29ObjectDriver DBI::SQLite
30AltTemplate foo bar
31AltTemplate baz quux
32CFG
33close $fh;
34
35$cfg = MT->config;
36isa_ok($cfg, 'MT::ConfigMgr');
37ok( $cfg->read_config($cfg_file), "read '$cfg_file'" );
38
39## Test standard get/set
40is($cfg->get('Database'), $db_dir . '/mt.db', "get(DataSource)=$db_dir");
41$cfg->set('DataSource', './db2');
42is($cfg->get('DataSource'), './db2', 'get(DataSource)=./db2');
43
44## Test autoloaded methods
45is($cfg->DataSource, './db2', 'autoloaded DataSource=./db2');
46$cfg->DataSource('./db');
47is($cfg->DataSource, './db', 'autoloaded DataSource=./db2');
48
49## Test defaults
50is($cfg->Serializer, 'MT', 'Serializer=MT');
51is($cfg->TimeOffset, 0, 'TimeOffset=0');
52
53## Test that multiple settings (AltTemplate) work.
54my @paths = $cfg->AltTemplate;
55is($cfg->type('AltTemplate'), 'ARRAY', 'AltTemplate=ARRAY');
56is(@paths, 2, 'paths=2');
57is(($cfg->AltTemplate)[0], 'foo bar', 'foo bar');
58is(($cfg->AltTemplate)[1], 'baz quux', 'baz quux');
59
60## Test bug in early version of ConfigMgr where space was not
61## stripped from the ends of values
62is($cfg->ObjectDriver, 'DBI::SQLite', 'ObjectDriver=SQLite');
63
64mkdir $db_dir;
65
66undef $MT::ConfigMgr::cfg;
67## Test that config file gets read correctly when passed to
68## constructor.
69$mt = MT->new( Config => $cfg_file, Directory => "." ) or die MT->errstr;
70if (!$mt) { print "# MT constructor returned error: ", MT->errstr(); }
71isa_ok($mt, 'MT');
72isa_ok($mt->{cfg}, 'MT::ConfigMgr');
73is($mt->{cfg}->Database, $db_dir . '/mt.db', "DataSource=$db_dir");
74
75unlink $cfg_file or die "Can't unlink '$cfg_file': $!";
Note: See TracBrowser for help on using the browser.