From 775707838ef7a354b33f6b0b3b83089c2370786f Mon Sep 17 00:00:00 2001 From: "mariano.iglesias" Date: Mon, 19 May 2008 02:40:13 +0000 Subject: [PATCH] Fixing docbloc in Containable, fixing issue where no notices and invalid bindings were throwing PHP warnings, added tests, fixes #4683 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6938 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/behaviors/containable.php | 8 +++++--- .../tests/cases/libs/model/behaviors/containable.test.php | 8 ++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/cake/libs/model/behaviors/containable.php b/cake/libs/model/behaviors/containable.php index 7d9a96536..f2e30f8c6 100644 --- a/cake/libs/model/behaviors/containable.php +++ b/cake/libs/model/behaviors/containable.php @@ -57,7 +57,7 @@ class ContainableBehavior extends ModelBehavior { * disables this feature. DEFAULTS TO: true * * - notices: (boolean, optional) issues E_NOTICES for bindings referenced in a - * containable call that are not valid. DEFAULTS TO: false + * containable call that are not valid. DEFAULTS TO: true * * - autoFields: (boolean, optional) auto-add needed fields to fetch requested * bindings. DEFAULTS TO: true @@ -297,8 +297,10 @@ class ContainableBehavior extends ModelBehavior { } } - if ($throwErrors && (!isset($Model->{$name}) || !is_object($Model->{$name}))) { - trigger_error(__(sprintf('Model "%s" is not associated with model "%s"', $Model->alias, $name), true), E_USER_WARNING); + if (!isset($Model->{$name}) || !is_object($Model->{$name})) { + if ($throwErrors) { + trigger_error(__(sprintf('Model "%s" is not associated with model "%s"', $Model->alias, $name), true), E_USER_WARNING); + } continue; } diff --git a/cake/tests/cases/libs/model/behaviors/containable.test.php b/cake/tests/cases/libs/model/behaviors/containable.test.php index 627defc63..ec000d02b 100644 --- a/cake/tests/cases/libs/model/behaviors/containable.test.php +++ b/cake/tests/cases/libs/model/behaviors/containable.test.php @@ -87,6 +87,14 @@ class ContainableTest extends CakeTestCase { $this->assertEqual(Set::extract('/ArticleFeatured/keep/Featured/fields', $r), array('id')); } + function testInvalidContainments() { + $this->expectError(); + $r = $this->__containments($this->Article, array('Comment', 'InvalidBinding')); + + $this->Article->Behaviors->attach('Containable', array('notices' => false)); + $r = $this->__containments($this->Article, array('Comment', 'InvalidBinding')); + } + function testBeforeFind() { $r = $this->Article->find('all', array('contain' => array('Comment'))); $this->assertFalse(Set::matches('/User', $r));