Skip to content

Commit

Permalink
[#33] Add checks that generated templates contain dynamic values
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuapease committed Mar 24, 2022
1 parent afe1b9f commit bcca341
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/console/controllers/GenerateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
class GenerateController extends Controller
{

// TODO - pass variants to make multiple files `default, dark, two-up`
// TODO - Make a "create section" action that takes a section handle and entry types list and
// adds to your Craft config.
// TODO - Use options to pass partial variants instead of using parameter position
// TODO - make multiple partials at once

private $templatesDir;
Expand All @@ -32,7 +34,6 @@ public function init()
parent::init();
}


/**
* Get a config item either the default or from the config file
*
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/console/GenerateControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ public function testCreatePartial()

$this->assertFileExists($this->partialsRoot . '/foo.html');
$this->assertFileExists($this->partsKitRoot . '/foo/default.html');

$partsKitContent = file_get_contents($this->partsKitRoot . '/foo/default.html');

$this->assertStringContainsString(
'_partials/foo',
$partsKitContent
);
}

/**
Expand All @@ -72,6 +79,13 @@ public function testCreateTemplate()
->run();

$this->assertFileExists($this->templatesRoot . '/foo.html');

$fileContent = file_get_contents($this->templatesRoot . '/foo.html');

$this->assertStringContainsString(
Module::$config['partsKit']['layout'],
$fileContent
);
}

/**
Expand All @@ -88,6 +102,19 @@ public function testCreateEntryTypes()
$this->assertFileExists($this->templatesRoot . '/test-section-1/index.html');
$this->assertFileExists($this->templatesRoot . '/test-section-1/testEntryType1.html');
$this->assertFileExists($this->templatesRoot . '/test-section-1/testEntryType2.html');

$indexContent = file_get_contents($this->templatesRoot . '/test-section-1/index.html');
$entryTypeContent = file_get_contents($this->templatesRoot . '/test-section-1/testEntryType1.html');

$this->assertStringContainsString(
'_elements/test-section-1/#{entry.type.handle}',
$indexContent
);

$this->assertStringContainsString(
Module::$config['partsKit']['layout'],
$entryTypeContent
);
}

}

0 comments on commit bcca341

Please sign in to comment.