Add some global variables for the templates and test them in the controller.
This commit is contained in:
parent
207304b373
commit
75bccb789d
@ -72,6 +72,9 @@ class Bootstrap
|
|||||||
$templatePath = __DIR__ . "/../templates";
|
$templatePath = __DIR__ . "/../templates";
|
||||||
$templateCache = false;
|
$templateCache = false;
|
||||||
$twig = Twig::create($templatePath, [ 'cache' => $templateCache ]);
|
$twig = Twig::create($templatePath, [ 'cache' => $templateCache ]);
|
||||||
|
// Add the global variables
|
||||||
|
$twig->getEnvironment()->addGlobal('site_name', "Slovocast");
|
||||||
|
$twig->getEnvironment()->addGlobal('site_description', "A no-bullshit podcast hosting service");
|
||||||
$app->add(TwigMiddleware::create($app, $twig));
|
$app->add(TwigMiddleware::create($app, $twig));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,4 +75,26 @@ class ControllerTest extends TestCase
|
|||||||
$response->getHeaderLine('Content-Type')
|
$response->getHeaderLine('Content-Type')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We have some Global variables set in the Configuration, for now its
|
||||||
|
* hardcoded in the Bootstrap class.
|
||||||
|
*/
|
||||||
|
public function testRenderSiteName(): void
|
||||||
|
{
|
||||||
|
$testController = new class extends Controller {
|
||||||
|
public function respond(): Response
|
||||||
|
{
|
||||||
|
return $this->renderInline("<h1>{{ site_name }}</h1>");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
$app = $this->getAppInstance();
|
||||||
|
$app->get('/test', $testController);
|
||||||
|
|
||||||
|
$request = $this->createRequest('GET', '/test');
|
||||||
|
$response = $app->handle($request);
|
||||||
|
|
||||||
|
$this->assertEquals('<h1>Slovocast</h1>', $response->getBody());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user