MustacheSpecTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /*
  3. * This file is part of Mustache.php.
  4. *
  5. * (c) 2010-2014 Justin Hileman
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. /**
  11. * A PHPUnit test case wrapping the Mustache Spec
  12. *
  13. * @group mustache-spec
  14. * @group functional
  15. */
  16. class Mustache_Test_Functional_MustacheSpecTest extends Mustache_Test_SpecTestCase
  17. {
  18. /**
  19. * For some reason data providers can't mark tests skipped, so this test exists
  20. * simply to provide a 'skipped' test if the `spec` submodule isn't initialized.
  21. */
  22. public function testSpecInitialized()
  23. {
  24. if (!file_exists(dirname(__FILE__).'/../../../../vendor/spec/specs/')) {
  25. $this->markTestSkipped('Mustache spec submodule not initialized: run "git submodule update --init"');
  26. }
  27. }
  28. /**
  29. * @group comments
  30. * @dataProvider loadCommentSpec
  31. */
  32. public function testCommentSpec($desc, $source, $partials, $data, $expected)
  33. {
  34. $template = self::loadTemplate($source, $partials);
  35. $this->assertEquals($expected, $template->render($data), $desc);
  36. }
  37. public function loadCommentSpec()
  38. {
  39. return $this->loadSpec('comments');
  40. }
  41. /**
  42. * @group delimiters
  43. * @dataProvider loadDelimitersSpec
  44. */
  45. public function testDelimitersSpec($desc, $source, $partials, $data, $expected)
  46. {
  47. $template = self::loadTemplate($source, $partials);
  48. $this->assertEquals($expected, $template->render($data), $desc);
  49. }
  50. public function loadDelimitersSpec()
  51. {
  52. return $this->loadSpec('delimiters');
  53. }
  54. /**
  55. * @group interpolation
  56. * @dataProvider loadInterpolationSpec
  57. */
  58. public function testInterpolationSpec($desc, $source, $partials, $data, $expected)
  59. {
  60. $template = self::loadTemplate($source, $partials);
  61. $this->assertEquals($expected, $template->render($data), $desc);
  62. }
  63. public function loadInterpolationSpec()
  64. {
  65. return $this->loadSpec('interpolation');
  66. }
  67. /**
  68. * @group inverted
  69. * @group inverted-sections
  70. * @dataProvider loadInvertedSpec
  71. */
  72. public function testInvertedSpec($desc, $source, $partials, $data, $expected)
  73. {
  74. $template = self::loadTemplate($source, $partials);
  75. $this->assertEquals($expected, $template->render($data), $desc);
  76. }
  77. public function loadInvertedSpec()
  78. {
  79. return $this->loadSpec('inverted');
  80. }
  81. /**
  82. * @group partials
  83. * @dataProvider loadPartialsSpec
  84. */
  85. public function testPartialsSpec($desc, $source, $partials, $data, $expected)
  86. {
  87. $template = self::loadTemplate($source, $partials);
  88. $this->assertEquals($expected, $template->render($data), $desc);
  89. }
  90. public function loadPartialsSpec()
  91. {
  92. return $this->loadSpec('partials');
  93. }
  94. /**
  95. * @group sections
  96. * @dataProvider loadSectionsSpec
  97. */
  98. public function testSectionsSpec($desc, $source, $partials, $data, $expected)
  99. {
  100. $template = self::loadTemplate($source, $partials);
  101. $this->assertEquals($expected, $template->render($data), $desc);
  102. }
  103. public function loadSectionsSpec()
  104. {
  105. return $this->loadSpec('sections');
  106. }
  107. }