test cleanup and start ad injection work

This commit is contained in:
John Bintz 2009-03-24 22:30:23 -04:00
parent b5afdf41b8
commit 6fb26fcaf4
3 changed files with 48 additions and 4 deletions

View File

@ -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;
}
}
?>

View File

@ -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,9 +18,16 @@ 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() {
@ -60,7 +67,7 @@ class TestPublisherInfo extends PHPUnit_Framework_TestCase {
}
public function testPWAPI() {
$this->parser->parse('<pw:member memberid="1"><pw:adboxes><pw:adbox type="a" adboxid="3" sitename="a" url="http://meow.raow/" dimensions="1x1" rating="a" category="a"><pw:description>a</pw:description><pw:tags>a</pw:tags><pw:standardcode>a</pw:standardcode><pw:advancedcode>a</pw:advancedcode></pw:adbox></pw:adboxes></pw:member>');
$this->parser->parse('<pw:member memberid="1"><pw:adboxes><pw:adbox type="a" adboxid="3" sitename="a" url="http://meow.raow/" dimensions="1x1" rating="a" category="a"><pw:description>a</pw:description><pw:tags>a</pw:tags><pw:standardcode>a</pw:standardcode><pw:advancedcode>b</pw:advancedcode></pw:adbox></pw:adboxes></pw:member>');
$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; }