Merge branch '1.2' of github.com:cakephp/cakephp1x into 1.2

This commit is contained in:
Mark Story 2010-03-10 21:49:55 -05:00
commit 239e34f032
17 changed files with 152 additions and 17 deletions

View file

@ -665,6 +665,7 @@ class ModelTask extends Shell {
}
$out .= "}\n";
$out .= "?>";
ClassRegistry::flush();
$filename = $this->path . Inflector::underscore($name) . '.php';
$this->out("\nBaking model class for $name...");
return $this->createFile($filename, $out);

View file

@ -473,7 +473,7 @@ class Folder extends Object {
}
}
}
return true;
return false;
}
/**
* Returns the size in bytes of this Folder.

View file

@ -294,7 +294,7 @@ class L10n extends Object {
'sq' => array('language' => 'Albanian', 'locale' => 'alb', 'localeFallback' => 'alb', 'charset' => 'utf-8'),
'sr' => array('language' => 'Serbian', 'locale' => 'scc', 'localeFallback' => 'scc', 'charset' => 'utf-8'),
'sv' => array('language' => 'Swedish', 'locale' => 'swe', 'localeFallback' => 'swe', 'charset' => 'utf-8'),
'sv-fi' => array('language' => 'Swedish (Findland)', 'locale' => 'sv_fi', 'localeFallback' => 'swe', 'charset' => 'utf-8'),
'sv-fi' => array('language' => 'Swedish (Finland)', 'locale' => 'sv_fi', 'localeFallback' => 'swe', 'charset' => 'utf-8'),
'sx' => array('language' => 'Sutu', 'locale' => 'sx', 'localeFallback' => 'sx', 'charset' => 'utf-8'),
'sz' => array('language' => 'Sami (Lappish)', 'locale' => 'smi', 'localeFallback' => 'smi', 'charset' => 'utf-8'),
'th' => array('language' => 'Thai', 'locale' => 'tha', 'localeFallback' => 'tha', 'charset' => 'utf-8'),

View file

@ -99,6 +99,13 @@ class DboMssql extends DboSource {
'commit' => 'COMMIT',
'rollback' => 'ROLLBACK'
);
/**
* Define if the last query had error
*
* @var string
* @access private
*/
var $__lastQueryHadError = false;
/**
* MS SQL DBO driver constructor; sets SQL Server error reporting defaults
*
@ -177,7 +184,9 @@ class DboMssql extends DboSource {
* @access protected
*/
function _execute($sql) {
return mssql_query($sql, $this->connection);
$result = @mssql_query($sql, $this->connection);
$this->__lastQueryHadError = ($result === false);
return $result;
}
/**
* Returns an array of sources (tables) in the database.
@ -411,10 +420,9 @@ class DboMssql extends DboSource {
* @return string Error message with error number
*/
function lastError() {
$error = mssql_get_last_message();
if ($error) {
if (!preg_match('/contexto de la base de datos a|contesto di database|changed database|contexte de la base de don|datenbankkontext/i', $error)) {
if ($this->__lastQueryHadError) {
$error = mssql_get_last_message();
if ($error && !preg_match('/contexto de la base de datos a|contesto di database|changed database|contexte de la base de don|datenbankkontext/i', $error)) {
return $error;
}
}

View file

@ -380,12 +380,12 @@ class DboSource extends DataSource {
* @return string SQL field
*/
function name($data) {
if ($data == '*') {
return '*';
}
if (is_object($data) && isset($data->type)) {
return $data->value;
}
if ($data == '*') {
return '*';
}
$array = is_array($data);
$data = (array)$data;
$count = count($data);

View file

@ -947,6 +947,9 @@ class Set extends Object {
} else {
$keys = Set::extract($data, $path1);
}
if (empty($keys)) {
return array();
}
if (!empty($path2) && is_array($path2)) {
$format = array_shift($path2);
@ -978,7 +981,9 @@ class Set extends Object {
return $out;
}
}
if (empty($vals)) {
return array();
}
return array_combine($keys, $vals);
}
/**

View file

@ -212,6 +212,7 @@ class AjaxHelper extends AppHelper {
unset($confirm);
}
$htmlOptions = $this->__getHtmlOptions($options, array('url'));
$options += array('safe' => true);
if (empty($options['fallback']) || !isset($options['fallback'])) {
$options['fallback'] = $href;
@ -257,7 +258,14 @@ class AjaxHelper extends AppHelper {
$func = "new Ajax.Request(";
}
$func .= "'" . $this->url(isset($options['url']) ? $options['url'] : "") . "'";
$url = isset($options['url']) ? $options['url'] : "";
if (empty($options['safe'])) {
$url = $this->url($url);
} else {
$url = Router::url($url);
}
$func .= "'" . $url . "'";
$func .= ", " . $this->__optionsForAjax($options) . ")";
if (isset($options['before'])) {

View file

@ -1097,11 +1097,17 @@ class FormHelper extends AppHelper {
/**
* Creates a submit button element.
*
* ### Options
*
* - `div` - Include a wrapping div? Defaults to true. Accepts sub options similar to
* FormHelper::input().
* - Other attributes will be assigned to the input element.
*
* @param string $caption The label appearing on the button OR if string contains :// or the
* extension .jpg, .jpe, .jpeg, .gif, .png use an image if the extension
* exists, AND the first character is /, image is relative to webroot,
* OR if the first character is not /, image is relative to webroot/img.
* @param array $options
* @param array $options Array of options. See above.
* @return string A HTML submit button
*/
function submit($caption = null, $options = array()) {

View file

@ -237,7 +237,7 @@ class HtmlHelper extends AppHelper {
}
$out .= sprintf($this->tags['metalink'], $attributes['link'], $this->_parseAttributes($attributes, array('link'), ' ', ' '));
} else {
$out = sprintf($this->tags['meta'], $this->_parseAttributes($attributes, array('type')));
$out = sprintf($this->tags['meta'], $this->_parseAttributes($attributes, array('type'), ' ', ' '));
}
if ($inline) {

View file

@ -632,7 +632,10 @@ class JavascriptHelper extends AppHelper {
foreach ($data as $key => $val) {
if (is_array($val) || is_object($val)) {
$val = $this->object($val, array_merge($options, array('block' => false)));
$val = $this->object(
$val,
array_merge($options, array('block' => false, 'prefix' => '', 'postfix' => ''))
);
} else {
$quoteStrings = (
!count($options['stringKeys']) ||

View file

@ -43,7 +43,7 @@ Mock::generatePartial(
);
Mock::generatePartial(
'ModelTask', 'MockModelTask',
array('in', 'out', 'createFile')
array('in', 'out', 'createFile', '_checkUnitTest')
);
/**
* ModelTaskTest class
@ -52,7 +52,7 @@ Mock::generatePartial(
* @subpackage cake.tests.cases.console.libs.tasks
*/
class ModelTaskTest extends CakeTestCase {
var $fixtures = array('core.datatype', 'core.binary_test');
var $fixtures = array('core.datatype', 'core.binary_test', 'core.article');
/**
* setUp method
*
@ -87,5 +87,23 @@ class ModelTaskTest extends CakeTestCase {
$result = $this->Task->fixture('BinaryTest');
$this->assertPattern("/'data' => 'Lorem ipsum dolor sit amet'/", $result);
}
/**
* test that execute passes runs bake depending with named model.
*
* @return void
* @access public
*/
function testBakeModel() {
$this->Task->connection = 'test_suite';
$this->Task->path = '/my/path/';
$filename = '/my/path/article.php';
$this->Task->setReturnValue('_checkUnitTest', 1);
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class Article extends AppModel/')));
$model =& new Model(array('name' => 'Article', 'table' => 'articles', 'ds' => 'test_suite'));
$this->Task->bake($model);
$this->assertEqual(count(ClassRegistry::keys()), 0);
$this->assertEqual(count(ClassRegistry::mapKeys()), 0);
}
}
?>

View file

@ -82,6 +82,48 @@ class FolderTest extends CakeTestCase {
$result = $Folder->inPath(DS . 'non-existing' . $inside);
$this->assertFalse($result);
}
/**
* test creation of single and mulitple paths.
*
* @return void
*/
function testCreation() {
$folder =& new Folder(TMP . 'tests');
$result = $folder->create(TMP . 'tests' . DS . 'first' . DS . 'second' . DS . 'third');
$this->assertTrue($result);
rmdir(TMP . 'tests' . DS . 'first' . DS . 'second' . DS . 'third');
rmdir(TMP . 'tests' . DS . 'first' . DS . 'second');
rmdir(TMP . 'tests' . DS . 'first');
$folder =& new Folder(TMP . 'tests');
$result = $folder->create(TMP . 'tests' . DS . 'first');
$this->assertTrue($result);
rmdir(TMP . 'tests' . DS . 'first');
}
/**
* test recurisve directory create failure.
*
* @return void
*/
function testRecursiveCreateFailure() {
if ($this->skipIf(DS == '\\', 'Cant perform operations using permissions on windows. %s')) {
return;
}
$path = TMP . 'tests' . DS . 'one';
mkdir($path);
chmod($path, '0444');
$this->expectError();
$folder =& new Folder($path);
$result = $folder->create($path . DS . 'two' . DS . 'three');
$this->assertFalse($result);
chmod($path, '0777');
rmdir($path);
}
/**
* testOperations method
*

View file

@ -627,5 +627,30 @@ class DboMssqlTest extends CakeTestCase {
);
$this->assertEqual($result, $expected);
}
/**
* testLastError
*
* @return void
* @access public
*/
function testLastError() {
$debug = Configure::read('debug');
Configure::write('debug', 0);
$this->db->simulate = false;
$query = 'SELECT [name] FROM [categories]';
$this->assertTrue($this->db->execute($query) !== false);
$this->assertNull($this->db->lastError());
$query = 'SELECT [inexistent_field] FROM [categories]';
$this->assertFalse($this->db->execute($query));
$this->assertNotNull($this->db->lastError());
$query = 'SELECT [name] FROM [categories]';
$this->assertTrue($this->db->execute($query) !== false);
$this->assertNull($this->db->lastError());
Configure::write('debug', $debug);
}
}
?>

View file

@ -1621,6 +1621,9 @@ class SetTest extends CakeTestCase {
$result = Set::combine($b, 'users.{n}.User.id', 'users.{n}.User.non-existant');
$expected = array(2 => null, 14 => null, 25 => null);
$this->assertIdentical($result, $expected);
$result = Set::combine($a, 'fail', 'fail');
$this->assertEqual($result, array());
}
/**
* testMapReverse method

View file

@ -557,6 +557,13 @@ class AjaxHelperTest extends CakeTestCase {
$this->assertPattern("/Event.observe\('link[0-9]+', [\w\d,'\(\)\s{}]+Ajax\.Request\([\w\d\s,'\(\){}:\/]+onComplete:function\(request, json\) {test}/", $result);
$this->assertNoPattern('/^<a[^<>]+complete="test"[^<>]*>Ajax Link<\/a>/', $result);
$this->assertNoPattern('/^<a\s+[^<>]*url="[^"]*"[^<>]*>/', $result);
$result = $this->Ajax->link(
'Ajax Link',
array('controller' => 'posts', 'action' => 'index', '?' => array('one' => '1', 'two' => '2')),
array('update' => 'myDiv', 'id' => 'myLink')
);
$this->assertPattern('#/posts/\?one\=1\&two\=2#', $result);
}
/**
* testRemoteTimer method

View file

@ -844,6 +844,8 @@ class HtmlHelperTest extends CakeTestCase {
$result = $this->Html->meta('keywords', 'these, are, some, meta, keywords');
$this->assertTags($result, array('meta' => array('name' => 'keywords', 'content' => 'these, are, some, meta, keywords')));
$this->assertPattern('/\s+\/>$/', $result);
$result = $this->Html->meta('description', 'this is the meta description');
$this->assertTags($result, array('meta' => array('name' => 'description', 'content' => 'this is the meta description')));

View file

@ -392,6 +392,13 @@ class JavascriptTest extends CakeTestCase {
$result = $this->Javascript->object($data);
$this->assertEqual($result, $expected);
}
$object = array('title' => 'New thing', 'indexes' => array(5, 6, 7, 8), 'object' => array('inner' => array('value' => 1)));
$result = $this->Javascript->object($object, array('prefix' => 'PREFIX', 'postfix' => 'POSTFIX'));
$this->assertPattern('/^PREFIX/', $result);
$this->assertPattern('/POSTFIX$/', $result);
$this->assertNoPattern('/.PREFIX./', $result);
$this->assertNoPattern('/.POSTFIX./', $result);
if ($this->Javascript->useNative) {
$this->Javascript->useNative = false;