Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ jobs:
with:
glpi-version: "11.0.x"
ci:
if: |
startsWith(github.ref_name, 'support/') &&
github.ref_name != 'support/1.0.0'
name: "GLPI ${{ matrix.glpi-version }} - php:${{ matrix.php-version }} - ${{ matrix.db-image }}"
needs: "generate-ci-matrix"
strategy:
Expand All @@ -38,3 +35,4 @@ jobs:
glpi-version: "${{ matrix.glpi-version }}"
php-version: "${{ matrix.php-version }}"
db-image: "${{ matrix.db-image }}"
skip-changelog-check: true
8 changes: 0 additions & 8 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ public function showForm($ID, $options = [])

$current_config = array_diff_key($current_config, array_flip($secured_config));

$hide_boaviztapi_base_url = (getenv(self::ENV_BOAVIZTAPI_BASE_URL) !== false);
$renderer = TemplateRenderer::getInstance();
$environment = $renderer->getEnvironment();
if (!$environment->hasExtension(StringLoaderExtension::class)) {
Expand All @@ -130,7 +129,6 @@ public function showForm($ID, $options = [])
'current_config' => $current_config,
'impact_engines' => Engine::getAvailableBackends(),
'include_configs' => $include_configs,
'hide_boaviztapi_base_url' => $hide_boaviztapi_base_url,
'action' => (isset($options['plugin_config']) ? Config::getFormURL() : GlpiConfig::getFormURL()),
]);

Expand Down Expand Up @@ -267,12 +265,6 @@ public static function getGeocoder(): Geocoder
*/
public static function getPluginConfigurationValue(string $name): ?string
{
if ($name === 'boaviztapi_base_url') {
$value = getenv(self::ENV_BOAVIZTAPI_BASE_URL);
if ($value !== false) {
return $value;
}
}
return GlpiConfig::getConfigurationValue(self::CONFIG_CONTEXT, $name);
}

Expand Down
8 changes: 4 additions & 4 deletions src/DataSource/Lca/Boaviztapi/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static function getSecuredConfigs(): array
#[Override]
public function getConfigTemplate(): string
{
$hide_boaviztapi_base_url = (getenv(self::ENV_BOAVIZTAPI_BASE_URL) !== false);
$hide_boaviztapi_base_url = defined(self::ENV_BOAVIZTAPI_BASE_URL) && constant(self::ENV_BOAVIZTAPI_BASE_URL) !== null;
$commercial_url = 'https://boavizta.org/';
$twig = <<<TWIG
{% import "components/form/fields_macros.html.twig" as fields %}
Expand Down Expand Up @@ -119,9 +119,9 @@ public function configUpdate(array $input): array

public static function getConfigurationValue(string $name)
{
if ($name === 'boaviztapi_base_url') {
$value = getenv(self::ENV_BOAVIZTAPI_BASE_URL);
if ($value !== false) {
if ($name === 'boaviztapi_base_url' && defined(self::ENV_BOAVIZTAPI_BASE_URL)) {
$value = constant(self::ENV_BOAVIZTAPI_BASE_URL);
if ($value !== null) {
return $value;
}
}
Expand Down
15 changes: 0 additions & 15 deletions tests/units/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,21 +246,6 @@ public function testGetPluginConfigurationValue()
]);
$result = Config::getPluginConfigurationValue('foo');
$this->assertEquals('bar', $result);

// Test an overridable configuration value, not overriden
GlpiConfig::setConfigurationValues('plugin:carbon', [
'boaviztapi_base_url' => 'bar',
]);
$result = Config::getPluginConfigurationValue('boaviztapi_base_url');
$this->assertEquals('bar', $result);

// Test an overridable configuration value, overriden by an env var
GlpiConfig::setConfigurationValues('plugin:carbon', [
'boaviztapi_base_url' => 'baz',
]);
putenv(Config::ENV_BOAVIZTAPI_BASE_URL . '=bar');
$result = Config::getPluginConfigurationValue('boaviztapi_base_url');
$this->assertEquals('bar', $result);
}

public function testSetPluginConfigurationValues()
Expand Down
30 changes: 24 additions & 6 deletions tests/units/DataSource/Lca/Boaviztapi/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function testGetSecuredConfig()
$this->assertSame($expected, $result);
}

public function testGetconfigTemplate()
public function test_getConfigTemplate_returns_full_template_when_boaviztapi_url_is_not_set_by_a_constant()
{
$context = [
'current_config' => [
Expand All @@ -60,7 +60,7 @@ public function testGetconfigTemplate()
];
$this->login('glpi', 'glpi');
$instance = new Config();
putenv(Config::ENV_BOAVIZTAPI_BASE_URL); // Env var unset

$result = $instance->getConfigTemplate();
$renderer = TemplateRenderer::getInstance();
if (!$renderer->getEnvironment()->hasExtension(StringLoaderExtension::class)) {
Expand All @@ -72,9 +72,25 @@ public function testGetconfigTemplate()
$geocoding = $crawler->filter('input[type="checkbox"][name="geocoding_enabled"]');
$this->assertEquals(1, $boaviztapi_url->count());
$this->assertEquals(1, $geocoding->count());
}

public function test_getConfigTemplate_returns_truncated_template_when_boaviztapi_url_is_set_by_a_constant()
{
$context = [
'current_config' => [
'boaviztapi_base_url' => 'foo',
'geocoding_enabled' => true,
],
];
$this->login('glpi', 'glpi');
$instance = new Config();

putenv(Config::ENV_BOAVIZTAPI_BASE_URL . '=bar');
define(Config::ENV_BOAVIZTAPI_BASE_URL, 'bar');
$result = $instance->getConfigTemplate();
$renderer = TemplateRenderer::getInstance();
if (!$renderer->getEnvironment()->hasExtension(StringLoaderExtension::class)) {
$renderer->getEnvironment()->addExtension(new StringLoaderExtension());
}
$result_html = $renderer->renderFromStringTemplate($result, $context);
$crawler = new Crawler($result_html);
$boaviztapi_url = $crawler->filter('input[name="boaviztapi_base_url"]');
Expand Down Expand Up @@ -116,21 +132,23 @@ public function testConfigUpdate(array $input, array $expected)
$this->assertEquals($expected, $result);
}

public function testGetPluginConfigurationValue()
public function test_getPluginConfigurationValue_returns_data_from_config_when_not_overriden()
{
// Test an overridable configuration value, not overriden
GlpiConfig::setConfigurationValues('plugin:carbon', [
'boaviztapi_base_url' => 'bar',
]);
putenv(Config::ENV_BOAVIZTAPI_BASE_URL); // Env var unset
$result = Config::getConfigurationValue('boaviztapi_base_url');
$this->assertEquals('bar', $result);
}

public function test_getPluginConfigurationValue_returns_data_from_config_when_overriden()
{
// Test an overridable configuration value, overriden by an env var
GlpiConfig::setConfigurationValues('plugin:carbon', [
'boaviztapi_base_url' => 'baz',
]);
putenv(Config::ENV_BOAVIZTAPI_BASE_URL . '=bar');
define(Config::ENV_BOAVIZTAPI_BASE_URL, 'bar');
$result = Config::getConfigurationValue('boaviztapi_base_url');
$this->assertEquals('bar', $result);
}
Expand Down