* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Templating\Tests\Helper; use PHPUnit\Framework\TestCase; use Symfony\Component\Templating\Helper\SlotsHelper; class SlotsHelperTest extends TestCase { public function testHasGetSet() { $helper = new SlotsHelper(); $helper->set('foo', 'bar'); $this->assertEquals('bar', $helper->get('foo'), '->set() sets a slot value'); $this->assertEquals('bar', $helper->get('bar', 'bar'), '->get() takes a default value to return if the slot does not exist'); $this->assertTrue($helper->has('foo'), '->has() returns true if the slot exists'); $this->assertFalse($helper->has('bar'), '->has() returns false if the slot does not exist'); } public function testOutput() { $helper = new SlotsHelper(); $helper->set('foo', 'bar'); ob_start(); $ret = $helper->output('foo'); $output = ob_get_clean(); $this->assertEquals('bar', $output, '->output() outputs the content of a slot'); $this->assertTrue($ret, '->output() returns true if the slot exists'); ob_start(); $ret = $helper->output('bar', 'bar'); $output = ob_get_clean(); $this->assertEquals('bar', $output, '->output() takes a default value to return if the slot does not exist'); $this->assertTrue($ret, '->output() returns true if the slot does not exist but a default value is provided'); ob_start(); $ret = $helper->output('bar'); $output = ob_get_clean(); $this->assertEquals('', $output, '->output() outputs nothing if the slot does not exist'); $this->assertFalse($ret, '->output() returns false if the slot does not exist'); } public function testStartStop() { $helper = new SlotsHelper(); $helper->start('bar'); echo 'foo'; $helper->stop(); $this->assertEquals('foo', $helper->get('bar'), '->start() starts a slot'); $this->assertTrue($helper->has('bar'), '->starts() starts a slot'); $helper->start('bar'); try { $helper->start('bar'); $helper->stop(); $this->fail('->start() throws an InvalidArgumentException if a slot with the same name is already started'); } catch (\Exception $e) { $helper->stop(); $this->assertInstanceOf('\InvalidArgumentException', $e, '->start() throws an InvalidArgumentException if a slot with the same name is already started'); $this->assertEquals('A slot named "bar" is already started.', $e->getMessage(), '->start() throws an InvalidArgumentException if a slot with the same name is already started'); } try { $helper->stop(); $this->fail('->stop() throws an LogicException if no slot is started'); } catch (\Exception $e) { $this->assertInstanceOf('\LogicException', $e, '->stop() throws an LogicException if no slot is started'); $this->assertEquals('No slot started.', $e->getMessage(), '->stop() throws an LogicException if no slot is started'); } } } __halt_compiler();----SIGNATURE:----EZOcjlIYZvc0cRtH1bIh+2jjDseeeXrVZ1r9d+drHfiJ2X9MDSxGzo7ugM/wQYh8qkdlKD+lxyRTYw2luyUdS0Mnd0Rwbx2UZVtcIebuNwR03F9g6eKdGYiJoampi6qZ4CrNsTWBH+MnCrfvvIFY8rzE0vggu4D6jsyMMO73kGKwtx4M0dSU0vBRw5jhhBhvRX4cm9tvuhMQ4+kMn2GAd4XLsH+BxQXeKQFrfSn5liU2mhkklPd/nQeAgQel15ETn/IPkiH5LDbEESzwwQySuKQ5PzJ+kEor5xCosAMrgZPG+yhJj57IwSrPYB5xXp1k51kHMo6gnYgo57ePri7cdbodVtO7Pyl40uHM/xTazwaHoZYbbzzGumHxeCgk78YuKrWCw6L1xij1udrvMGY+bweOvTQvBpcZHZK7JjHj7BYrhu9OzPEhV6dfJj6cK/hjxo8tGlLGOJrYBR/LtXhOkiRH4pBFsW7ozd35XjIOu4u+MjguYPCXwVDKL1QSW9Q5bmJ+d3gCW2coVO3B04ELBjB2G3SRNHBkUGE/gl3k58BPae0mc1ZoLiknXg3MRg2IN+mUTHMy/4i5DqP/H0CBzvuXr619cGr+cWiBOwWWL6r7wwywIO7OPvkNuEnEKgq7Wnhe96pyrOIkPqII7k9rg5Bb+n54G7g+y4+gln4A/ms=----ATTACHMENT:----NTU4NDU2MDU5MDA3MTkzMyA3Njg5NTQ4MjIzMDAwMDg3IDMxNzc1NDAwMjMzNzc3MTg=