PageRenderTime 57ms CodeModel.GetById 35ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/symfony/symfony/src/Symfony/Component/Templating/Tests/Helper/SlotsHelperTest.php

https://bitbucket.org/pyneff/carsharing
PHP | 80 lines | 61 code | 11 blank | 8 comment | 0 complexity | 76d50b1a2294fb8a77d763564d54d396 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0, BSD-3-Clause, BSD-2-Clause
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Templating\Tests\Helper;
  11. use Symfony\Component\Templating\Helper\SlotsHelper;
  12. class SlotsHelperTest extends \PHPUnit_Framework_TestCase
  13. {
  14. public function testHasGetSet()
  15. {
  16. $helper = new SlotsHelper();
  17. $helper->set('foo', 'bar');
  18. $this->assertEquals('bar', $helper->get('foo'), '->set() sets a slot value');
  19. $this->assertEquals('bar', $helper->get('bar', 'bar'), '->get() takes a default value to return if the slot does not exist');
  20. $this->assertTrue($helper->has('foo'), '->has() returns true if the slot exists');
  21. $this->assertFalse($helper->has('bar'), '->has() returns false if the slot does not exist');
  22. }
  23. public function testOutput()
  24. {
  25. $helper = new SlotsHelper();
  26. $helper->set('foo', 'bar');
  27. ob_start();
  28. $ret = $helper->output('foo');
  29. $output = ob_get_clean();
  30. $this->assertEquals('bar', $output, '->output() outputs the content of a slot');
  31. $this->assertTrue($ret, '->output() returns true if the slot exists');
  32. ob_start();
  33. $ret = $helper->output('bar', 'bar');
  34. $output = ob_get_clean();
  35. $this->assertEquals('bar', $output, '->output() takes a default value to return if the slot does not exist');
  36. $this->assertTrue($ret, '->output() returns true if the slot does not exist but a default value is provided');
  37. ob_start();
  38. $ret = $helper->output('bar');
  39. $output = ob_get_clean();
  40. $this->assertEquals('', $output, '->output() outputs nothing if the slot does not exist');
  41. $this->assertFalse($ret, '->output() returns false if the slot does not exist');
  42. }
  43. public function testStartStop()
  44. {
  45. $helper = new SlotsHelper();
  46. $helper->start('bar');
  47. echo 'foo';
  48. $helper->stop();
  49. $this->assertEquals('foo', $helper->get('bar'), '->start() starts a slot');
  50. $this->assertTrue($helper->has('bar'), '->starts() starts a slot');
  51. $helper->start('bar');
  52. try {
  53. $helper->start('bar');
  54. $helper->stop();
  55. $this->fail('->start() throws an InvalidArgumentException if a slot with the same name is already started');
  56. } catch (\Exception $e) {
  57. $helper->stop();
  58. $this->assertInstanceOf('\InvalidArgumentException', $e, '->start() throws an InvalidArgumentException if a slot with the same name is already started');
  59. $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');
  60. }
  61. try {
  62. $helper->stop();
  63. $this->fail('->stop() throws an LogicException if no slot is started');
  64. } catch (\Exception $e) {
  65. $this->assertInstanceOf('\LogicException', $e, '->stop() throws an LogicException if no slot is started');
  66. $this->assertEquals('No slot started.', $e->getMessage(), '->stop() throws an LogicException if no slot is started');
  67. }
  68. }
  69. }