mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Merge branch '2.1' into 2.2
Conflicts: lib/Cake/Test/Case/View/XmlViewTest.php
This commit is contained in:
commit
9a8ceaeba6
6 changed files with 91 additions and 15 deletions
|
@ -484,7 +484,8 @@ class TranslateBehavior extends ModelBehavior {
|
||||||
*
|
*
|
||||||
* @param Model $model instance of model
|
* @param Model $model instance of model
|
||||||
* @param string|array $fields string with field or array(field1, field2=>AssocName, field3)
|
* @param string|array $fields string with field or array(field1, field2=>AssocName, field3)
|
||||||
* @param boolean $reset
|
* @param boolean $reset Leave true to have the fields only modified for the next operation.
|
||||||
|
* if false the field will be added for all future queries.
|
||||||
* @return boolean
|
* @return boolean
|
||||||
* @throws CakeException when attempting to bind a translating called name. This is not allowed
|
* @throws CakeException when attempting to bind a translating called name. This is not allowed
|
||||||
* as it shadows Model::$name.
|
* as it shadows Model::$name.
|
||||||
|
@ -511,7 +512,7 @@ class TranslateBehavior extends ModelBehavior {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->_updateSettings($model, $field);
|
$this->_removeField($model, $field);
|
||||||
|
|
||||||
if (is_null($association)) {
|
if (is_null($association)) {
|
||||||
if ($reset) {
|
if ($reset) {
|
||||||
|
@ -553,17 +554,17 @@ class TranslateBehavior extends ModelBehavior {
|
||||||
*
|
*
|
||||||
* @param string $field The field to update.
|
* @param string $field The field to update.
|
||||||
*/
|
*/
|
||||||
protected function _updateSettings(Model $model, $field) {
|
protected function _removeField(Model $model, $field) {
|
||||||
if (array_key_exists($field, $this->settings[$model->alias])) {
|
if (array_key_exists($field, $this->settings[$model->alias])) {
|
||||||
unset($this->settings[$model->alias][$field]);
|
unset($this->settings[$model->alias][$field]);
|
||||||
} elseif (in_array($field, $this->settings[$model->alias])) {
|
} elseif (in_array($field, $this->settings[$model->alias])) {
|
||||||
$this->settings[$model->alias] = array_merge(array_diff_assoc($this->settings[$model->alias], array($field)));
|
$this->settings[$model->alias] = array_merge(array_diff($this->settings[$model->alias], array($field)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists($field, $this->runtime[$model->alias]['fields'])) {
|
if (array_key_exists($field, $this->runtime[$model->alias]['fields'])) {
|
||||||
unset($this->runtime[$model->alias]['fields'][$field]);
|
unset($this->runtime[$model->alias]['fields'][$field]);
|
||||||
} elseif (in_array($field, $this->runtime[$model->alias]['fields'])) {
|
} elseif (in_array($field, $this->runtime[$model->alias]['fields'])) {
|
||||||
$this->runtime[$model->alias]['fields'] = array_merge(array_diff_assoc($this->runtime[$model->alias]['fields'], array($field)));
|
$this->runtime[$model->alias]['fields'] = array_merge(array_diff($this->runtime[$model->alias]['fields'], array($field)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -599,7 +600,7 @@ class TranslateBehavior extends ModelBehavior {
|
||||||
$association = $value;
|
$association = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->_updateSettings($model, $field);
|
$this->_removeField($model, $field);
|
||||||
|
|
||||||
if (!is_null($association) && (isset($model->hasMany[$association]) || isset($model->__backAssociation['hasMany'][$association]))) {
|
if (!is_null($association) && (isset($model->hasMany[$association]) || isset($model->__backAssociation['hasMany'][$association]))) {
|
||||||
$associations[] = $association;
|
$associations[] = $association;
|
||||||
|
|
|
@ -1006,4 +1006,28 @@ class TranslateBehaviorTest extends CakeTestCase {
|
||||||
$TestModel = new TranslatedItem();
|
$TestModel = new TranslatedItem();
|
||||||
$TestModel->bindTranslation(array('name' => 'name'));
|
$TestModel->bindTranslation(array('name' => 'name'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that translations can be bound and unbound dynamically.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testUnbindTranslation() {
|
||||||
|
$this->loadFixtures('Translate', 'TranslatedItem');
|
||||||
|
$Model = new TranslatedItem();
|
||||||
|
$Model->unbindTranslation();
|
||||||
|
$Model->bindTranslation(array('body', 'slug'), false);
|
||||||
|
|
||||||
|
$result = $Model->Behaviors->Translate->settings['TranslatedItem'];
|
||||||
|
$this->assertEquals(array('body', 'slug'), $result);
|
||||||
|
|
||||||
|
$Model->unbindTranslation(array('body'));
|
||||||
|
$result = $Model->Behaviors->Translate->settings['TranslatedItem'];
|
||||||
|
$this->assertNotContains('body', $result);
|
||||||
|
|
||||||
|
$Model->unbindTranslation('slug');
|
||||||
|
$result = $Model->Behaviors->Translate->settings['TranslatedItem'];
|
||||||
|
$this->assertNotContains('slug', $result);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1344,6 +1344,33 @@ class SetTest extends CakeTestCase {
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that extract() + matching can hit null things.
|
||||||
|
*/
|
||||||
|
public function testExtractMatchesNull() {
|
||||||
|
$data = array(
|
||||||
|
'Country' => array(
|
||||||
|
array('name' => 'Canada'),
|
||||||
|
array('name' => 'Australia'),
|
||||||
|
array('name' => null),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$result = Set::extract('/Country[name=/Canada|^$/]', $data);
|
||||||
|
$expected = array(
|
||||||
|
array(
|
||||||
|
'Country' => array(
|
||||||
|
'name' => 'Canada',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'Country' => array(
|
||||||
|
'name' => null,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$this->assertEquals($expected, $result);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testMatches method
|
* testMatches method
|
||||||
*
|
*
|
||||||
|
|
|
@ -43,9 +43,27 @@ class XmlViewTest extends CakeTestCase {
|
||||||
$View = new XmlView($Controller);
|
$View = new XmlView($Controller);
|
||||||
$output = $View->render(false);
|
$output = $View->render(false);
|
||||||
|
|
||||||
$expected = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<users><user>user1</user><user>user2</user></users>';
|
$this->assertSame(Xml::build($data)->asXML(), $output);
|
||||||
$this->assertTextEquals($expected, trim($output));
|
|
||||||
$this->assertSame('application/xml', $Response->type());
|
$this->assertSame('application/xml', $Response->type());
|
||||||
|
|
||||||
|
$data = array(
|
||||||
|
array(
|
||||||
|
'User' => array(
|
||||||
|
'username' => 'user1'
|
||||||
|
)
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'User' => array(
|
||||||
|
'username' => 'user2'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$Controller->set(array('users' => $data, '_serialize' => 'users'));
|
||||||
|
$View = new XmlView($Controller);
|
||||||
|
$output = $View->render(false);
|
||||||
|
|
||||||
|
$expected = Xml::build(array('response'=> array('users'=> $data)))->asXML();
|
||||||
|
$this->assertSame($expected, $output);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -100,8 +118,11 @@ class XmlViewTest extends CakeTestCase {
|
||||||
$View = new XmlView($Controller);
|
$View = new XmlView($Controller);
|
||||||
$output = $View->render('index');
|
$output = $View->render('index');
|
||||||
|
|
||||||
$expected = '<?xml version="1.0" encoding="UTF-8"?><users><user>user1</user><user>user2</user></users>';
|
$expected = array(
|
||||||
$this->assertSame($expected, str_replace(array("\r", "\n"), '', $output));
|
'users'=> array('user'=> array('user1', 'user2'))
|
||||||
|
);
|
||||||
|
$expected = Xml::build($expected)->asXML();
|
||||||
|
$this->assertSame($expected, $output);
|
||||||
$this->assertSame('application/xml', $Response->type());
|
$this->assertSame('application/xml', $Response->type());
|
||||||
$this->assertInstanceOf('HelperCollection', $View->Helpers);
|
$this->assertInstanceOf('HelperCollection', $View->Helpers);
|
||||||
}
|
}
|
||||||
|
|
|
@ -494,7 +494,7 @@ class Set {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
list(, $key, $op, $expected) = $match;
|
list(, $key, $op, $expected) = $match;
|
||||||
if (!isset($data[$key])) {
|
if (!(isset($data[$key]) || array_key_exists($key, $data))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,6 +93,9 @@ class XmlView extends View {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$data = isset($this->viewVars[$serialize]) ? $this->viewVars[$serialize] : null;
|
$data = isset($this->viewVars[$serialize]) ? $this->viewVars[$serialize] : null;
|
||||||
|
if (is_array($data) && Set::numeric(array_keys($data))) {
|
||||||
|
$data = array('response' => array($serialize => $data));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$content = Xml::fromArray($data)->asXML();
|
$content = Xml::fromArray($data)->asXML();
|
||||||
$this->Blocks->set('content', $content);
|
$this->Blocks->set('content', $content);
|
||||||
|
|
Loading…
Reference in a new issue