Skip to content

Commit

Permalink
Item1984: Change the way of enabling a non-default plugin to use the …
Browse files Browse the repository at this point in the history
…standard $Foswiki::cfg interface, now that the standard interface works.

Pass a query object with the correct web when creating a new session, because trunk will now call initPlugin when creating a new session, and initPlugin must have the correct web name or the test will fail.
Change the routine for setting preferences to use Foswiki::Func instead of Foswiki::Meta, so that the tests work on trunk and on 1.0.6.
Remove an extra "my" that causes the test module not to compile with "warnings as errors" on.


git-svn-id: http://svn.foswiki.org/trunk/GoogleAnalyticsPlugin@4778 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
MichaelTempest authored and MichaelTempest committed Sep 6, 2009
1 parent a9560fe commit f40450a
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions test/unit/GoogleAnalyticsPlugin/GoogleAnalyticsPluginTests.pm
Expand Up @@ -23,11 +23,17 @@ sub new {
return $self;
}

sub loadExtraConfig {
my $this = shift;
$this->SUPER::loadExtraConfig();

$Foswiki::cfg{Plugins}{GoogleAnalyticsPlugin}{Enabled} = 1;
}

sub set_up {
my $this = shift;

$this->SUPER::set_up();
$this->{session}->enterContext('GoogleAnalyticsPluginEnabled');
$Foswiki::cfg{Plugins}{GoogleAnalyticsPlugin}{WebPropertyId} = $WEB_ID;
$userWikiName = Foswiki::Func::getWikiName($this->{test_user});
}
Expand Down Expand Up @@ -109,7 +115,9 @@ sub test_script_output_GOOGLESITEKEY {
Foswiki::Plugins::GoogleAnalyticsPlugin::initPlugin($this->{test_topic}, $this->{test_web}, $this->{test_user}, 'System');
$this->_setWebPref( "GOOGLESITEKEY", "MY_OLD_GOOGLESITEKEY" );
my $t = new Foswiki( $this->{test_user_login} );
my $query = new Unit::Request("");
$query->path_info("/$this->{test_web}/$this->{test_topic}");
my $t = new Foswiki( $this->{test_user_login}, $query );
my $html = <<HTML_END;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
Expand Down Expand Up @@ -481,7 +489,7 @@ sub test_isTrackingEnabledForUser {
$Foswiki::cfg{Plugins}{GoogleAnalyticsPlugin}{Tracking}{Enable}{Users} = '';
$Foswiki::cfg{Plugins}{GoogleAnalyticsPlugin}{Tracking}{Disable}{Users} = '';
my $enabled = Foswiki::Plugins::GoogleAnalyticsPlugin::_isTrackingEnabledForUser('');
$enabled = Foswiki::Plugins::GoogleAnalyticsPlugin::_isTrackingEnabledForUser('');
$this->assert_equals( 0, $enabled );
}
Expand All @@ -505,15 +513,11 @@ sub _set {
$this->assert_not_null($pref);
$type ||= 'Set';
my $user = $this->{session}->{user};
$this->assert_not_null($user);
my $topicObject = Foswiki::Meta->load( $this->{session}, $web, $topic );
my $text = $topicObject->text();
$text =~ s/^\s*\* $type $pref =.*$//gm;
$text .= "\n\t* $type $pref = $val\n";
$topicObject->text($text);
try {
$topicObject->save();
my( $meta, $text ) = Foswiki::Func::readTopic( $web, $topic );
$text =~ s/^\s*\* $type $pref =.*$//gm;
$text .= "\n\t* $type $pref = $val\n";
Foswiki::Func::saveTopic( $web, $topic, $meta, $text, { dontlog => 1, minor => 1 } );
}
catch Foswiki::AccessControlException with {
$this->assert( 0, shift->stringify() );
Expand Down

0 comments on commit f40450a

Please sign in to comment.