Skip to content

Commit

Permalink
Merge pull request #1 from sreichel/get_config_value
Browse files Browse the repository at this point in the history
Update PR
  • Loading branch information
kiatng committed Aug 27, 2024
2 parents 17999d4 + eb00f5c commit 85f6101
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
15 changes: 15 additions & 0 deletions app/code/core/Mage/Core/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -1698,6 +1698,21 @@ public function deleteConfig($path, $scope = 'default', $scopeId = 0)
return $this;
}


/**
* Get config value from DB
*
* @param string $path
* @param string $scope
* @param int $scopeId
* @return string|false
*/
public function getConfig(string $path, string $scope = 'default', int $scopeId = 0)
{
$resource = $this->getResourceModel();
return $resource->getConfig(rtrim($path, '/'), $scope, $scopeId);
}

/**
* Get fieldset from configuration
*
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Model/Resource/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public function deleteConfig($path, $scope, $scopeId)
* @param int $scopeId
* @return string|false
*/
public function getValue(string $path, string $scope = 'default', int $scopeId = 0)
public function getConfig(string $path, string $scope, int $scopeId)
{
$readAdapter = $this->_getReadAdapter();
$select = $readAdapter->select()
Expand Down
37 changes: 37 additions & 0 deletions dev/tests/unit/Mage/Core/Model/ConfigTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace OpenMage\Tests\Unit\Mage\Core\Model;

use Mage;
use Mage_Core_Model_Config;
use PHPUnit\Framework\TestCase;

class ConfigTest extends TestCase
{
/**
* @var Mage_Core_Model_Config
*/
public Mage_Core_Model_Config $subject;

public function setUp(): void
{
Mage::app();
$this->subject = Mage::getModel('core/config');
}

public function testSaveDeleteGetConfig(): void
{
$path = 'test/config';
$value = 'foo';

$this->assertFalse($this->subject->getConfig($path));

$this->subject->saveConfig($path, $value);
$this->assertEquals($value, $this->subject->getConfig($path));

$this->subject->deleteConfig($path);
$this->assertFalse($this->subject->getConfig($path));
}
}

0 comments on commit 85f6101

Please sign in to comment.