<?php
namespace Lia\Test;
/**
* for testing bugs I find while working on Liaison
*/
class Bugs extends \Tlf\Tester {
/**
* @bug(dec-16-2021) the 'lia' object being passed to views is NOT the root lia object. Could not re-produce issue in test. This bug originated in taeluf.com
*/
public function testViewLiaObj(){
$lia = new \Lia();
$server = new \Lia\Package\Server($lia);
$test = new \Lia\Package\Server($lia, 'test', $this->file('test/Server/'));
$target = get_class($lia).'#'.spl_object_id($lia).'#addon-count('.count($lia->addons).')';
$actual = $lia->view('wrong-lia').'';
$this->compare($target, $actual);
}
/**
* Happening on taeluf.com. I have a `theme.php` view & associated `.css` and `.js` files in `theme/` dir. I think the files are all being added to `resources` addon, BUT they're NOT being output to the cached css file
*
* This test FAILED to re-create the bug. So I realized that resource files were being added AFTER the theme view was being `require`d. I moved the code around & now it works. I have not added a test for this.
*
* @tldr theme view wasn't adding resources. This test fails to test that. The issue is fixed & untested.
*/
public function testViewAddsChildResources(){
$this->empty_dir($this->file('test/Server/cache/'));
$response = $this->get('/nest-res/');
preg_match("/href=\"([^\"]+)\"/", $response, $css_matches);
$css_url = $css_matches[1];
preg_match("/src=\"([^\"]+)\"/", $response, $js_matches);
$js_url = $js_matches[1];
$css = $this->get($css_url);
$js = $this->get($js_url);
$this->test('compiled css');
echo "\n\n".$css;
$this->str_contains($css, ['.one{}','.two{}']);
$this->test('compiled js');
echo "\n\n".$js;
$this->str_contains($js, ['var one;','var two;']);
$this->empty_dir($this->file('test/Server/cache/'));
}
/**
* When updating taeluf.com, resources weren't loading because cache dir wasn't set. I set the cache dir AFTER creating server & that worked. Then the routes weren't working & I found Resource's route...() method was not being setup through scan('route'); So I added an `onPackageReady()` feature to do the scanning after a package is all set up. Now, route...() gets called, but the cache dir isn't set yet. So now the routes can't setup.
*
* @tldr setting a prop before creating package/addons stopped propagation to the addons
* @fixed by doing: `$this->props[$this->addon_name] = $this->props[$this->addon_name] ?? [];` instead of just `$this->props[$this->addon_name] = [];`
*/
public function testCacheDirPropagation(){
$dir = $this->file('input/Bugs/cache/');
$lia = new \Lia();
$server = new \Lia\Package\Server($lia, 'server');
$lia->set('lia:server.cache.dir', $dir);
$this->compare($dir, $lia->addons['cache']->dir);
}
}