Merge branch '2.1' into 2.2

Conflicts:
	lib/Cake/Test/Case/View/XmlViewTest.php
This commit is contained in:
mark_story 2012-05-30 21:20:56 -04:00
commit 9a8ceaeba6
6 changed files with 91 additions and 15 deletions

View file

@ -484,7 +484,8 @@ class TranslateBehavior extends ModelBehavior {
*
* @param Model $model instance of model
* @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
* @throws CakeException when attempting to bind a translating called name. This is not allowed
* 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 ($reset) {
@ -553,17 +554,17 @@ class TranslateBehavior extends ModelBehavior {
*
* @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])) {
unset($this->settings[$model->alias][$field]);
} 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'])) {
unset($this->runtime[$model->alias]['fields'][$field]);
} 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;
}
$this->_updateSettings($model, $field);
$this->_removeField($model, $field);
if (!is_null($association) && (isset($model->hasMany[$association]) || isset($model->__backAssociation['hasMany'][$association]))) {
$associations[] = $association;

View file

@ -1006,4 +1006,28 @@ class TranslateBehaviorTest extends CakeTestCase {
$TestModel = new TranslatedItem();
$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);
}
}

View file

@ -1344,6 +1344,33 @@ class SetTest extends CakeTestCase {
$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
*

View file

@ -43,9 +43,27 @@ class XmlViewTest extends CakeTestCase {
$View = new XmlView($Controller);
$output = $View->render(false);
$expected = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<users><user>user1</user><user>user2</user></users>';
$this->assertTextEquals($expected, trim($output));
$this->assertSame(Xml::build($data)->asXML(), $output);
$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);
$output = $View->render('index');
$expected = '<?xml version="1.0" encoding="UTF-8"?><users><user>user1</user><user>user2</user></users>';
$this->assertSame($expected, str_replace(array("\r", "\n"), '', $output));
$expected = array(
'users'=> array('user'=> array('user1', 'user2'))
);
$expected = Xml::build($expected)->asXML();
$this->assertSame($expected, $output);
$this->assertSame('application/xml', $Response->type());
$this->assertInstanceOf('HelperCollection', $View->Helpers);
}

View file

@ -494,7 +494,7 @@ class Set {
continue;
}
list(, $key, $op, $expected) = $match;
if (!isset($data[$key])) {
if (!(isset($data[$key]) || array_key_exists($key, $data))) {
return false;
}

View file

@ -93,6 +93,9 @@ class XmlView extends View {
}
} else {
$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();
$this->Blocks->set('content', $content);