mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge branch '1.2' into 1.3
This commit is contained in:
commit
f1a4352620
8 changed files with 191 additions and 32 deletions
|
@ -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) {
|
||||
|
|
|
@ -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]);
|
||||
}
|
||||
|
|
|
@ -1808,7 +1808,7 @@ class Model extends Overloadable {
|
|||
);
|
||||
|
||||
if (empty($ids)) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($callbacks) {
|
||||
|
|
|
@ -137,7 +137,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'])) {
|
||||
|
@ -146,6 +148,7 @@ class PaginatorHelper extends AppHelper {
|
|||
if (preg_match('/(?:\w+\.)?(\w+)/', $options['order'], $result) && isset($result[1])) {
|
||||
return $result[1];
|
||||
}
|
||||
return $options['order'];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -220,13 +223,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';
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
@ -214,15 +245,6 @@ class ScaffoldViewTest extends CakeTestCase {
|
|||
function tearDown() {
|
||||
unset($this->Controller);
|
||||
}
|
||||
/**
|
||||
* endTest
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function endTest() {
|
||||
App::build();
|
||||
}
|
||||
/**
|
||||
* testGetViewFilename method
|
||||
*
|
||||
|
@ -271,10 +293,12 @@ class ScaffoldViewTest extends CakeTestCase {
|
|||
$expected = 'cake' . DS . 'libs' . DS . 'view' . DS . 'errors' . DS . 'scaffold_error.ctp';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
App::build(array(
|
||||
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
|
||||
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS)
|
||||
));
|
||||
$_back = array(
|
||||
'viewPaths' => Configure::read('viewPaths'),
|
||||
'pluginPaths' => Configure::read('pluginPaths'),
|
||||
);
|
||||
Configure::write('viewPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS));
|
||||
Configure::write('pluginPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS));
|
||||
|
||||
$Controller =& new ScaffoldMockController();
|
||||
$Controller->scaffold = 'admin';
|
||||
|
@ -305,6 +329,8 @@ class ScaffoldViewTest extends CakeTestCase {
|
|||
. DS .'test_plugin' . DS . 'views' . DS . 'tests' . DS . 'scaffold.edit.ctp';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
Configure::write('viewPaths', $_back['viewPaths']);
|
||||
Configure::write('pluginPaths', $_back['pluginPaths']);
|
||||
Configure::write('Routing.admin', $_admin);
|
||||
}
|
||||
/**
|
||||
|
@ -585,5 +611,76 @@ class ScaffoldTest extends CakeTestCase {
|
|||
$result = $Scaffold->getParams();
|
||||
$this->assertEqual($result['action'], 'admin_edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* test that the proper names and variable values are set by Scaffold
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testScaffoldVariableSetting() {
|
||||
$this->Controller->action = 'admin_edit';
|
||||
$this->Controller->here = '/admin/scaffold_mock/edit';
|
||||
$this->Controller->webroot = '/';
|
||||
$params = array(
|
||||
'plugin' => null,
|
||||
'pass' => array(),
|
||||
'form' => array(),
|
||||
'named' => array(),
|
||||
'url' => array('url' =>'admin/scaffold_mock/edit'),
|
||||
'controller' => 'scaffold_mock',
|
||||
'action' => 'admin_edit',
|
||||
'admin' => true,
|
||||
);
|
||||
//set router.
|
||||
Router::setRequestInfo(array($params, array('base' => '/', 'here' => 'admin/scaffold_mock', 'webroot' => '/')));
|
||||
|
||||
$this->Controller->params = $params;
|
||||
$this->Controller->controller = 'scaffold_mock';
|
||||
$this->Controller->base = '/';
|
||||
$this->Controller->constructClasses();
|
||||
$Scaffold =& new TestScaffoldMock($this->Controller, $params);
|
||||
$result = $this->Controller->viewVars;
|
||||
|
||||
$this->assertEqual($result['singularHumanName'], 'Scaffold Mock');
|
||||
$this->assertEqual($result['pluralHumanName'], 'Scaffold Mock');
|
||||
$this->assertEqual($result['modelClass'], 'ScaffoldMock');
|
||||
$this->assertEqual($result['primaryKey'], 'id');
|
||||
$this->assertEqual($result['displayField'], 'title');
|
||||
$this->assertEqual($result['singularVar'], 'scaffoldMock');
|
||||
$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);
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -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
|
||||
|
@ -12969,5 +12972,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);
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -918,5 +918,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);
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Reference in a new issue