mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
Enhance Parser & Plugin testing
This commit is contained in:
parent
d79e5bfdf6
commit
830d7186a5
@ -72,6 +72,24 @@ class ParserPluginTest extends \CIUnitTestCase
|
||||
$this->assertEquals($this->setHints($this->validator->showError('email')), $this->setHints($this->parser->renderString($template)));
|
||||
}
|
||||
|
||||
public function testRoute()
|
||||
{
|
||||
// prime the pump
|
||||
$routes = service('routes');
|
||||
$routes->add('path/(:any)/to/(:num)', 'myController::goto/$1/$2');
|
||||
|
||||
$template = '{+ route myController::goto string 13 +}';
|
||||
|
||||
$this->assertEquals('/path/string/to/13', $this->parser->renderString($template));
|
||||
}
|
||||
|
||||
public function testSiteURL()
|
||||
{
|
||||
$template = '{+ siteURL +}';
|
||||
|
||||
$this->assertEquals('http://example.com/index.php', $this->parser->renderString($template));
|
||||
}
|
||||
|
||||
public function testValidationErrorsList()
|
||||
{
|
||||
$this->validator->setError('email', 'Invalid email address');
|
||||
|
@ -224,6 +224,31 @@ class ParserTest extends \CIUnitTestCase
|
||||
$this->assertEquals("Super Heroes\nTom Dick Henry ", $parser->renderString($template));
|
||||
}
|
||||
|
||||
public function testParseLoopObjectProperties()
|
||||
{
|
||||
$parser = new Parser($this->config, $this->viewsDir, $this->loader);
|
||||
$obj1 = new stdClass();
|
||||
$obj1->name = 'Tom';
|
||||
$obj2 = new stdClass();
|
||||
$obj2->name = 'Dick';
|
||||
$obj3 = new stdClass();
|
||||
$obj3->name = 'Henry';
|
||||
|
||||
$data = [
|
||||
'title' => 'Super Heroes',
|
||||
'powers' => [
|
||||
$obj1,
|
||||
$obj2,
|
||||
$obj3,
|
||||
],
|
||||
];
|
||||
|
||||
$template = "{title}\n{powers}{name} {/powers}";
|
||||
|
||||
$parser->setData($data, 'html');
|
||||
$this->assertEquals("Super Heroes\nTom Dick Henry ", $parser->renderString($template));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
public function testParseLoopEntityProperties()
|
||||
@ -242,6 +267,7 @@ class ParserTest extends \CIUnitTestCase
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
$parser = new Parser($this->config, $this->viewsDir, $this->loader);
|
||||
@ -258,6 +284,44 @@ class ParserTest extends \CIUnitTestCase
|
||||
$this->assertEquals("Super Heroes\n bar baz first second ", $parser->renderString($template));
|
||||
}
|
||||
|
||||
public function testParseLoopEntityObjectProperties()
|
||||
{
|
||||
$power = new class extends \CodeIgniter\Entity
|
||||
{
|
||||
|
||||
public $foo = 'bar';
|
||||
protected $bar = 'baz';
|
||||
protected $obj1 = null;
|
||||
protected $obj2 = null;
|
||||
public $bobbles = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->obj1 = new stdClass();
|
||||
$this->obj2 = new stdClass();
|
||||
$this->obj1->name = 'first';
|
||||
$this->obj2->name = 'second';
|
||||
$this->bobbles = [
|
||||
$this->obj1,
|
||||
$this->obj2,
|
||||
];
|
||||
}
|
||||
};
|
||||
|
||||
$parser = new Parser($this->config, $this->viewsDir, $this->loader);
|
||||
$data = [
|
||||
'title' => 'Super Heroes',
|
||||
'powers' => [
|
||||
$power
|
||||
],
|
||||
];
|
||||
|
||||
$template = "{title}\n{powers} {foo} {bar} {bobbles}{name} {/bobbles}{/powers}";
|
||||
|
||||
$parser->setData($data, 'html');
|
||||
$this->assertEquals("Super Heroes\n bar baz first second ", $parser->renderString($template));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
public function testMismatchedVarPair()
|
||||
|
Loading…
x
Reference in New Issue
Block a user