-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new abstract class `ViewBuilder`: the complex views (eg: pages) are now seen as objects
- Loading branch information
Showing
5 changed files
with
134 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Exacodis\Pilot; | ||
use rawsrc\PhpEcho\PhpEcho; | ||
use rawsrc\PhpEcho\ViewBuilder; | ||
|
||
class Login extends ViewBuilder | ||
{ | ||
public function build(): PhpEcho | ||
{ | ||
$layout = new PhpEcho('layout_01.php'); | ||
$layout['body'] = new PhpEcho('block/block_01.php', ['block_01_text' => 'run_txt_block_01']); | ||
|
||
return $layout; | ||
} | ||
} | ||
|
||
/** @var Pilot $pilot */ | ||
|
||
$pilot->run( | ||
id: 'view.builder.001', | ||
test: function() { | ||
$view = new Login(); | ||
|
||
return $view->build(); | ||
}, | ||
description: 'test the return value from view builder', | ||
); | ||
$pilot->assertIsInstanceOf(PhpEcho::class); | ||
|
||
$login = new Login(); | ||
$login['foo'] = 'bar'; | ||
$login['abc'] = '" < > "'; | ||
$pilot->run( | ||
id: 'view.builder.002', | ||
test: fn() => $login['abc'], | ||
description: 'array access, value never escaped', | ||
); | ||
$pilot->assertIsString(); | ||
$pilot->assertEqual('" < > "'); | ||
|
||
$pilot->run( | ||
id: 'view.builder.003', | ||
test: fn() => (string)new Login(), | ||
description: 'return a view builder as a string', | ||
); | ||
$pilot->assertIsString(); | ||
$pilot->assertEqual(<<<html | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
</head> | ||
<body> | ||
<p>run_txt_block_01</p> | ||
</body> | ||
</html> | ||
html); |