Skip to content

Commit

Permalink
Merge pull request #11 from DarrenInwood/templatedir
Browse files Browse the repository at this point in the history
Enable using configured template directories for setup task
  • Loading branch information
madmatt committed Apr 11, 2016
2 parents 5669fc4 + e64e7cc commit 0017594
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
7 changes: 4 additions & 3 deletions code/tasks/RealMeSetupTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,12 +396,13 @@ private function getSimpleSAMLVendorPath()
private function getConfigurationTemplateDir()
{
$dir = $this->config()->template_config_dir;
$path = Controller::join_links(BASE_PATH, $dir);

if (!$dir || false === $this->isReadable($dir)) {
$dir = REALME_MODULE_PATH . '/templates/simplesaml-configuration';
if ($dir && false !== $this->isReadable($path)) {
return $path;
}

return Controller::join_links(BASE_PATH, $dir);
return Controller::join_links(BASE_PATH, REALME_MODULE_PATH . '/templates/simplesaml-configuration');
}

/**
Expand Down
38 changes: 38 additions & 0 deletions tests/RealMeSetupTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,42 @@ public function testValidateConsumerAssertionURL()
$validateAuthNContext->invoke($realMeSetupTask, RealMeService::ENV_MTS);
$this->assertCount(1, $errors->getValue($realMeSetupTask), "The validation should fail for non-HTTPs");
}

/**
* Ensure that setting the RealMeSetupTask template_config_dir config value
* can adjust the path that the task looks in for its templates.
* - ensure the default works
* - ensure configuring a bad directory name falls back to the default
* - ensure that configuring a good value uses the configured directory
*/
public function testConfigurationTemplateDir()
{
$realMeSetupTask = new RealMeSetupTask();

$getConfigurationTemplateDirMethod = new ReflectionMethod('RealMeSetupTask', 'getConfigurationTemplateDir');
$getConfigurationTemplateDirMethod->setAccessible(true);

$config = Config::inst();

$config->update('RealMeSetupTask', 'template_config_dir', '');
$this->assertEquals(
BASE_PATH . DIRECTORY_SEPARATOR . REALME_MODULE_PATH . '/templates/simplesaml-configuration',
$getConfigurationTemplateDirMethod->invoke($realMeSetupTask),
'Using no configuration for template_config_dir should use the default template directory.'
);

$config->update('RealMeSetupTask', 'template_config_dir', 'xyzzy');
$this->assertEquals(
BASE_PATH . DIRECTORY_SEPARATOR . REALME_MODULE_PATH . '/templates/simplesaml-configuration',
$getConfigurationTemplateDirMethod->invoke($realMeSetupTask),
'Configuring a directory that does not exist should use the default template directory.'
);

$config->update('RealMeSetupTask', 'template_config_dir', REALME_MODULE_PATH);
$this->assertEquals(
BASE_PATH . DIRECTORY_SEPARATOR . REALME_MODULE_PATH, // doesn't contain templates, but does exist
$getConfigurationTemplateDirMethod->invoke($realMeSetupTask),
'Configuring a directory that exists should use the configured template directory.'
);
}
}

0 comments on commit 0017594

Please sign in to comment.