public function testShiftTwo() { $request = new Request(); $request->params = array('command' => 'one', 'action' => 'two', 'args' => array('three', 'four', 'five')); $request->shift(2); $expected = array('command' => 'three', 'action' => 'four', 'args' => array('five')); $result = $request->params; $this->assertEqual($expected, $result); }
/** * Detects preferred locales from a console request by looking at certain * environment variables. The environment variables may be present or not * depending on your system. If multiple variables are present the following * hierarchy is used: `'LANGUAGE'`, `'LC_ALL'`, `'LANG'`. * * The locales of the `'LC_ALL'` and the `'LANG'` are formatted according * to the posix standard: `language(_territory)(.encoding)(@modifier)`. * Locales having such a format are automatically canonicalized and transformed * into the `Locale` class' format. * * @link http://www.linux.com/archive/feature/53781 * @param \lithium\console\Request $request * @return array Preferred locales in their canonical form (i.e. `'fr_CA'`). */ protected static function _preferredConsole($request) { $regex = '(?P<locale>[\\w\\_]+)(\\.|@|$)+'; $result = array(); if ($value = $request->env('LANGUAGE')) { return explode(':', $value); } foreach (array('LC_ALL', 'LANG') as $variable) { $value = $request->env($variable); if (!$value || $value === 'C' || $value === 'POSIX') { continue; } if (preg_match("/{$regex}/", $value, $matches)) { return (array) $matches['locale']; } } return $result; }