test-timber-starter-theme.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. class TestTimberStarterTheme extends WP_UnitTestCase {
  3. function setUp() {
  4. self::_setupStarterTheme();
  5. switch_theme( basename( dirname( dirname( __FILE__ ) ) ) );
  6. require_once(__DIR__.'/../functions.php');
  7. }
  8. function tearDown() {
  9. switch_theme('twentythirteen');
  10. }
  11. function testTimberExists() {
  12. $context = Timber::context();
  13. $this->assertTrue(is_array($context));
  14. }
  15. function testFunctionsPHP() {
  16. $context = Timber::context();
  17. $this->assertEquals('StarterSite', get_class($context['site']));
  18. $this->assertTrue(current_theme_supports('post-thumbnails'));
  19. $this->assertEquals('bar', $context['foo']);
  20. }
  21. function testLoading() {
  22. $str = Timber::compile('tease.twig');
  23. $this->assertStringStartsWith('<article class="tease tease-" id="tease-">', $str);
  24. $this->assertStringEndsWith('</article>', $str);
  25. }
  26. /**
  27. * Helper test to output current twig version
  28. */
  29. function testTwigVersion() {
  30. $str = Timber::compile_string("{{ constant('Twig_Environment::VERSION') }}");
  31. //error_log('Twig version = '.$str);
  32. }
  33. function testTwigFilter() {
  34. $str = Timber::compile_string('{{ "foo" | myfoo }}');
  35. $this->assertEquals('foo bar!', $str);
  36. }
  37. static function _setupStarterTheme(){
  38. $dest = WP_CONTENT_DIR . '/themes/' . basename( dirname( dirname( __FILE__ ) ) );
  39. $src = realpath( __DIR__ . '/../../' . basename( dirname( dirname( __FILE__ ) ) ) );
  40. if ( is_dir($src) && !file_exists($dest) ) {
  41. symlink($src, $dest);
  42. }
  43. }
  44. }