Boilerplate to use a Directus Instance to Build a Custom Website, Content will be Manage by Directus
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.9 KiB

5 years ago
  1. <?php
  2. /**
  3. * Flight: An extensible micro-framework.
  4. *
  5. * @copyright Copyright (c) 2012, Mike Cao <mike@mikecao.com>
  6. * @license MIT, http://flightphp.com/license
  7. */
  8. require_once 'vendor/autoload.php';
  9. require_once __DIR__.'/../flight/autoload.php';
  10. class ViewTest extends PHPUnit_Framework_TestCase
  11. {
  12. /**
  13. * @var \flight\template\View
  14. */
  15. private $view;
  16. function setUp() {
  17. $this->view = new \flight\template\View();
  18. $this->view->path = __DIR__.'/views';
  19. }
  20. // Set template variables
  21. function testVariables() {
  22. $this->view->set('test', 123);
  23. $this->assertEquals(123, $this->view->get('test'));
  24. $this->assertTrue($this->view->has('test'));
  25. $this->assertTrue(!$this->view->has('unknown'));
  26. $this->view->clear('test');
  27. $this->assertEquals(null, $this->view->get('test'));
  28. }
  29. // Check if template files exist
  30. function testTemplateExists() {
  31. $this->assertTrue($this->view->exists('hello.php'));
  32. $this->assertTrue(!$this->view->exists('unknown.php'));
  33. }
  34. // Render a template
  35. function testRender() {
  36. $this->view->render('hello', array('name' => 'Bob'));
  37. $this->expectOutputString('Hello, Bob!');
  38. }
  39. // Fetch template output
  40. function testFetch() {
  41. $output = $this->view->fetch('hello', array('name' => 'Bob'));
  42. $this->assertEquals('Hello, Bob!', $output);
  43. }
  44. // Default extension
  45. function testTemplateWithExtension() {
  46. $this->view->set('name', 'Bob');
  47. $this->view->render('hello.php');
  48. $this->expectOutputString('Hello, Bob!');
  49. }
  50. // Custom extension
  51. function testTemplateWithCustomExtension() {
  52. $this->view->set('name', 'Bob');
  53. $this->view->extension = '.html';
  54. $this->view->render('world');
  55. $this->expectOutputString('Hello world, Bob!');
  56. }
  57. }