<?php
namespace Liaison\Test\Addon;
/**
* Old router tests that are sloppy, confusing, hard to understand but still provide utility.
*/
class RouterOther extends \Tlf\Tester {
//@TODO Fill in placeholder tests for Router
// public function testNotImplemented_InvalidMethods(){
// $this->disable();
// echo "This is not implemented currently, but the test-method is left here as a placeholder, as a note.";
// }
// public function testPublicDirRouting(){
// $this->disable();
// }
// public function testConflictBetweenRoutesWithDifferentVarCounts(){
// $this->disable();
// }
// public function testConflictBetweenRoutesWithSameVarCounts(){
// $this->disable();
// }
// public function testConflictBetweenStaticRouteAndVarRoute(){
// $this->disable();
// }
//
// public function testCustomRouteMethod(){
// $this->disable();
// // echo "This is not implemented currently, but the test-method is left here as a placeholder, as a note.";
// return false;
// }
/**
*
* @note this test changes the varDelim
*/
public function testPatternRouteMethod(){
// this test has been failing for awhile & I'm not fixing it right now.
// $this->disable();
// return;
// $this->setup($lia,$router, $package);
$lia = new \Lia();
$package = new \Lia\Package($lia, 'test:package');
$router = new \Lia\Addon\Router($package);
$router->init_lia();
$router->varDelim = '\\.\\/\\:';
$compo = new class($package) extends \Lia\Addon {
public string $fqn = 'test:idk';
public function __construct($lia=null, $name=null){
parent::__construct($lia,$name);
// $this->lia = $lia;
}
//@export_start(Usage.Router.PatternCallback)
// Declare functions inside your component with the 'routePattern' prefix, followed by an uppercase letter or underscore
// I believe this implementation is going to change.
public function routePatternBlog($route) {
// echo 'reout method';
// exit;
if ($route===false)return [
'/blog/{article}/',
'/blog/{article}',
'/about/{page}/'
];
$blogs = [
'black-lives-matter'=> 'Have you looked at traffic data in your home town? Is there a racial disparity?',
'toxic-pollution' => 'The US EPA, under Trump, has rolled back many protections for U.S. citizens',
'us-voter-suppression' => 'Why are mailboxes and mail-sorting machines being removed from cities? Why isn\'t the post office tax-payer funded?',
];
$abouts = [
'me'=>"Hi, I'm Reed. I'm an indie developer. I'm very opinionated and wish the world were a better place."
];
$var = $route->var(0);
if ($route->part(0)=='about'
&&isset($abouts[$var]))return $abouts[$var];
else if ($route->part(0)=='blog'
&&isset($blogs[$var]))return $blogs[$var];
else return "A blog was not found for '{$var}'";
}
//@export_end(Usage.Router.PatternCallback)
};
// $compo->autoRegisterScannedPrefixes($lia);
$lia->scan('route', $compo);
// $lia->dump();
$urls = [
'/blog/black-lives-matter/',
'/blog/toxic-pollution',
'/about/me/',
'/blog/global-warming/',
];
$success = true;
foreach ($urls as $url){
$route = new \Lia\Obj\Route(
[
'url'=>$url,
'paramaters'=>array_slice(explode('/',$url),2,1)
]
);
$aRoute = $lia->route(new \Lia\Obj\Request($url))[0];
// print_r($aRoute);
$this->compare($compo->routePatternBlog($route), ($aRoute->target())($aRoute));
}
$t1 = $lia->route(new \Lia\Obj\Request('/blog/us-voter-suppression'))[0]->target();
$a1 = $lia->route(new \Lia\Obj\Request('/blog/us-voter-suppression/'))[0]->target();
$compo->lia = null;
$this->compare_raw($t1,$a1);
$this->compare([], $lia->route(new \Lia\Obj\Request('/ranked-choice-voting/')));
$this->compare([], $lia->route(new \Lia\Obj\Request('/about/me')));
}
// public function testBenchmarktestPatternRouteMethod(){
// $this->disable();
// echo 'to save energy, this benchmark is disabled, as it does not actually test anything.';
// return false;
// $i=0;
// ob_start();
// while ($i++<100)$this->testPatternRouteMethod();
// ob_get_clean();
// return true;
// }
// public function testBenchmarkGetRoute(){
// $this->disable();
// echo 'to save energy, this benchmark is disabled, as it does not actually test anything.';
// return false;
// $i=0;
// ob_start();
// while ($i++<100)$this->testGetRoute();
// ob_get_clean();
// return true;
// }
// public function testBenchmarkUrlToTestReg(){
// $this->disable();
// echo 'to save energy, this benchmark is disabled, as it does not actually test anything.';
// return false;
// $i=0;
// ob_start();
// while ($i++<100)$this->testUrlToTestReg();
// ob_get_clean();
// return true;
// }
// public function testBenchmarkParsePatternsOneHundredTimes(){
// $this->disable();
// echo 'to save energy, this benchmark is disabled, as it does not actually test anything.';
// return false;
// $i=0;
// ob_start();
// while ($i++<100)$this->testParsePatterns();
// ob_get_clean();
// return true;
// }
}