Skip to content

Commit

Permalink
Discovered work needing done for #322 before continuing on #315
Browse files Browse the repository at this point in the history
  • Loading branch information
carbontwelve committed Oct 8, 2018
1 parent 8ecbf0a commit 7159887
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/Modules/ContentTypes/ContentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
use Tapestry\Entities\Taxonomy;
use Tapestry\Modules\Source\SourceInterface;

/**
* Class ContentType
*
* @todo #322 write unit test...
* @package Tapestry\Modules\ContentTypes
*/
class ContentType
{
/**
Expand Down Expand Up @@ -235,6 +241,7 @@ public function getSourceList(string $order = 'desc')
}

/**
* @todo should this not be done when a Source is bucketed into this content type?
* @param Project $project
* @throws \Exception
*/
Expand Down
17 changes: 14 additions & 3 deletions src/Modules/Generators/TaxonomyArchiveGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tapestry\Modules\Generators;

use Tapestry\Entities\DependencyGraph\SimpleNode;
use Tapestry\Entities\Project;
use Tapestry\Modules\Source\ClonedSource;
use Tapestry\Modules\Source\SourceInterface;
Expand Down Expand Up @@ -59,8 +60,11 @@ public function generate(Project $project): array
return [$this->source];
}

foreach ($uses as $use){
// Add the Generator to the graph
$nodeId = $this->source->getUid().'_generator_TaxonomyGenerator_'.time();
$project->addSource($this->source->getUid(), new SimpleNode($nodeId, 'TaxonomyGenerator'));

foreach ($uses as $use){
if (! $data = $this->source->getData($use.'_items')) {
continue;
}
Expand All @@ -69,6 +73,8 @@ public function generate(Project $project): array

foreach ($data as $taxonomyName => $files) {
$newFile = new ClonedSource($this->source);
$newFile->setUid($newFile->getUid().'_taxonomyarchive_'.$taxonomyName);
$newFile->setOverloaded('filename', $taxonomyName);

// @todo refactor so that a TaxonomyViewHelper is injected?
$newFile->setData([
Expand All @@ -79,8 +85,13 @@ public function generate(Project $project): array
$use.'_items' => $files,
$use => $classifications,
]);
$newFile->setUid($newFile->getUid().'_'.$taxonomyName);
$newFile->setOverloaded('filename', $taxonomyName);


// Add Generated Source to Source Graph
$project->addSource($nodeId, $newFile);

// @todo before we can complete this section of 315 the ContentType needs unit testing to ensure it works as expected.

array_push($generated, $newFile);
}
}
Expand Down
11 changes: 11 additions & 0 deletions tests/Unit/ContentGeneratorsNTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,17 @@ public function testTaxonomyArchiveGenerator()

$this->assertTrue(is_array($result));
$this->assertCount(2, $result);

$graph = new Debug($project->getGraph());
$n = $graph->graphViz('configuration');

//
// Check Graph is updated with correct dependencies
//
$dep = (new Resolver())->resolve($project->getSource('configuration'));
$this->assertCount(10, $dep); // (8 initial sources + 2 for each generated)

$n = 1;
}

// @todo add test to check this modifies the graph
Expand Down

0 comments on commit 7159887

Please sign in to comment.