Esempio n. 1
0
 public function testGetSetHas()
 {
     $engine = new ProjectTemplateEngine(new ehough_templating_TemplateNameParser(), $this->loader);
     $foo = new ehough_templating_test_helper_SimpleHelper('foo');
     $engine->set($foo);
     $this->assertEquals($foo, $engine->get('foo'), '->set() sets a helper');
     $engine[$foo] = 'bar';
     $this->assertEquals($foo, $engine->get('bar'), '->set() takes an alias as a second argument');
     $this->assertTrue(isset($engine['bar']));
     try {
         $engine->get('foobar');
         $this->fail('->get() throws an InvalidArgumentException if the helper is not defined');
     } catch (Exception $e) {
         $this->assertInstanceOf('InvalidArgumentException', $e, '->get() throws an InvalidArgumentException if the helper is not defined');
         $this->assertEquals('The helper "foobar" is not defined.', $e->getMessage(), '->get() throws an InvalidArgumentException if the helper is not defined');
     }
     $this->assertTrue(isset($engine['bar']));
     $this->assertTrue($engine->has('foo'), '->has() returns true if the helper exists');
     $this->assertFalse($engine->has('foobar'), '->has() returns false if the helper does not exist');
 }
Esempio n. 2
0
// __get()
$t->diag('__get()');
$t->is($engine->foo, $helper, '->__get() returns the value of a helper');
try {
    $engine->bar;
    $t->fail('->__get() throws an InvalidArgumentException if the helper is not defined');
} catch (InvalidArgumentException $e) {
    $t->pass('->__get() throws an InvalidArgumentException if the helper is not defined');
}
// ->get() ->set() ->has()
$t->diag('->get() ->set() ->has()');
$engine = new ProjectTemplateEngine($loader);
$engine->set('foo', 'bar');
$t->is($engine->get('foo'), 'bar', '->set() sets a slot value');
$t->is($engine->get('bar', 'bar'), 'bar', '->get() takes a default value to return if the slot does not exist');
$t->ok($engine->has('foo'), '->has() returns true if the slot exists');
$t->ok(!$engine->has('bar'), '->has() returns false if the slot does not exist');
// ->output()
$t->diag('->output()');
ob_start();
$ret = $engine->output('foo');
$output = ob_get_clean();
$t->is($output, 'bar', '->output() outputs the content of a slot');
$t->is($ret, true, '->output() returns true if the slot exists');
ob_start();
$ret = $engine->output('bar', 'bar');
$output = ob_get_clean();
$t->is($output, 'bar', '->output() takes a default value to return if the slot does not exist');
$t->is($ret, true, '->output() returns true if the slot does not exist but a default value is provided');
ob_start();
$ret = $engine->output('bar');