Skip to content

Commit

Permalink
Catalog to extend Adaptable.
Browse files Browse the repository at this point in the history
Removing ununused test methods.
  • Loading branch information
mariuswilms committed Dec 8, 2009
1 parent be5a27f commit 6a3a8ca
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 61 deletions.
39 changes: 6 additions & 33 deletions libraries/lithium/g11n/Catalog.php
Expand Up @@ -27,25 +27,18 @@
*
* The class is able to aggregate data from different sources which allows to complement sparse
* data. Not all categories must be supported by an individual adapter.
*
* @todo Extend \lithium\core\Adaptable.
*/
class Catalog extends \lithium\core\StaticObject {
class Catalog extends \lithium\core\Adaptable {

protected static $_configurations = null;

public static function __init() {
static::$_configurations = new Collection();
}

public static function config($config = null) {
$default = array('adapter' => null, 'scope' => null);
$default = array('scope' => null);

if ($config) {
$items = array_map(function($i) use ($default) { return $i + $default; }, $config);
static::$_configurations = new Collection(compact('items'));
$config = array_map(function($i) use ($default) { return $i + $default; }, $config);
}
return static::$_configurations;
return parent::config($config);
}

/**
Expand Down Expand Up @@ -148,28 +141,8 @@ public static function write($category, $data, $options = array()) {
return false;
}

public static function clear() {
static::__init();
}

public static function _adapter($name = null) {
if (empty($name)) {
$names = static::$_configurations->keys();
if (empty($names)) {
return;
}
$name = end($names);
}
if (!isset(static::$_configurations[$name])) {
return;
}
if (is_string(static::$_configurations[$name]['adapter'])) {
$config = static::$_configurations[$name];
$class = Libraries::locate('adapters.g11n.catalog', $config['adapter']);
$conf = array('adapter' => new $class($config)) + static::$_configurations[$name];
static::$_configurations[$name] = $conf;
}
return static::$_configurations[$name]['adapter'];
public static function adapter($name) {
return static::_adapter('adapters.g11n.catalog', $name);
}
}

Expand Down
28 changes: 4 additions & 24 deletions libraries/lithium/tests/cases/g11n/CatalogTest.php
Expand Up @@ -17,37 +17,17 @@ class CatalogTest extends \lithium\test\Unit {

public function setUp() {
$this->_backups['catalogConfig'] = Catalog::config()->to('array');
Catalog::clear();
Catalog::reset();
Catalog::config(array(
'runtime' => array('adapter' => new Memory())
));
}

public function tearDown() {
Catalog::clear();
Catalog::reset();
Catalog::config($this->_backups['catalogConfig']);
}

/**
* Tests configuration.
*
* @return void
*/
public function testConfig() {}

/**
* Tests if configurations are cleared.
*
* @return void
*/
public function testClear() {
$this->assertTrue(Catalog::config()->count());
Catalog::clear();
$this->assertFalse(Catalog::config()->count());
}

public function testDescribe() {}

/**
* Tests for values returned by `read()`.
*
Expand Down Expand Up @@ -322,7 +302,7 @@ public function testWriteReadWithScope() {
* @return void
*/
public function testWriteReadMergeConfigurations() {
Catalog::clear();
Catalog::reset();
Catalog::config(array(
'runtime0' => array('adapter' => new Memory()),
'runtime1' => array('adapter' => new Memory())
Expand All @@ -343,7 +323,7 @@ public function testWriteReadMergeConfigurations() {
);
$this->assertEqual($expected, $result);

Catalog::clear();
Catalog::reset();
Catalog::config(array(
'runtime0' => array('adapter' => new Memory()),
'runtime1' => array('adapter' => new Memory())
Expand Down
4 changes: 2 additions & 2 deletions libraries/lithium/tests/cases/g11n/MessageTest.php
Expand Up @@ -19,14 +19,14 @@ class MessageTest extends \lithium\test\Unit {

public function setUp() {
$this->_backups['catalogConfig'] = Catalog::config()->to('array');
Catalog::clear();
Catalog::reset();
Catalog::config(array(
'runtime' => array('adapter' => new Memory())
));
}

public function tearDown() {
Catalog::clear();
Catalog::reset();
Catalog::config($this->_backups['catalogConfig']);
}

Expand Down
4 changes: 2 additions & 2 deletions libraries/lithium/tests/cases/template/ViewTest.php
Expand Up @@ -51,7 +51,7 @@ public function testEscapeOutputFilter() {

public function testTranslationOutputFilters() {
$backup = Catalog::config()->to('array');
Catalog::clear();
Catalog::reset();
Catalog::config(array(
'runtime' => array('adapter' => new Memory())
));
Expand Down Expand Up @@ -81,7 +81,7 @@ public function testTranslationOutputFilters() {
$result = $tn('house', 'houses', 3, array('locale' => 'de'));
$this->assertEqual($expected, $result);

Catalog::clear();
Catalog::reset();
Catalog::config($backup);
}
}
Expand Down

0 comments on commit 6a3a8ca

Please sign in to comment.