<?php
namespace Liaison\Test\Addon;
class ViewOld extends \Tlf\Tester {
/**
* @test Exception message when view not found
*/
public function testViewNotFound(){
$v = new \Lia\Addon\View();
$v->addViewCallable('found', function(){return 'nah';});
$this->catch('ErrorException')
->containing('Undefined index: not-found')
;
try {
$view = $v->view('not-found');
} catch (\Exception $e){
$this->throw($e);
}
}
/**
* @test Exception message when there are no views for the requested null namespace
*/
public function testNullNamespaceNotFound(){
$v = new \Lia\Addon\View();
$this->catch('Exception')
->containing('Undefined index: '.null)
;
try {
$view = $v->view('not-found');
} catch (\Exception $e){
$this->throw($e);
}
}
/**
* @test Exception when there are no views for the requested non-null namespace
*/
public function testNamespaceNotFound(){
$v = new \Lia\Addon\View();
$this->catch('Exception')
->containing('Undefined index: nons')
;
try {
$view = $v->view('nons:not-found');
} catch (\Exception $e){
$this->throw($e);
}
}
/**
*
* @test that a null-namespace view() call will fallback to a namespaced view (when null-namespace view was not explicitly set)
*/
public function testNoNamespaceFallback(){
$v = new \Lia\Addon\View();
$v->addViewCallable('lia:theme', function(){return 'ok';});
$output = $v->view('theme').'';
$this->compare('ok', $output);
}
/**
* @test views can be loaded from multiple namespaces
* @test that overwrite happens when conflictMode == overwrite
*/
public function testAddViewCallableWithNamespace(){
$lia = $view_addon = new \Lia\Addon\View();
$view_addon->conflictMode = 'overwrite';
// This approach is extremely rudimentary and not recommended.
$phrase = "Fight for your right to vote.";
$lia->addViewCallable('lia:theme',
$liaTheme=function($name, $args) use ($phrase){
return $phrase;
}
);
$lia->addViewCallable('theme',$liaTheme);
$lia->addViewCallable('wrong:theme',
function($name, $args) use ($phrase){
return 'view with wrong namespace';
}
);
$phraseAny = 'view with no namespace';
$lia->addViewCallable('theme',
function($name, $args) use ($phraseAny){
return $phraseAny;
}
);
$anyNamespace = $lia->view('theme').'';
$this->compare($phraseAny, $anyNamespace);
$specificNamespace = $lia->view('lia:theme').'';
$this->compare($phrase, $specificNamespace);
$this->compare('view with wrong namespace', $lia->view('wrong:theme').'');
}
public function testAddViewCallable(){
$lia = $view_addon = new \Lia\Addon\View();
//@export_start(Usage.View.AddViewCallable)
$phrase = "Fight for your right to vote.";
$lia->addViewCallable('theme',
function($name, $args) use ($phrase){
return $phrase;
}
);
$content = $lia->view('theme').'';
//@export_end(Usage.View.AddViewCallable)
$this->compare($phrase, $content);
}
public function view_dir(){
return $this->cli->pwd.'/test/input/Views/';
}
}