diff --git a/e107_plugins/social/SocialLoginConfigManager.php b/e107_plugins/social/SocialLoginConfigManager.php index d512af199..b752a30b2 100644 --- a/e107_plugins/social/SocialLoginConfigManager.php +++ b/e107_plugins/social/SocialLoginConfigManager.php @@ -65,7 +65,7 @@ class SocialLoginConfigManager */ public function setProviderConfig($providerName, $options) { - $config = $this->getSocialLoginConfig(); + $config = $this->config->get(self::SOCIAL_LOGIN_PREF); if (!is_array($config)) $this->config->set(self::SOCIAL_LOGIN_PREF, []); self::array_unset_empty_recursive($options); @@ -182,7 +182,10 @@ class SocialLoginConfigManager protected function getSocialLoginConfig() { - return $this->config->get(self::SOCIAL_LOGIN_PREF); + $config = $this->config->get(self::SOCIAL_LOGIN_PREF); + if (!is_array($config)) $config = []; + + return $config; } /** diff --git a/e107_tests/tests/unit/plugins/social/SocialLoginConfigManagerTest.php b/e107_tests/tests/unit/plugins/social/SocialLoginConfigManagerTest.php index 3117c1983..5d3b4adb1 100644 --- a/e107_tests/tests/unit/plugins/social/SocialLoginConfigManagerTest.php +++ b/e107_tests/tests/unit/plugins/social/SocialLoginConfigManagerTest.php @@ -29,7 +29,7 @@ class SocialLoginConfigManagerTest extends \Codeception\Test\Unit include_once(e_PLUGIN . "social/SocialLoginConfigManager.php"); $this->pref = $this->make('e_pref'); - $this->pref->set('social_login', [ + $this->pref->set(SocialLoginConfigManager::SOCIAL_LOGIN_PREF, [ 'Twitter-OAuth1' => [ 'enabled' => true, 'keys' => [ @@ -120,6 +120,18 @@ class SocialLoginConfigManagerTest extends \Codeception\Test\Unit $this->assertEquals(['enabled' => true], $result); } + public function testSetProviderConfigOverwritesNonArray() + { + $this->pref->set(SocialLoginConfigManager::SOCIAL_LOGIN_PREF, 'bad string!'); + $manager = new SocialLoginConfigManager($this->pref); + $expected = ['enabled' => true]; + + $manager->setProviderConfig('FirstProvider', $expected); + $result = $manager->getProviderConfig('FirstProvider'); + + $this->assertEquals($expected, $result); + } + public function testGetProviderConfig() { $result = $this->manager->getProviderConfig('Twitter');