root/branches/boomer/t/04-config.t @ 1100

Revision 1100, 1.9 kB (checked in by hachi, 2 years ago)

Merging release-20 to boomer branch: svn merge -r62323:63659 http://svn.sixapart.com/repos/eng/movabletype/branches/release-20 .

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