From 6fb26fcaf4757f2d465f89a78cbcefc2d548a085 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 24 Mar 2009 22:30:23 -0400 Subject: [PATCH] test cleanup and start ad injection work --- classes/PublisherInfo.php | 16 +++++++++ test/TestPublisherInfo.php | 36 ++++++++++++++++--- ...erful.php => TestSuitePluginWonderful.php} | 0 3 files changed, 48 insertions(+), 4 deletions(-) rename test/{TestPluginWonderful.php => TestSuitePluginWonderful.php} (100%) diff --git a/classes/PublisherInfo.php b/classes/PublisherInfo.php index d3f34a2..fe70a0c 100644 --- a/classes/PublisherInfo.php +++ b/classes/PublisherInfo.php @@ -128,6 +128,22 @@ class PublisherInfo { return false; } } + + /** + * Inject ads into body copy. + * @param string $copy The body copy to inject the ads into. + * @return string The body copy with injected ads. + */ + function inject_ads_into_body_copy($copy, $use_standardcode = false) { + foreach ($this->adboxes as $adbox) { + foreach (array('adboxid', 'template_tag_id') as $field) { + $code = $use_standardcode ? "standardcode" : "advancedcode"; + $copy = str_replace("PW(" . $adbox->{$field} . ")", $adbox->{$code}, $copy); + } + } + $copy = preg_replace('#PW\\\\\(([^\\\]*)\\\\\)#', 'PW(\1)', $copy); // backslash alert! + return $copy; + } } ?> \ No newline at end of file diff --git a/test/TestPublisherInfo.php b/test/TestPublisherInfo.php index 2ea6b93..a41c657 100644 --- a/test/TestPublisherInfo.php +++ b/test/TestPublisherInfo.php @@ -3,7 +3,7 @@ require_once('../classes/PublisherInfo.php'); class TestPublisherInfo extends PHPUnit_Framework_TestCase { - private $parser, $default_data; + private $parser, $default_data, $default_data_as_hash; public function setup() { $this->parser = new PublisherInfo(); @@ -18,10 +18,17 @@ class TestPublisherInfo extends PHPUnit_Framework_TestCase { array("a", 'description'), array("a", 'tags'), array("a", 'standardcode'), - array("a", 'advancedcode'), + array("b", 'advancedcode'), array(PW_ADBOXES_PROJECT_WONDERFUL, "type") ); - } + + $default_data_as_hash = array(); + foreach ($this->default_data as $info) { + list($value, $param) = $info; + $default_data_as_hash[$param] = $value; + } + $this->default_data_as_hash = (object)$default_data_as_hash; +} public static function badDataProvider() { return array( @@ -60,7 +67,7 @@ class TestPublisherInfo extends PHPUnit_Framework_TestCase { } public function testPWAPI() { - $this->parser->parse('aaaa'); + $this->parser->parse('aaab'); $this->assertEquals(1, $this->parser->memberid); $this->assertEquals(1, count($this->parser->adboxes)); @@ -111,6 +118,27 @@ class TestPublisherInfo extends PHPUnit_Framework_TestCase { } $this->parser->adboxes = array((object)$default_data_as_hash); } + + function adBodyInjectionData() { + return array( + array("", "", false), + array("test", "test", false), + array("PW(3)", "b", false), + array("PW(c)", "b", false), + array("PW(3)", "a", true), + array("PW(c)", "a", true), + array("PW\(3\)", "PW(3)", false), + ); + } + + /** + * @dataProvider adBodyInjectionData + */ + function testInjectAdsIntoBodyCopy($copy, $result, $use_standardcode) { + $this->parser->adboxes[0] = $this->default_data_as_hash; + $this->parser->adboxes[0]->template_tag_id = "c"; + $this->assertEquals($result, $this->parser->inject_ads_into_body_copy($copy, $use_standardcode)); + } } function __($string, $domain) { return $string; } diff --git a/test/TestPluginWonderful.php b/test/TestSuitePluginWonderful.php similarity index 100% rename from test/TestPluginWonderful.php rename to test/TestSuitePluginWonderful.php