diff --git a/lib/classes/User/Adapter.php b/lib/classes/User/Adapter.php index 7e28331559..417282679b 100644 --- a/lib/classes/User/Adapter.php +++ b/lib/classes/User/Adapter.php @@ -1334,11 +1334,27 @@ class User_Adapter implements User_Interface, cache_cacheableInterface } } + if (isset($this->app['phraseanet.configuration']['user-settings'])) { + $this->_prefs = array_replace( + $this->_prefs, + // remove keys that are not defined in default values + array_intersect_key( + $this->app['phraseanet.configuration']['user-settings'], + self::$def_values + ) + ); + } + $this->preferences_loaded = true; return $this; } + public function purgePreferences() + { + $this->notifications_preferences_loaded = $this->preferences_loaded = false; + } + protected function load_notifications_preferences(Application $app) { $this->load_preferences(); @@ -1352,7 +1368,7 @@ class User_Adapter implements User_Interface, cache_cacheableInterface } } } - $this->notification_preferences_loaded = true; + $this->notifications_preferences_loaded = true; } public function get_notifications_preference(Application $app, $notification_id) diff --git a/tests/classes/PhraseanetPHPUnitAbstract.php b/tests/classes/PhraseanetPHPUnitAbstract.php index d52993041a..bfbd6f5d73 100644 --- a/tests/classes/PhraseanetPHPUnitAbstract.php +++ b/tests/classes/PhraseanetPHPUnitAbstract.php @@ -201,6 +201,7 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase return new Client($DI['app'], array()); }); + self::$DI['user']->purgePreferences(); } public function tearDown() diff --git a/tests/classes/userTest.php b/tests/classes/userTest.php index d2625ecd06..eb747973c7 100644 --- a/tests/classes/userTest.php +++ b/tests/classes/userTest.php @@ -58,6 +58,30 @@ class userTest extends PhraseanetPHPUnitAbstract $this->assertSame(\User_Adapter::$def_values['editing_top_box'], $user->getPrefs('editing_top_box')); } + public function testGetPrefWithACustomizedConf() + { + $data = isset(self::$DI['app']['phraseanet.configuration']['user-settings']) ? self::$DI['app']['phraseanet.configuration']['user-settings'] : null; + + self::$DI['app']['phraseanet.configuration']['user-settings'] = array( + 'images_per_page' => 42, + 'images_size' => 666, + 'lalala' => 'didou', + ); + + $user = $this->get_user(); + + $this->assertNull($user->getPrefs('lalala')); + $this->assertSame(666, $user->getPrefs('images_size')); + $this->assertSame(42, $user->getPrefs('images_per_page')); + $this->assertSame(\User_Adapter::$def_values['editing_top_box'], $user->getPrefs('editing_top_box')); + + if (null === $data) { + unset(self::$DI['app']['phraseanet.configuration']['user-settings']); + } else { + self::$DI['app']['phraseanet.configuration']['user-settings'] = $data; + } + } + public function testSetPref() { $user = $this->get_user();