Merge branch 'local/svn/1.2.x.x' into 1.2

This commit is contained in:
gwoo 2009-07-03 08:22:43 -07:00
commit ea6a80d419
8 changed files with 144 additions and 19 deletions

View file

@ -263,8 +263,8 @@ class AuthComponent extends Object {
*/
function startup(&$controller) {
$methods = array_flip($controller->methods);
$controllerAction = strtolower($controller->params['action']);
$lowerAllowedActions = array_map('strtolower', $this->allowedActions);
$action = strtolower($controller->params['action']);
$allowedActions = array_map('strtolower', $this->allowedActions);
$isErrorOrTests = (
strtolower($controller->name) == 'cakeerror' ||
@ -276,7 +276,7 @@ class AuthComponent extends Object {
$isMissingAction = (
$controller->scaffold === false &&
!isset($methods[$controllerAction])
!isset($methods[$action])
);
if ($isMissingAction) {
@ -298,7 +298,7 @@ class AuthComponent extends Object {
$isAllowed = (
$this->allowedActions == array('*') ||
in_array($controllerAction, $lowerAllowedActions)
in_array($action, $allowedActions)
);
if ($loginAction != $url && $isAllowed) {

View file

@ -858,11 +858,8 @@ class DboSource extends DataSource {
foreach ($fetch as $j => $data) {
if (
(isset($data[$with]) && $data[$with][$foreignKey] === $row[$model->alias][$model->primaryKey]) &&
(!in_array($data[$with][$joinKeys[1]], $uniqueIds))
(isset($data[$with]) && $data[$with][$foreignKey] === $row[$model->alias][$model->primaryKey])
) {
$uniqueIds[] = $data[$with][$joinKeys[1]];
if ($habtmFieldsCount <= 2) {
unset($data[$with]);
}

View file

@ -1811,7 +1811,7 @@ class Model extends Overloadable {
);
if (empty($ids)) {
return false;
return true;
}
if ($callbacks) {

View file

@ -140,7 +140,9 @@ class PaginatorHelper extends AppHelper {
if (isset($options['sort']) && !empty($options['sort'])) {
if (preg_match('/(?:\w+\.)?(\w+)/', $options['sort'], $result) && isset($result[1])) {
return $result[1];
if ($result[0] == $this->defaultModel()) {
return $result[1];
}
}
return $options['sort'];
} elseif (isset($options['order']) && is_array($options['order'])) {
@ -149,6 +151,7 @@ class PaginatorHelper extends AppHelper {
if (preg_match('/(?:\w+\.)?(\w+)/', $options['order'], $result) && isset($result[1])) {
return $result[1];
}
return $options['order'];
}
return null;
}
@ -223,13 +226,7 @@ class PaginatorHelper extends AppHelper {
}
$dir = 'asc';
$sortKey = $this->sortKey($options['model']);
$defaultModel = $this->defaultModel();
if (strpos($sortKey, $defaultModel) !== false && strpos($key, $defaultModel) === false) {
$isSorted = ($sortKey === $defaultModel . '.' . $key);
} else {
$isSorted = ($sortKey === $key);
}
$isSorted = ($sortKey === $key);
if ($isSorted && $this->sortDir($options['model']) === 'asc') {
$dir = 'desc';

View file

@ -25,7 +25,7 @@
<div class="<?php echo $pluralVar;?> form">
<?php
echo $form->create();
echo $form->inputs(null, array('created', 'modified', 'updated'));
echo $form->inputs($scaffoldFields, array('created', 'modified', 'updated'));
echo $form->end(__('Submit', true));
?>
</div>

View file

@ -47,6 +47,37 @@ class ScaffoldMockController extends Controller {
*/
var $scaffold;
}
/**
* ScaffoldMockControllerWithFields class
*
* @package cake
* @subpackage cake.tests.cases.libs.controller
*/
class ScaffoldMockControllerWithFields extends Controller {
/**
* name property
*
* @var string 'ScaffoldMock'
* @access public
*/
var $name = 'ScaffoldMock';
/**
* scaffold property
*
* @var mixed
* @access public
*/
var $scaffold;
/**
* function _beforeScaffold
*
* @param string method
*/
function _beforeScaffold($method) {
$this->set('scaffoldFields', array('title'));
return true;
}
}
/**
* TestScaffoldMock class
*
@ -619,5 +650,37 @@ class ScaffoldTest extends CakeTestCase {
$this->assertEqual($result['pluralVar'], 'scaffoldMock');
$this->assertEqual($result['scaffoldFields'], array('id', 'user_id', 'title', 'body', 'published', 'created', 'updated'));
}
/**
* test that the proper names and variable values are set by Scaffold
*
* @return void
**/
function testEditScaffoldWithScaffoldFields() {
$this->Controller = new ScaffoldMockControllerWithFields();
$this->Controller->action = 'edit';
$this->Controller->here = '/scaffold_mock';
$this->Controller->webroot = '/';
$params = array(
'plugin' => null,
'pass' => array(1),
'form' => array(),
'named' => array(),
'url' => array('url' =>'scaffold_mock'),
'controller' => 'scaffold_mock',
'action' => 'edit',
);
//set router.
Router::reload();
Router::setRequestInfo(array($params, array('base' => '/', 'here' => '/scaffold_mock', 'webroot' => '/')));
$this->Controller->params = $params;
$this->Controller->controller = 'scaffold_mock';
$this->Controller->base = '/';
$this->Controller->constructClasses();
ob_start();
new Scaffold($this->Controller, $params);
$result = ob_get_clean();
$this->assertNoPattern('/textarea name="data\[ScaffoldMock\]\[body\]" cols="30" rows="6" id="ScaffoldMockBody"/', $result);
}
}
?>

View file

@ -7487,6 +7487,9 @@ class ModelTest extends CakeTestCase {
'published' => 'Y'
)));
$this->assertEqual($result, $expected);
$result = $TestModel->deleteAll(array('Article.user_id' => 999));
$this->assertTrue($result, 'deleteAll returned false when all no records matched conditions. %s');
}
/**
* testRecursiveDel method
@ -13019,5 +13022,42 @@ class ModelTest extends CakeTestCase {
$TestModel2 =& new ArticleB();
$this->assertEqual($TestModel2->ArticlesTag->primaryKey, 'article_id');
}
/**
* testFetchingNonUniqueFKJoinTableRecords()
*
* Tests if the results are properly returned in the case there are non-unique FK's
* in the join table but another fields value is different. For example:
* something_id | something_else_id | doomed = 1
* something_id | something_else_id | doomed = 0
* Should return both records and not just one.
*
* @access public
* @return void
*/
function testFetchingNonUniqueFKJoinTableRecords() {
$this->loadFixtures('Something', 'SomethingElse', 'JoinThing');
$Something = new Something();
$joinThingData = array(
'JoinThing' => array(
'something_id' => 1,
'something_else_id' => 2,
'doomed' => '0',
'created' => '2007-03-18 10:39:23',
'updated' => '2007-03-18 10:41:31'
)
);
$Something->JoinThing->create($joinThingData);
$Something->JoinThing->save();
$result = $Something->JoinThing->find('all', array('conditions' => array('something_else_id' => 2)));
$this->assertEqual($result[0]['JoinThing']['doomed'], 1);
$this->assertEqual($result[1]['JoinThing']['doomed'], 0);
$result = $Something->find('first');
$this->assertEqual(count($result['SomethingElse']), 2);
$this->assertEqual($result['SomethingElse'][0]['JoinThing']['doomed'], 1);
$this->assertEqual($result['SomethingElse'][1]['JoinThing']['doomed'], 0);
}
}
?>

View file

@ -911,5 +911,33 @@ class PaginatorHelperTest extends CakeTestCase {
$result = $this->Paginator->link('Page 3', array('page' => 3));
$this->assertPattern('/["\']\/issues\/index\/page:3["\']/', $result);
}
/**
* testNextLinkUsingDotNotation method
*
* @access public
* @return void
*/
function testNextLinkUsingDotNotation() {
Router::reload();
Router::parse('/');
Router::setRequestInfo(array(
array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'form' => array(), 'url' => array('url' => 'accounts/', 'mod_rewrite' => 'true'), 'bare' => 0),
array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/', 'passedArgs' => array())
));
$this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
$this->Paginator->params['paging']['Article']['page'] = 1;
$test = array('url'=> array(
'page'=> '1',
'sort'=>'Article.title',
'direction'=>'asc',
));
$this->Paginator->options($test);
$result = $this->Paginator->next('Next');
$this->assertPattern('/\/accounts\/index\/page:2\/sort:Article.title\/direction:asc">Next<\/a>$/', $result);
}
}
?>