Skip to content
This repository has been archived by the owner on Aug 13, 2020. It is now read-only.

Commit

Permalink
Updated more code to test reg ex
Browse files Browse the repository at this point in the history
  • Loading branch information
josephspurrier committed May 3, 2014
1 parent e8c922c commit db1f657
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/SurfStack/Templating/Template_Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -757,8 +757,8 @@ protected function getRequiredClasses($class)
return join(PHP_EOL, array_reverse($arrRequire));
}

public $pre;
public $post;
public $plugrex;

/**
* Replace plugin tags with PHP code
Expand All @@ -767,11 +767,12 @@ protected function getRequiredClasses($class)
*/
protected function parsePlugins($content)
{
$this->pre = true;
$this->post = false;

$this->plugrex = array_values($this->loadPlugins());

// Load the plugin content and replace
return preg_replace_callback(array_values($this->loadPlugins()), function($matches) {
return preg_replace_callback($this->plugrex, function($matches) {
$pluginName = $matches[1];
$pluginData = $matches[2];
// Block has content, Slice does not
Expand Down
25 changes: 24 additions & 1 deletion tests/SurfStack/Templating/Template_Engine_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,33 @@ public function testPrePost()

$this->render();

$this->assertTrue($this->view->pre);
$this->assertTrue($this->view->post);
}

public function testPlugRex()
{
$this->view->clear();

$this->view->assign('test', 'Hello world');

$this->view->setTemplate('blockVariable.tpl');

$this->view->setLoadPlugins(true);

$this->view->setStripTags(false);

$this->view->setStripWhitespace(false);

$this->render();

$this->assertSame($this->view->plugrex, array(
0 => '/\{\s*(Blank)\s*(.*?)\}/i',
1 => '/\{\s*(Bold)\s*(.*?)\}(.[^\}\{]*?)\{\/\s*Bold\s*\}/i',
2 => '/\{\s*(Passthru)\s*(.*?)\}(.[^\}\{]*?)\{\/\s*Passthru\s*\}/i',
3 => '/\{\s*(Time)\s*(.*?)\}/i',
));
}

public function testSlice()
{
$this->expectOutputString(date('Y'));
Expand Down

0 comments on commit db1f657

Please sign in to comment.