Skip to content

Commit

Permalink
Add ContentTypeGeneratorTest class
Browse files Browse the repository at this point in the history
  • Loading branch information
jatempa committed Sep 22, 2015
1 parent 92be80e commit 7f65585
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 0 deletions.
58 changes: 58 additions & 0 deletions Test/Command/GeneratorContentTypeCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
/**
* @file
* Contains \Drupal\Console\Test\Command\GeneratorContentTypeCommandTest.
*/

namespace Drupal\Console\Test\Command;

use Drupal\Console\Command\GeneratorContentTypeCommand;
use Symfony\Component\Console\Tester\CommandTester;
use Drupal\Console\Test\DataProvider\ContentTypeDataProviderTrait;

class GeneratorContentTypeCommandTest extends GenerateCommandTest
{
use ContentTypeDataProviderTrait;

/**
* ContentType generator test
*
* @param $module
* @param $bundle_name
* @param $bundle_title
*
* @dataProvider commandData
*/
public function testGenerateContentType(
$module,
$bundle_name,
$bundle_title
) {
$command = new GeneratorContentTypeCommand($this->getTranslatorHelper());
$command->setContainer($this->getContainer());
$command->setHelperSet($this->getHelperSet());
$command->setGenerator($this->getGenerator());

$commandTester = new CommandTester($command);

$code = $commandTester->execute(
[
'--module' => $module,
'--bundle-name' => $bundle_name,
'--bundle-title' => $bundle_title
],
['interactive' => false]
);

$this->assertEquals(0, $code);
}

private function getGenerator()
{
return $this
->getMockBuilder('Drupal\Console\Generator\ContentTypeGenerator')
->disableOriginalConstructor()
->setMethods(['generate'])
->getMock();
}
}
22 changes: 22 additions & 0 deletions Test/DataProvider/ContentTypeDataProviderTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Drupal\Console\Test\DataProvider;

/**
* Class ContentTypeDataProviderTrait
* @package Drupal\Console\Test\DataProvider
*/
trait ContentTypeDataProviderTrait
{
/**
* @return array
*/
public function commandData()
{
$this->setUpTemporalDirectory();

return [
['foo', 'default', 'default']
];
}
}
52 changes: 52 additions & 0 deletions Test/Generator/ContentTypeGeneratorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/**
* @file
* Contains Drupal\Console\Test\Generator\ContentTypeGeneratorTest.
*/

namespace Drupal\Console\Test\Generator;

use Drupal\Console\Generator\ContentTypeGenerator;
use Drupal\Console\Test\DataProvider\ContentTypeDataProviderTrait;

class ContentTypeGeneratorTest extends GeneratorTest
{
use ContentTypeDataProviderTrait;

/**
* ContentType generator test
*
* @param $module
* @param $bundle_name
* @param $bundle_title
*
* @dataProvider commandData
*/
public function testGenerateContentType(
$module,
$bundle_name,
$bundle_title
) {
$generator = new ContentTypeGenerator();
$this->getHelperSet()->get('renderer')->setSkeletonDirs($this->getSkeletonDirs());
$this->getHelperSet()->get('renderer')->setTranslator($this->getTranslatorHelper());
$generator->setHelpers($this->getHelperSet());

$files = [
$generator->getSite()->getModulePath($module) . '/' . $module . '/config/install/core.entity_form_display.node.' . $bundle_name . '.default.yml',
$generator->getSite()->getModulePath($module) . '/' . $module . '/config/install/core.entity_view_display.node.' . $bundle_name . '.default.yml',
$generator->getSite()->getModulePath($module) . '/' . $module . '/config/install/core.entity_view_display.node.' . $bundle_name . '.teaser.yml',
$generator->getSite()->getModulePath($module) . '/' . $module . '/config/install/core.entity_view_mode.node.teaser.yml',
$generator->getSite()->getModulePath($module) . '/' . $module . '/config/install/field.field.node.' . $bundle_name . '.body.yml',
$generator->getSite()->getModulePath($module) . '/' . $module . '/config/install/field.storage.node.body.yml'
];

foreach ($files as $file) {
$this->assertTrue(
file_exists($file),
sprintf('%s does not exist', $file)
);
}
}
}

0 comments on commit 7f65585

Please sign in to comment.