Skip to content

Commit

Permalink
Merge pull request #23 from kenjis/add-test-for-nested-view
Browse files Browse the repository at this point in the history
test: add test for nested views
  • Loading branch information
kenjis authored Mar 17, 2023
2 parents 0de196c + c444e73 commit 509266b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ parameters:
scanDirectories:
- vendor/codeigniter4/codeigniter4/system/Helpers
- src/CI3Compatible/Helper
excludePaths:
- tests/App/Views/*
3 changes: 3 additions & 0 deletions src/CI3Compatible/Core/CI_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
use Kenjis\CI3Compatible\Internal\DebugLog;
use Psr\Log\LoggerInterface;

/**
* @property CI_Input $input
*/
#[\AllowDynamicProperties]
class CI_Controller extends BaseController
{
Expand Down
1 change: 1 addition & 0 deletions tests/App/Views/body.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>This is body.</p>
5 changes: 5 additions & 0 deletions tests/App/Views/layout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<p>This is layout header.</p>
<?php
$this->load->view('body');
?>
<p>This is layout footer.</p>
21 changes: 21 additions & 0 deletions tests/CI3Compatible/Core/CI_LoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use App\Libraries\Validation\Field_validation;
use App\Models\News_model;
use App\Models\Shop\Shop_model;
use CodeIgniter\Config\Factories;
use Config\Paths;
use Kenjis\CI3Compatible\Database\CI_DB;
use Kenjis\CI3Compatible\Database\CI_DB_forge;
use Kenjis\CI3Compatible\Library\CI_Form_validation;
Expand Down Expand Up @@ -69,6 +71,25 @@ public function test_view_output_return_false(): void
);
}

public function test_view_nested(): void
{
$pathConfig = config(Paths::class);
$pathConfig->viewDirectory = __DIR__ . '/../../App/Views/';
Factories::injectMock('config', 'Paths', $pathConfig);
$this->loader = new CI_Loader();
$this->controller = new CI_Controller();
$this->loader->setController($this->controller);

$output = $this->loader->view('layout', [], true);

$this->assertStringContainsString(
'<p>This is layout header.</p>
<p>This is body.</p>
<p>This is layout footer.</p>',
$output
);
}

public function test_model_loads_News_model(): void
{
$ret = $this->loader->model('news_model');
Expand Down

0 comments on commit 509266b

Please sign in to comment.