Merge pull request #12378 from mma/tests

Fixes #12376 bindTranslation restore fields
This commit is contained in:
Mark Story 2018-07-30 15:05:32 -04:00 committed by GitHub
commit 9f16d2e515
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View file

@ -344,7 +344,7 @@ class TranslateBehavior extends ModelBehavior {
public function afterFind(Model $Model, $results, $primary = false) { public function afterFind(Model $Model, $results, $primary = false) {
$Model->virtualFields = $this->runtime[$Model->alias]['virtualFields']; $Model->virtualFields = $this->runtime[$Model->alias]['virtualFields'];
$this->runtime[$Model->alias]['virtualFields'] = $this->runtime[$Model->alias]['fields'] = array(); $this->runtime[$Model->alias]['virtualFields'] = array();
if (!empty($this->runtime[$Model->alias]['restoreFields'])) { if (!empty($this->runtime[$Model->alias]['restoreFields'])) {
$this->runtime[$Model->alias]['fields'] = $this->runtime[$Model->alias]['restoreFields']; $this->runtime[$Model->alias]['fields'] = $this->runtime[$Model->alias]['restoreFields'];
unset($this->runtime[$Model->alias]['restoreFields']); unset($this->runtime[$Model->alias]['restoreFields']);

View file

@ -1144,6 +1144,16 @@ class TranslateBehaviorTest extends CakeTestCase {
$TestModel->bindTranslation($translations); $TestModel->bindTranslation($translations);
$result = $TestModel->find('first'); $result = $TestModel->find('first');
$TestModel->find('first', array(
'fields' => array(
'TranslatedItem.title',
),
));
$TestModel->find('first', array(
'fields' => array(
'TranslatedItem.title',
),
));
$this->assertArrayHasKey('Title', $result); $this->assertArrayHasKey('Title', $result);
$this->assertArrayHasKey('content', $result['Title'][0]); $this->assertArrayHasKey('content', $result['Title'][0]);
$this->assertArrayNotHasKey('title', $result); $this->assertArrayNotHasKey('title', $result);