Skip to content

Commit

Permalink
Old functionality refactored, needs to modify graph
Browse files Browse the repository at this point in the history
  • Loading branch information
carbontwelve committed Oct 8, 2018
1 parent 6a654e0 commit 8ecbf0a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
33 changes: 32 additions & 1 deletion src/Modules/Generators/TaxonomyArchiveGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Tapestry\Modules\Generators;

use Tapestry\Entities\Project;
use Tapestry\Modules\Source\ClonedSource;
use Tapestry\Modules\Source\SourceInterface;

/**
Expand Down Expand Up @@ -48,12 +49,42 @@ class TaxonomyArchiveGenerator extends AbstractGenerator implements GeneratorInt
*
* @param Project $project
* @return array|SourceInterface[]
* @throws \Exception
*/
public function generate(Project $project): array
{
$generated = [];

if (! $uses = $this->source->getData('use')){
return [$this->source];
}

foreach ($uses as $use){

// TODO: Implement generate() method.
if (! $data = $this->source->getData($use.'_items')) {
continue;
}

$classifications = array_keys($data);

foreach ($data as $taxonomyName => $files) {
$newFile = new ClonedSource($this->source);

// @todo refactor so that a TaxonomyViewHelper is injected?
$newFile->setData([
'generator' => array_filter($this->source->getData('generator'), function ($value) {
return $value !== 'TaxonomyArchiveGenerator';
}),
'taxonomyName' => $taxonomyName,
$use.'_items' => $files,
$use => $classifications,
]);
$newFile->setUid($newFile->getUid().'_'.$taxonomyName);
$newFile->setOverloaded('filename', $taxonomyName);
array_push($generated, $newFile);
}
}

return $generated;
}
}
14 changes: 12 additions & 2 deletions tests/Unit/ContentGeneratorsNTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
use Tapestry\Modules\Generators\ContentGeneratorFactory;
use Tapestry\Modules\Generators\Generator;
use Tapestry\Modules\Generators\PaginationGenerator;
use Tapestry\Modules\Generators\TaxonomyArchiveGenerator;
use Tapestry\Modules\Source\ClonedSource;
use Tapestry\Modules\Source\MemorySource;
use Tapestry\Steps\LoadContentTypes;
use Tapestry\Steps\ParseContentTypes;
use Tapestry\Tests\TestCase;

class ContentGeneratorsNTest extends TestCase
Expand Down Expand Up @@ -251,9 +253,17 @@ public function testTaxonomyArchiveGenerator()
}
unset($x,$y);

$n = 1;
$t = new MemorySource('template', '', 'template.phtml', 'phtml', '/', '/template.phtml', ['date' => time(), 'generator' => ['TaxonomyArchiveGenerator'], 'use' => ['blog_tags']]);
$contentTypes->bucketSource($t);

$this->markTestIncomplete('This test has not been implemented yet');
(new ParseContentTypes())($project, new NullOutput());

$generator = new TaxonomyArchiveGenerator();
$generator->setSource($t);
$result = $generator->generate($project);

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

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

0 comments on commit 8ecbf0a

Please sign in to comment.