From a2d04589a6d98179b2fa094cdbf065a0233526aa Mon Sep 17 00:00:00 2001 From: tranfuga25s Date: Fri, 5 Dec 2014 15:23:48 -0300 Subject: [PATCH 01/18] Change to output the difference between fixture data and fields --- .../TestSuite/Fixture/CakeTestFixture.php | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php index 329eef27f..fc70aa519 100644 --- a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php +++ b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php @@ -287,9 +287,25 @@ class CakeTestFixture { $fields = array_unique($fields); $default = array_fill_keys($fields, null); foreach ($this->records as $record) { - $merge = array_values(array_merge($default, $record)); + $merge_data = array_merge( $default, $record ); + $merge = array_values( $temporal ); if (count($fields) !== count($merge)) { - throw new CakeException('Fixture invalid: Count of fields does not match count of values in ' . get_class($this)); + + $merge_fields = array_keys( $merge_data ); + $remove = array(); + + foreach( $fields as $f ) { + if( in_array( $f, $merge_fields ) ) { + $remove[] = $f; + } + } + $merge_fields = array_diff( $merge_fields, $remove ); + $message = 'Fixture invalid: Count of fields does not match count of values in ' . get_class($this)."\n"; + foreach( $merge_fields as $field ) { + $message .= "The field '".$field."' is not in the fixture used in the schema."."\n"; + } + + throw new CakeException( $message ); } $values[] = $merge; } From fc756ac0b80bc5252659246f0ca7591bd44a23d1 Mon Sep 17 00:00:00 2001 From: tranfuga25s Date: Fri, 5 Dec 2014 15:34:53 -0300 Subject: [PATCH 02/18] fix some small typo changing variables names --- lib/Cake/TestSuite/Fixture/CakeTestFixture.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php index fc70aa519..4cad64c00 100644 --- a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php +++ b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php @@ -288,7 +288,7 @@ class CakeTestFixture { $default = array_fill_keys($fields, null); foreach ($this->records as $record) { $merge_data = array_merge( $default, $record ); - $merge = array_values( $temporal ); + $merge = array_values( $merge_data ); if (count($fields) !== count($merge)) { $merge_fields = array_keys( $merge_data ); From ec2530ba58b88db75224aeb65a5b0f40947ece31 Mon Sep 17 00:00:00 2001 From: tranfuga25s Date: Fri, 5 Dec 2014 16:01:49 -0300 Subject: [PATCH 03/18] Fix PHPCS problems and a better comparation of schema and data --- .../TestSuite/Fixture/CakeTestFixture.php | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php index 4cad64c00..ca7363641 100644 --- a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php +++ b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php @@ -287,25 +287,29 @@ class CakeTestFixture { $fields = array_unique($fields); $default = array_fill_keys($fields, null); foreach ($this->records as $record) { - $merge_data = array_merge( $default, $record ); - $merge = array_values( $merge_data ); + $mergeData = array_merge( $default, $record ); + $merge = array_values( $mergeData ); if (count($fields) !== count($merge)) { - $merge_fields = array_keys( $merge_data ); - $remove = array(); - - foreach( $fields as $f ) { - if( in_array( $f, $merge_fields ) ) { - $remove[] = $f; - } - } - $merge_fields = array_diff( $merge_fields, $remove ); - $message = 'Fixture invalid: Count of fields does not match count of values in ' . get_class($this)."\n"; - foreach( $merge_fields as $field ) { - $message .= "The field '".$field."' is not in the fixture used in the schema."."\n"; - } - - throw new CakeException( $message ); + $mergeFields = array_keys( $merge_data ); + $remove = array(); + + foreach ($fields as $k => $f) { + if (in_array( $f, $mergeFields )) { + $remove[] = $f; + unset( $fields[$k] ); + } + } + $mergeFields = array_diff( $mergeFields, $remove ); + $message = 'Fixture invalid: Count of fields does not match count of values in ' . get_class($this)."\n"; + foreach ($mergeFields as $field) { + $message .= "The field '" . $field . "' is in the data fixture but not in the schema." . "\n"; + } + foreach ($fields as $field) { + $message .= "The field '" . $field . "' is in the fixture but not in the data." . "\n"; + } + + throw new CakeException( $message ); } $values[] = $merge; } From b0d0143b8218c1c56ffae2678ad4c69a8d03a34a Mon Sep 17 00:00:00 2001 From: tranfuga25s Date: Fri, 5 Dec 2014 16:14:47 -0300 Subject: [PATCH 04/18] Fix PHPCS problems --- lib/Cake/TestSuite/Fixture/CakeTestFixture.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php index ca7363641..e31f38986 100644 --- a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php +++ b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php @@ -291,7 +291,7 @@ class CakeTestFixture { $merge = array_values( $mergeData ); if (count($fields) !== count($merge)) { - $mergeFields = array_keys( $merge_data ); + $mergeFields = array_keys( $mergeData ); $remove = array(); foreach ($fields as $k => $f) { @@ -301,7 +301,7 @@ class CakeTestFixture { } } $mergeFields = array_diff( $mergeFields, $remove ); - $message = 'Fixture invalid: Count of fields does not match count of values in ' . get_class($this)."\n"; + $message = 'Fixture invalid: Count of fields does not match count of values in ' . get_class($this) . "\n"; foreach ($mergeFields as $field) { $message .= "The field '" . $field . "' is in the data fixture but not in the schema." . "\n"; } From 850edf47a0d0f019d204e80a76156686f11a2847 Mon Sep 17 00:00:00 2001 From: ADmad Date: Mon, 8 Dec 2014 23:45:34 +0530 Subject: [PATCH 05/18] Fix plural calculation for Arabic. Refs #5348 --- lib/Cake/I18n/I18n.php | 9 ++ lib/Cake/Test/Case/I18n/I18nTest.php | 131 +++++++++++++++++- .../Locale/rule_15_mo/LC_MESSAGES/core.mo | Bin 0 -> 875 bytes .../Locale/rule_15_mo/LC_MESSAGES/default.mo | Bin 0 -> 769 bytes .../Locale/rule_15_po/LC_MESSAGES/core.po | 25 ++++ .../Locale/rule_15_po/LC_MESSAGES/default.po | 25 ++++ 6 files changed, 186 insertions(+), 4 deletions(-) create mode 100644 lib/Cake/Test/test_app/Locale/rule_15_mo/LC_MESSAGES/core.mo create mode 100644 lib/Cake/Test/test_app/Locale/rule_15_mo/LC_MESSAGES/default.mo create mode 100644 lib/Cake/Test/test_app/Locale/rule_15_po/LC_MESSAGES/core.po create mode 100644 lib/Cake/Test/test_app/Locale/rule_15_po/LC_MESSAGES/default.po diff --git a/lib/Cake/I18n/I18n.php b/lib/Cake/I18n/I18n.php index 253081ba6..3cc00290b 100644 --- a/lib/Cake/I18n/I18n.php +++ b/lib/Cake/I18n/I18n.php @@ -311,6 +311,7 @@ class I18n { * @param string $header Type * @param int $n Number * @return int plural match + * @see */ protected function _pluralGuess($header, $n) { if (!is_string($header) || $header === "nplurals=1;plural=0;" || !isset($header[0])) { @@ -351,7 +352,15 @@ class I18n { } } elseif (strpos($header, "plurals=5")) { return $n == 1 ? 0 : ($n == 2 ? 1 : ($n >= 3 && $n <= 6 ? 2 : ($n >= 7 && $n <= 10 ? 3 : 4))); + } elseif (strpos($header, "plurals=6")) { + return $n == 0 ? 0 : + ($n == 1 ? 1 : + ($n == 2 ? 2 : + ($n % 100 >= 3 && $n % 100 <= 10 ? 3 : + ($n % 100 >= 11 ? 4 : 5)))); } + + return 0; } /** diff --git a/lib/Cake/Test/Case/I18n/I18nTest.php b/lib/Cake/Test/Case/I18n/I18nTest.php index 35ff4b056..ded12231c 100644 --- a/lib/Cake/Test/Case/I18n/I18nTest.php +++ b/lib/Cake/Test/Case/I18n/I18nTest.php @@ -1512,6 +1512,127 @@ class I18nTest extends CakeTestCase { $this->assertTrue(in_array('25 everything else (from core translated)', $corePlurals)); } +/** + * testMoRulesFifteen method + * + * @return void + */ + public function testMoRulesFifteen() { + Configure::write('Config.language', 'rule_15_mo'); + $this->assertRulesFifteen(); + } + +/** + * testPoRulesFifteen method + * + * @return void + */ + public function testPoRulesFifteen() { + Configure::write('Config.language', 'rule_15_po'); + $this->assertRulesFifteen(); + } + +/** + * Assertions for plural rules fifteen + * + * @return void + */ + public function assertRulesFifteen() { + $singular = $this->_singular(); + $this->assertEquals('Plural Rule 15 (translated)', $singular); + + $plurals = $this->_plural(111); + $this->assertTrue(in_array('0 is 0 (translated)', $plurals)); + $this->assertTrue(in_array('1 is 1 (translated)', $plurals)); + $this->assertTrue(in_array('2 is 2 (translated)', $plurals)); + $this->assertTrue(in_array('3 ends with 03-10 (translated)', $plurals)); + $this->assertTrue(in_array('4 ends with 03-10 (translated)', $plurals)); + $this->assertTrue(in_array('5 ends with 03-10 (translated)', $plurals)); + $this->assertTrue(in_array('6 ends with 03-10 (translated)', $plurals)); + $this->assertTrue(in_array('7 ends with 03-10 (translated)', $plurals)); + $this->assertTrue(in_array('8 ends with 03-10 (translated)', $plurals)); + $this->assertTrue(in_array('9 ends with 03-10 (translated)', $plurals)); + $this->assertTrue(in_array('10 ends with 03-10 (translated)', $plurals)); + $this->assertTrue(in_array('11 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('12 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('13 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('14 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('15 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('16 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('17 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('18 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('19 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('20 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('31 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('42 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('53 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('64 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('75 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('86 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('97 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('98 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('99 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('100 everything else (translated)', $plurals)); + $this->assertTrue(in_array('101 everything else (translated)', $plurals)); + $this->assertTrue(in_array('102 everything else (translated)', $plurals)); + $this->assertTrue(in_array('103 ends with 03-10 (translated)', $plurals)); + $this->assertTrue(in_array('104 ends with 03-10 (translated)', $plurals)); + $this->assertTrue(in_array('105 ends with 03-10 (translated)', $plurals)); + $this->assertTrue(in_array('106 ends with 03-10 (translated)', $plurals)); + $this->assertTrue(in_array('107 ends with 03-10 (translated)', $plurals)); + $this->assertTrue(in_array('108 ends with 03-10 (translated)', $plurals)); + $this->assertTrue(in_array('109 ends with 03-10 (translated)', $plurals)); + $this->assertTrue(in_array('110 ends with 03-10 (translated)', $plurals)); + $this->assertTrue(in_array('111 ends with 11-99 (translated)', $plurals)); + + $coreSingular = $this->_singularFromCore(); + $this->assertEquals('Plural Rule 15 (from core translated)', $coreSingular); + + $corePlurals = $this->_pluralFromCore(111); + $this->assertTrue(in_array('0 is 0 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('1 is 1 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('2 is 2 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('3 ends with 03-10 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('4 ends with 03-10 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('5 ends with 03-10 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('6 ends with 03-10 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('7 ends with 03-10 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('8 ends with 03-10 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('9 ends with 03-10 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('10 ends with 03-10 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('11 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('12 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('13 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('14 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('15 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('16 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('17 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('18 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('19 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('20 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('31 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('42 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('53 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('64 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('75 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('86 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('97 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('98 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('99 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('100 everything else (from core translated)', $corePlurals)); + $this->assertTrue(in_array('101 everything else (from core translated)', $corePlurals)); + $this->assertTrue(in_array('102 everything else (from core translated)', $corePlurals)); + $this->assertTrue(in_array('103 ends with 03-10 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('104 ends with 03-10 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('105 ends with 03-10 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('106 ends with 03-10 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('107 ends with 03-10 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('108 ends with 03-10 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('109 ends with 03-10 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('110 ends with 03-10 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('111 ends with 11-99 (from core translated)', $corePlurals)); + } + /** * testSetLanguageWithSession method * @@ -1948,11 +2069,12 @@ class I18nTest extends CakeTestCase { /** * Plural method * + * @param int $upTo For numbers upto (default to 25) * @return void */ - protected function _plural() { + protected function _plural($upTo = 25) { $plurals = array(); - for ($number = 0; $number <= 25; $number++) { + for ($number = 0; $number <= $upTo; $number++) { $plurals[] = sprintf(__n('%d = 1', '%d = 0 or > 1', (float)$number), (float)$number); } return $plurals; @@ -1971,11 +2093,12 @@ class I18nTest extends CakeTestCase { /** * pluralFromCore method * + * @param int $upTo For numbers upto (default to 25) * @return void */ - protected function _pluralFromCore() { + protected function _pluralFromCore($upTo = 25) { $plurals = array(); - for ($number = 0; $number <= 25; $number++) { + for ($number = 0; $number <= $upTo; $number++) { $plurals[] = sprintf(__n('%d = 1 (from core)', '%d = 0 or > 1 (from core)', (float)$number), (float)$number); } return $plurals; diff --git a/lib/Cake/Test/test_app/Locale/rule_15_mo/LC_MESSAGES/core.mo b/lib/Cake/Test/test_app/Locale/rule_15_mo/LC_MESSAGES/core.mo new file mode 100644 index 0000000000000000000000000000000000000000..54ae1eeb2fc2e42de1eac36f1d5a00aebef7b055 GIT binary patch literal 875 zcmaJ<%We}f6dhihS$2oS;%*v&go8avt7Os%NFf!G+7h(`Vu_i#NnB>^$oBN{6YTg0 zeuLj&!MAWHQ<$nEwRGewpX2-fz4Q2cK<5$R8KF;jLO3GS=QH6YK@y%4z7c*t2!bDU z|00|}41!&{r{sX1|DD<&QAFmDfPm)R+>ImgVi zSZZ@GE<9Fd zU8^;+1Xa;BUx?8u^k5-)&5R4|c!Ee!C`VH+BFn4&JZ>QM(Zu{4{UrX@Q7ytkO literal 0 HcmV?d00001 diff --git a/lib/Cake/Test/test_app/Locale/rule_15_po/LC_MESSAGES/core.po b/lib/Cake/Test/test_app/Locale/rule_15_po/LC_MESSAGES/core.po new file mode 100644 index 000000000..1f8d1fe9c --- /dev/null +++ b/lib/Cake/Test/test_app/Locale/rule_15_po/LC_MESSAGES/core.po @@ -0,0 +1,25 @@ +msgid "" +msgstr "" +"Project-Id-Version: CakePHP Testsuite\n" +"POT-Creation-Date: 2014-12-06 19:20-0300\n" +"PO-Revision-Date: \n" +"Language-Team: CakePHP I18N & I10N Team \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=6; plural=n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 && n%100<=99 ? 4 : 5;\n" +"X-Poedit-Language: Six Forms of Plurals\n" +"X-Poedit-SourceCharset: utf-8\n" + +msgid "Plural Rule 1 (from core)" +msgstr "Plural Rule 15 (from core translated)" + +msgid "%d = 1 (from core)" +msgid_plural "%d = 0 or > 1 (from core)" +msgstr[0] "%d is 0 (from core translated)" +msgstr[1] "%d is 1 (from core translated)" +msgstr[2] "%d is 2 (from core translated)" +msgstr[3] "%d ends with 03-10 (from core translated)" +msgstr[4] "%d ends with 11-99 (from core translated)" +msgstr[5] "%d everything else (from core translated)" + diff --git a/lib/Cake/Test/test_app/Locale/rule_15_po/LC_MESSAGES/default.po b/lib/Cake/Test/test_app/Locale/rule_15_po/LC_MESSAGES/default.po new file mode 100644 index 000000000..3a2998804 --- /dev/null +++ b/lib/Cake/Test/test_app/Locale/rule_15_po/LC_MESSAGES/default.po @@ -0,0 +1,25 @@ +msgid "" +msgstr "" +"Project-Id-Version: CakePHP Testsuite\n" +"POT-Creation-Date: 2014-12-06 19:20-0300\n" +"PO-Revision-Date: \n" +"Language-Team: CakePHP I18N & I10N Team \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=6; plural=n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 && n%100<=99 ? 4 : 5;\n" +"X-Poedit-Language: Six Forms of Plurals\n" +"X-Poedit-SourceCharset: utf-8\n" + +msgid "Plural Rule 1" +msgstr "Plural Rule 15 (translated)" + +msgid "%d = 1" +msgid_plural "%d = 0 or > 1" +msgstr[0] "%d is 0 (translated)" +msgstr[1] "%d is 1 (translated)" +msgstr[2] "%d is 2 (translated)" +msgstr[3] "%d ends with 03-10 (translated)" +msgstr[4] "%d ends with 11-99 (translated)" +msgstr[5] "%d everything else (translated)" + From 31c7b01c3a7b5af29cbffe3e587c7a91b5217bab Mon Sep 17 00:00:00 2001 From: ADmad Date: Tue, 9 Dec 2014 00:03:24 +0530 Subject: [PATCH 06/18] Add reference links to docblock --- lib/Cake/I18n/I18n.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Cake/I18n/I18n.php b/lib/Cake/I18n/I18n.php index 3cc00290b..b03655c9a 100644 --- a/lib/Cake/I18n/I18n.php +++ b/lib/Cake/I18n/I18n.php @@ -311,7 +311,8 @@ class I18n { * @param string $header Type * @param int $n Number * @return int plural match - * @see + * @link http://localization-guide.readthedocs.org/en/latest/l10n/pluralforms.html + * @link https://developer.mozilla.org/en-US/docs/Mozilla/Localization/Localization_and_Plurals#List_of_Plural_Rules */ protected function _pluralGuess($header, $n) { if (!is_string($header) || $header === "nplurals=1;plural=0;" || !isset($header[0])) { From ef28b42b2b8885a2be216c11adbbf32919e04a5b Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 8 Dec 2014 20:50:35 -0500 Subject: [PATCH 07/18] Update version number to 2.5.7 --- lib/Cake/VERSION.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/VERSION.txt b/lib/Cake/VERSION.txt index a11f97fa6..85172b1d3 100644 --- a/lib/Cake/VERSION.txt +++ b/lib/Cake/VERSION.txt @@ -17,4 +17,4 @@ // @license http://www.opensource.org/licenses/mit-license.php MIT License // +--------------------------------------------------------------------------------------------+ // //////////////////////////////////////////////////////////////////////////////////////////////////// -2.5.6 +2.5.7 From e1c128bb9923272240f6a98de576e31c010a687b Mon Sep 17 00:00:00 2001 From: euromark Date: Tue, 9 Dec 2014 03:17:35 +0100 Subject: [PATCH 08/18] Consolidate with conditions sniff. --- lib/Cake/Console/Command/SchemaShell.php | 9 +++---- lib/Cake/Console/ConsoleOptionParser.php | 3 +-- lib/Cake/Console/ConsoleOutput.php | 3 +-- .../Component/PaginatorComponent.php | 3 +-- .../Component/SecurityComponent.php | 3 +-- lib/Cake/Core/Object.php | 3 +-- lib/Cake/Log/Engine/ConsoleLog.php | 3 +-- lib/Cake/Model/AclNode.php | 3 +-- lib/Cake/Model/Behavior/TranslateBehavior.php | 3 +-- lib/Cake/Model/Datasource/DboSource.php | 13 +++------ lib/Cake/Model/Model.php | 3 +-- lib/Cake/Network/CakeRequest.php | 6 ++--- lib/Cake/Network/CakeResponse.php | 3 +-- lib/Cake/Network/Email/CakeEmail.php | 3 +-- lib/Cake/Network/Http/HttpSocket.php | 3 +-- lib/Cake/Routing/Route/CakeRoute.php | 3 +-- lib/Cake/Routing/Router.php | 3 +-- .../Test/Case/Log/Engine/ConsoleLogTest.php | 3 +-- lib/Cake/Test/Case/Utility/FileTest.php | 3 +-- .../TestSuite/Fixture/CakeTestFixture.php | 3 +-- lib/Cake/Utility/CakeTime.php | 3 +-- lib/Cake/Utility/Hash.php | 3 +-- lib/Cake/Utility/ObjectCollection.php | 3 +-- lib/Cake/View/Helper.php | 9 +++---- lib/Cake/View/Helper/FormHelper.php | 27 +++++++------------ 25 files changed, 41 insertions(+), 83 deletions(-) diff --git a/lib/Cake/Console/Command/SchemaShell.php b/lib/Cake/Console/Command/SchemaShell.php index e60d8e734..6f77220d8 100644 --- a/lib/Cake/Console/Command/SchemaShell.php +++ b/lib/Cake/Console/Command/SchemaShell.php @@ -334,8 +334,7 @@ class SchemaShell extends AppShell { $this->out("\n" . __d('cake_console', 'The following table(s) will be dropped.')); $this->out(array_keys($drop)); - if ( - !empty($this->params['yes']) || + if (!empty($this->params['yes']) || $this->in(__d('cake_console', 'Are you sure you want to drop the table(s)?'), array('y', 'n'), 'n') === 'y' ) { $this->out(__d('cake_console', 'Dropping table(s).')); @@ -345,8 +344,7 @@ class SchemaShell extends AppShell { $this->out("\n" . __d('cake_console', 'The following table(s) will be created.')); $this->out(array_keys($create)); - if ( - !empty($this->params['yes']) || + if (!empty($this->params['yes']) || $this->in(__d('cake_console', 'Are you sure you want to create the table(s)?'), array('y', 'n'), 'y') === 'y' ) { $this->out(__d('cake_console', 'Creating table(s).')); @@ -399,8 +397,7 @@ class SchemaShell extends AppShell { $this->out("\n" . __d('cake_console', 'The following statements will run.')); $this->out(array_map('trim', $contents)); - if ( - !empty($this->params['yes']) || + if (!empty($this->params['yes']) || $this->in(__d('cake_console', 'Are you sure you want to alter the tables?'), array('y', 'n'), 'n') === 'y' ) { $this->out(); diff --git a/lib/Cake/Console/ConsoleOptionParser.php b/lib/Cake/Console/ConsoleOptionParser.php index 8960e7589..0f55b3108 100644 --- a/lib/Cake/Console/ConsoleOptionParser.php +++ b/lib/Cake/Console/ConsoleOptionParser.php @@ -510,8 +510,7 @@ class ConsoleOptionParser { * @return string Generated help. */ public function help($subcommand = null, $format = 'text', $width = 72) { - if ( - isset($this->_subcommands[$subcommand]) && + if (isset($this->_subcommands[$subcommand]) && $this->_subcommands[$subcommand]->parser() instanceof self ) { $subparser = $this->_subcommands[$subcommand]->parser(); diff --git a/lib/Cake/Console/ConsoleOutput.php b/lib/Cake/Console/ConsoleOutput.php index 2b5176887..32abf7123 100644 --- a/lib/Cake/Console/ConsoleOutput.php +++ b/lib/Cake/Console/ConsoleOutput.php @@ -161,8 +161,7 @@ class ConsoleOutput { public function __construct($stream = 'php://stdout') { $this->_output = fopen($stream, 'w'); - if ( - (DS === '\\' && !(bool)env('ANSICON')) || + if ((DS === '\\' && !(bool)env('ANSICON')) || (function_exists('posix_isatty') && !posix_isatty($this->_output)) ) { $this->_outputAs = self::PLAIN; diff --git a/lib/Cake/Controller/Component/PaginatorComponent.php b/lib/Cake/Controller/Component/PaginatorComponent.php index 82a322fec..1b0d1c43a 100644 --- a/lib/Cake/Controller/Component/PaginatorComponent.php +++ b/lib/Cake/Controller/Component/PaginatorComponent.php @@ -240,8 +240,7 @@ class PaginatorComponent extends Component { throw new NotFoundException(); } - if ( - !in_array('Paginator', $this->Controller->helpers) && + if (!in_array('Paginator', $this->Controller->helpers) && !array_key_exists('Paginator', $this->Controller->helpers) ) { $this->Controller->helpers[] = 'Paginator'; diff --git a/lib/Cake/Controller/Component/SecurityComponent.php b/lib/Cake/Controller/Component/SecurityComponent.php index 820cf43ab..2a2b41dd6 100644 --- a/lib/Cake/Controller/Component/SecurityComponent.php +++ b/lib/Cake/Controller/Component/SecurityComponent.php @@ -415,8 +415,7 @@ class SecurityComponent extends Component { if ($this->Session->check('_Token')) { $tData = $this->Session->read('_Token'); - if ( - !empty($tData['allowedControllers']) && + if (!empty($tData['allowedControllers']) && !in_array($this->request->params['controller'], $tData['allowedControllers']) || !empty($tData['allowedActions']) && !in_array($this->request->params['action'], $tData['allowedActions']) diff --git a/lib/Cake/Core/Object.php b/lib/Cake/Core/Object.php index 82de65fee..1c7543750 100644 --- a/lib/Cake/Core/Object.php +++ b/lib/Cake/Core/Object.php @@ -197,8 +197,7 @@ class Object { protected function _mergeVars($properties, $class, $normalize = true) { $classProperties = get_class_vars($class); foreach ($properties as $var) { - if ( - isset($classProperties[$var]) && + if (isset($classProperties[$var]) && !empty($classProperties[$var]) && is_array($this->{$var}) && $this->{$var} != $classProperties[$var] diff --git a/lib/Cake/Log/Engine/ConsoleLog.php b/lib/Cake/Log/Engine/ConsoleLog.php index 807b02777..e76172957 100644 --- a/lib/Cake/Log/Engine/ConsoleLog.php +++ b/lib/Cake/Log/Engine/ConsoleLog.php @@ -48,8 +48,7 @@ class ConsoleLog extends BaseLog { */ public function __construct($config = array()) { parent::__construct($config); - if ( - (DS === '\\' && !(bool)env('ANSICON')) || + if ((DS === '\\' && !(bool)env('ANSICON')) || (function_exists('posix_isatty') && !posix_isatty($this->_output)) ) { $outputAs = ConsoleOutput::PLAIN; diff --git a/lib/Cake/Model/AclNode.php b/lib/Cake/Model/AclNode.php index d77666bba..ab73f7b1d 100644 --- a/lib/Cake/Model/AclNode.php +++ b/lib/Cake/Model/AclNode.php @@ -116,8 +116,7 @@ class AclNode extends Model { $result = $db->read($this, $queryData, -1); $path = array_values($path); - if ( - !isset($result[0][$type]) || + if (!isset($result[0][$type]) || (!empty($path) && $result[0][$type]['alias'] != $path[count($path) - 1]) || (empty($path) && $result[0][$type]['alias'] != $start) ) { diff --git a/lib/Cake/Model/Behavior/TranslateBehavior.php b/lib/Cake/Model/Behavior/TranslateBehavior.php index 5ae7b4855..b82ed26cd 100644 --- a/lib/Cake/Model/Behavior/TranslateBehavior.php +++ b/lib/Cake/Model/Behavior/TranslateBehavior.php @@ -157,8 +157,7 @@ class TranslateBehavior extends ModelBehavior { ); foreach ($fields as $key => $value) { $field = (is_numeric($key)) ? $value : $key; - if ( - $isAllFields || + if ($isAllFields || in_array($Model->alias . '.' . $field, $query['fields']) || in_array($field, $query['fields']) ) { diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index eb3211a1a..545c1d358 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -834,9 +834,7 @@ class DboSource extends DataSource { $matches[1] . '(' . $this->name($matches[2]) . ')' ); } - if ( - preg_match('/^([\w-]+(\.[\w-]+|\(.*\))*)\s+' . preg_quote($this->alias) . '\s*([\w-]+)$/i', $data, $matches - )) { + if (preg_match('/^([\w-]+(\.[\w-]+|\(.*\))*)\s+' . preg_quote($this->alias) . '\s*([\w-]+)$/i', $data, $matches)) { return $this->cacheMethod( __FUNCTION__, $cacheKey, preg_replace( @@ -1313,8 +1311,7 @@ class DboSource extends DataSource { $assocResultSet = array(); $prefetched = false; - if ( - ($type === 'hasOne' || $type === 'belongsTo') && + if (($type === 'hasOne' || $type === 'belongsTo') && isset($row[$LinkModel->alias], $joined[$Model->alias]) && in_array($LinkModel->alias, $joined[$Model->alias]) ) { @@ -1337,8 +1334,7 @@ class DboSource extends DataSource { foreach ($LinkModel->{$type1} as $assoc1 => $assocData1) { $DeepModel = $LinkModel->{$assoc1}; - if ( - $type1 === 'belongsTo' || + if ($type1 === 'belongsTo' || ($type === 'belongsTo' && $DeepModel->alias === $modelAlias) || ($DeepModel->alias !== $modelAlias) ) { @@ -1589,8 +1585,7 @@ class DboSource extends DataSource { $assocFields = $this->fields($Model, null, "{$Model->alias}.{$Model->primaryKey}"); $passedFields = $queryData['fields']; - if ( - count($passedFields) > 1 || + if (count($passedFields) > 1 || (strpos($passedFields[0], $assocFields[0]) === false && !preg_match('/^[a-z]+\(/i', $passedFields[0])) ) { $queryData['fields'] = array_merge($passedFields, $assocFields); diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index f3faad97b..25f7c3813 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -1293,8 +1293,7 @@ class Model extends Object implements CakeEventListener { return null; } - if ( - isset($data['hour']) && + if (isset($data['hour']) && isset($data['meridian']) && !empty($data['hour']) && $data['hour'] != 12 && diff --git a/lib/Cake/Network/CakeRequest.php b/lib/Cake/Network/CakeRequest.php index 1cd0f0a96..32c0f2dd8 100644 --- a/lib/Cake/Network/CakeRequest.php +++ b/lib/Cake/Network/CakeRequest.php @@ -162,8 +162,7 @@ class CakeRequest implements ArrayAccess { protected function _processPost() { if ($_POST) { $this->data = $_POST; - } elseif ( - ($this->is('put') || $this->is('delete')) && + } elseif (($this->is('put') || $this->is('delete')) && strpos(env('CONTENT_TYPE'), 'application/x-www-form-urlencoded') === 0 ) { $data = $this->_readInput(); @@ -261,8 +260,7 @@ class CakeRequest implements ArrayAccess { } $endsWithIndex = '/webroot/index.php'; $endsWithLength = strlen($endsWithIndex); - if ( - strlen($uri) >= $endsWithLength && + if (strlen($uri) >= $endsWithLength && substr($uri, -$endsWithLength) === $endsWithIndex ) { $uri = '/'; diff --git a/lib/Cake/Network/CakeResponse.php b/lib/Cake/Network/CakeResponse.php index bd5890e61..4c84b5a66 100644 --- a/lib/Cake/Network/CakeResponse.php +++ b/lib/Cake/Network/CakeResponse.php @@ -464,8 +464,7 @@ class CakeResponse { ); $charset = false; - if ( - $this->_charset && + if ($this->_charset && (strpos($this->_contentType, 'text/') === 0 || in_array($this->_contentType, $whitelist)) ) { $charset = true; diff --git a/lib/Cake/Network/Email/CakeEmail.php b/lib/Cake/Network/Email/CakeEmail.php index 61dc597b3..ca7f8a97c 100644 --- a/lib/Cake/Network/Email/CakeEmail.php +++ b/lib/Cake/Network/Email/CakeEmail.php @@ -1481,8 +1481,7 @@ class CakeEmail { $msg[] = '--' . $boundary; $msg[] = 'Content-Type: ' . $fileInfo['mimetype']; $msg[] = 'Content-Transfer-Encoding: base64'; - if ( - !isset($fileInfo['contentDisposition']) || + if (!isset($fileInfo['contentDisposition']) || $fileInfo['contentDisposition'] ) { $msg[] = 'Content-Disposition: attachment; filename="' . $filename . '"'; diff --git a/lib/Cake/Network/Http/HttpSocket.php b/lib/Cake/Network/Http/HttpSocket.php index 09e8b0c30..3416c45b7 100644 --- a/lib/Cake/Network/Http/HttpSocket.php +++ b/lib/Cake/Network/Http/HttpSocket.php @@ -311,8 +311,7 @@ class HttpSocket extends CakeSocket { if (isset($this->request['uri']['port'])) { $port = $this->request['uri']['port']; } - if ( - ($scheme === 'http' && $port != 80) || + if (($scheme === 'http' && $port != 80) || ($scheme === 'https' && $port != 443) || ($port != 80 && $port != 443) ) { diff --git a/lib/Cake/Routing/Route/CakeRoute.php b/lib/Cake/Routing/Route/CakeRoute.php index 53fc5e354..a3bf0bf68 100644 --- a/lib/Cake/Routing/Route/CakeRoute.php +++ b/lib/Cake/Routing/Route/CakeRoute.php @@ -448,8 +448,7 @@ class CakeRoute { } // pull out named params if named params are greedy or a rule exists. - if ( - ($greedyNamed || isset($allowedNamedParams[$key])) && + if (($greedyNamed || isset($allowedNamedParams[$key])) && ($value !== false && $value !== null) && (!in_array($key, $prefixes)) ) { diff --git a/lib/Cake/Routing/Router.php b/lib/Cake/Routing/Router.php index f5768ebbd..5e843ef93 100644 --- a/lib/Cake/Routing/Router.php +++ b/lib/Cake/Routing/Router.php @@ -227,8 +227,7 @@ class Router { * @throws RouterException */ protected static function _validateRouteClass($routeClass) { - if ( - $routeClass !== 'CakeRoute' && + if ($routeClass !== 'CakeRoute' && (!class_exists($routeClass) || !is_subclass_of($routeClass, 'CakeRoute')) ) { throw new RouterException(__d('cake_dev', 'Route class not found, or route class is not a subclass of CakeRoute')); diff --git a/lib/Cake/Test/Case/Log/Engine/ConsoleLogTest.php b/lib/Cake/Test/Case/Log/Engine/ConsoleLogTest.php index 3a53976d0..c9a06b7fc 100644 --- a/lib/Cake/Test/Case/Log/Engine/ConsoleLogTest.php +++ b/lib/Cake/Test/Case/Log/Engine/ConsoleLogTest.php @@ -139,8 +139,7 @@ class ConsoleLogTest extends CakeTestCase { TestCakeLog::config('test_console_log', array( 'engine' => 'TestConsole', )); - if ( - (DS === '\\' && !(bool)env('ANSICON')) || + if ((DS === '\\' && !(bool)env('ANSICON')) || (function_exists('posix_isatty') && !posix_isatty(null)) ) { $expected = ConsoleOutput::PLAIN; diff --git a/lib/Cake/Test/Case/Utility/FileTest.php b/lib/Cake/Test/Case/Utility/FileTest.php index 52ad6ee7b..501ff7047 100644 --- a/lib/Cake/Test/Case/Utility/FileTest.php +++ b/lib/Cake/Test/Case/Utility/FileTest.php @@ -81,8 +81,7 @@ class FileTest extends CakeTestCase { 'filesize' => filesize($file), 'mime' => 'text/plain' ); - if ( - !function_exists('finfo_open') && + if (!function_exists('finfo_open') && (!function_exists('mime_content_type') || function_exists('mime_content_type') && mime_content_type($this->File->pwd()) === false) diff --git a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php index 329eef27f..5bf624d6e 100644 --- a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php +++ b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php @@ -296,8 +296,7 @@ class CakeTestFixture { $nested = $db->useNestedTransactions; $db->useNestedTransactions = false; $result = $db->insertMulti($this->table, $fields, $values); - if ( - $this->primaryKey && + if ($this->primaryKey && isset($this->fields[$this->primaryKey]['type']) && in_array($this->fields[$this->primaryKey]['type'], array('integer', 'biginteger')) ) { diff --git a/lib/Cake/Utility/CakeTime.php b/lib/Cake/Utility/CakeTime.php index 6e76351ad..f798c0f0f 100644 --- a/lib/Cake/Utility/CakeTime.php +++ b/lib/Cake/Utility/CakeTime.php @@ -322,8 +322,7 @@ class CakeTime { if (is_int($dateString) || is_numeric($dateString)) { $date = (int)$dateString; - } elseif ( - $dateString instanceof DateTime && + } elseif ($dateString instanceof DateTime && $dateString->getTimezone()->getName() != date_default_timezone_get() ) { $clone = clone $dateString; diff --git a/lib/Cake/Utility/Hash.php b/lib/Cake/Utility/Hash.php index 73f4a4c69..242c4a9f7 100644 --- a/lib/Cake/Utility/Hash.php +++ b/lib/Cake/Utility/Hash.php @@ -220,8 +220,7 @@ class Hash { if (!preg_match($val, $prop)) { return false; } - } elseif ( - ($op === '=' && $prop != $val) || + } elseif (($op === '=' && $prop != $val) || ($op === '!=' && $prop == $val) || ($op === '>' && $prop <= $val) || ($op === '<' && $prop >= $val) || diff --git a/lib/Cake/Utility/ObjectCollection.php b/lib/Cake/Utility/ObjectCollection.php index a65f6db93..4bbb1a3ea 100644 --- a/lib/Cake/Utility/ObjectCollection.php +++ b/lib/Cake/Utility/ObjectCollection.php @@ -129,8 +129,7 @@ abstract class ObjectCollection { if ($options['collectReturn'] === true) { $collected[] = $result; } - if ( - $options['break'] && ($result === $options['breakOn'] || + if ($options['break'] && ($result === $options['breakOn'] || (is_array($options['breakOn']) && in_array($result, $options['breakOn'], true))) ) { return $result; diff --git a/lib/Cake/View/Helper.php b/lib/Cake/View/Helper.php index e4fc03cf4..e91299e73 100644 --- a/lib/Cake/View/Helper.php +++ b/lib/Cake/View/Helper.php @@ -320,8 +320,7 @@ class Helper extends Object { if (!empty($options['pathPrefix']) && $path[0] !== '/') { $path = $options['pathPrefix'] . $path; } - if ( - !empty($options['ext']) && + if (!empty($options['ext']) && strpos($path, '?') === false && substr($path, -strlen($options['ext'])) !== $options['ext'] ) { @@ -543,8 +542,7 @@ class Helper extends Object { $lastPart = isset($parts[$count - 1]) ? $parts[$count - 1] : null; // Either 'body' or 'date.month' type inputs. - if ( - ($count === 1 && $this->_modelScope && !$setScope) || + if (($count === 1 && $this->_modelScope && !$setScope) || ( $count === 2 && in_array($lastPart, $this->_fieldSuffixes) && @@ -556,8 +554,7 @@ class Helper extends Object { } // 0.name, 0.created.month style inputs. Excludes inputs with the modelScope in them. - if ( - $count >= 2 && + if ($count >= 2 && is_numeric($parts[0]) && !is_numeric($parts[1]) && $this->_modelScope && diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 852c2653d..f147b1f8f 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -534,8 +534,7 @@ class FormHelper extends AppHelper { } $out .= $this->submit($submit, $submitOptions); } - if ( - $this->requestType !== 'get' && + if ($this->requestType !== 'get' && isset($this->request['_Token']) && !empty($this->request['_Token']) ) { @@ -1199,8 +1198,7 @@ class FormHelper extends AppHelper { if ($fieldKey === $primaryKey) { $options['type'] = 'hidden'; } - if ( - $options['type'] === 'number' && + if ($options['type'] === 'number' && !isset($options['step']) ) { if ($type === 'decimal') { @@ -1318,8 +1316,7 @@ class FormHelper extends AppHelper { } elseif (is_array($div)) { $divOptions = array_merge($divOptions, $div); } - if ( - $this->_extractOption('required', $options) !== false && + if ($this->_extractOption('required', $options) !== false && $this->_introspectModel($this->model(), 'validates', $this->field()) ) { $divOptions = $this->addClass($divOptions, 'required'); @@ -1362,8 +1359,7 @@ class FormHelper extends AppHelper { $idKey = null; if ($options['type'] === 'date' || $options['type'] === 'datetime') { $firstInput = 'M'; - if ( - array_key_exists('dateFormat', $options) && + if (array_key_exists('dateFormat', $options) && ($options['dateFormat'] === null || $options['dateFormat'] === 'NONE') ) { $firstInput = 'H'; @@ -1444,8 +1440,7 @@ class FormHelper extends AppHelper { $value = current($this->value($valueOptions)); $output = ''; - if ( - (!isset($options['checked']) && !empty($value) && $value == $options['value']) || + if ((!isset($options['checked']) && !empty($value) && $value == $options['value']) || !empty($options['checked']) ) { $options['checked'] = 'checked'; @@ -2086,8 +2081,7 @@ class FormHelper extends AppHelper { $hasOptions = (count($options) > 0 || $showEmpty); // Secure the field if there are options, or its a multi select. // Single selects with no options don't submit, but multiselects do. - if ( - (!isset($secure) || $secure) && + if ((!isset($secure) || $secure) && empty($attributes['disabled']) && (!empty($attributes['multiple']) || $hasOptions) ) { @@ -2761,8 +2755,7 @@ class FormHelper extends AppHelper { if ($name !== null) { $isNumeric = is_numeric($name); - if ( - (!$selectedIsArray && !$selectedIsEmpty && (string)$attributes['value'] == (string)$name) || + if ((!$selectedIsArray && !$selectedIsEmpty && (string)$attributes['value'] == (string)$name) || ($selectedIsArray && in_array((string)$name, $attributes['value'], !$isNumeric)) ) { if ($attributes['style'] === 'checkbox') { @@ -2782,8 +2775,7 @@ class FormHelper extends AppHelper { $disabledIsNumeric = is_numeric($name); } } - if ( - $hasDisabled && + if ($hasDisabled && $disabledIsArray && in_array((string)$name, $attributes['disabled'], !$disabledIsNumeric) ) { @@ -2902,8 +2894,7 @@ class FormHelper extends AppHelper { if ($min > $max) { list($min, $max) = array($max, $min); } - if ( - !empty($options['value']) && + if (!empty($options['value']) && (int)$options['value'] < $min && (int)$options['value'] > 0 ) { From 9ecdaf79655db798bfd48886cc3d3bd7a6792aa8 Mon Sep 17 00:00:00 2001 From: tranfuga25s Date: Tue, 9 Dec 2014 08:56:34 -0300 Subject: [PATCH 09/18] Added PHPCS fixes and better array diff handling on fixture data count difference --- .../TestSuite/Fixture/CakeTestFixture.php | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php index e31f38986..c8b2a0182 100644 --- a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php +++ b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php @@ -287,26 +287,15 @@ class CakeTestFixture { $fields = array_unique($fields); $default = array_fill_keys($fields, null); foreach ($this->records as $record) { - $mergeData = array_merge( $default, $record ); - $merge = array_values( $mergeData ); + $mergeData = array_merge($default, $record); + $merge = array_values($mergeData); if (count($fields) !== count($merge)) { - $mergeFields = array_keys( $mergeData ); - $remove = array(); + $mergeFields = array_diff_key(array_keys($mergeData), $fields); - foreach ($fields as $k => $f) { - if (in_array( $f, $mergeFields )) { - $remove[] = $f; - unset( $fields[$k] ); - } - } - $mergeFields = array_diff( $mergeFields, $remove ); - $message = 'Fixture invalid: Count of fields does not match count of values in ' . get_class($this) . "\n"; + $message = 'Fixture invalid: Count of fields does not match count of values in ' . get_class($this)."\n"; foreach ($mergeFields as $field) { - $message .= "The field '" . $field . "' is in the data fixture but not in the schema." . "\n"; - } - foreach ($fields as $field) { - $message .= "The field '" . $field . "' is in the fixture but not in the data." . "\n"; + $message .= "The field '".$field."' is in the data fixture but not in the schema."."\n"; } throw new CakeException( $message ); From 674af51d6b875496fe2b9075476d8702c30f29a5 Mon Sep 17 00:00:00 2001 From: tranfuga25s Date: Tue, 9 Dec 2014 09:16:34 -0300 Subject: [PATCH 10/18] Added PHPCS fixes --- lib/Cake/TestSuite/Fixture/CakeTestFixture.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php index c8b2a0182..6b13b995a 100644 --- a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php +++ b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php @@ -293,9 +293,9 @@ class CakeTestFixture { $mergeFields = array_diff_key(array_keys($mergeData), $fields); - $message = 'Fixture invalid: Count of fields does not match count of values in ' . get_class($this)."\n"; + $message = 'Fixture invalid: Count of fields does not match count of values in ' . get_class($this) . "\n"; foreach ($mergeFields as $field) { - $message .= "The field '".$field."' is in the data fixture but not in the schema."."\n"; + $message .= "The field '" . $field . "' is in the data fixture but not in the schema." . "\n"; } throw new CakeException( $message ); From 360346acd055e33fef382fc578a96646c434adf6 Mon Sep 17 00:00:00 2001 From: tranfuga25s Date: Tue, 9 Dec 2014 09:35:12 -0300 Subject: [PATCH 11/18] Added PHPCS fixes --- lib/Cake/TestSuite/Fixture/CakeTestFixture.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php index 6b13b995a..e37f74f41 100644 --- a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php +++ b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php @@ -295,7 +295,7 @@ class CakeTestFixture { $message = 'Fixture invalid: Count of fields does not match count of values in ' . get_class($this) . "\n"; foreach ($mergeFields as $field) { - $message .= "The field '" . $field . "' is in the data fixture but not in the schema." . "\n"; + $message .= "The field '" . $field . "' is in the data fixture but not in the schema." . "\n"; } throw new CakeException( $message ); From ac6d5cc70f2932de5eee17638ac7cd6c264ca9b0 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 9 Dec 2014 21:51:42 -0500 Subject: [PATCH 12/18] Fix incorrect pluralization of Human. Human should become humans, unlike other words ending in man. Fixes #5370 --- lib/Cake/Test/Case/Utility/InflectorTest.php | 4 ++++ lib/Cake/Utility/Inflector.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Utility/InflectorTest.php b/lib/Cake/Test/Case/Utility/InflectorTest.php index 1239aa2cb..f600ae757 100644 --- a/lib/Cake/Test/Case/Utility/InflectorTest.php +++ b/lib/Cake/Test/Case/Utility/InflectorTest.php @@ -186,6 +186,10 @@ class InflectorTest extends CakeTestCase { * @return void */ public function testInflectingPlurals() { + $this->assertEquals(Inflector::pluralize('axman'), 'axmen'); + $this->assertEquals(Inflector::pluralize('man'), 'men'); + $this->assertEquals(Inflector::pluralize('woman'), 'women'); + $this->assertEquals(Inflector::pluralize('human'), 'humans'); $this->assertEquals(Inflector::pluralize('categoria'), 'categorias'); $this->assertEquals(Inflector::pluralize('house'), 'houses'); $this->assertEquals(Inflector::pluralize('powerhouse'), 'powerhouses'); diff --git a/lib/Cake/Utility/Inflector.php b/lib/Cake/Utility/Inflector.php index 74c005e10..a8ca02dfd 100644 --- a/lib/Cake/Utility/Inflector.php +++ b/lib/Cake/Utility/Inflector.php @@ -44,7 +44,7 @@ class Inflector { '/sis$/i' => 'ses', '/([ti])um$/i' => '\1a', '/(p)erson$/i' => '\1eople', - '/(m)an$/i' => '\1en', + '/(? '\1en', '/(c)hild$/i' => '\1hildren', '/(buffal|tomat)o$/i' => '\1\2oes', '/(alumn|bacill|cact|foc|fung|nucle|radi|stimul|syllab|termin|vir)us$/i' => '\1i', From 23c4b7b7d5dd2fd6fbc4bc15c56ca3371ed910fa Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 10 Dec 2014 22:17:02 -0500 Subject: [PATCH 13/18] Fix whitespace. --- lib/Cake/TestSuite/Fixture/CakeTestFixture.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php index 3dd3fa69e..a09ed21e2 100644 --- a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php +++ b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php @@ -298,7 +298,7 @@ class CakeTestFixture { $message .= "The field '" . $field . "' is in the data fixture but not in the schema." . "\n"; } - throw new CakeException( $message ); + throw new CakeException($message); } $values[] = $merge; } From cf108dbff31ebfe72d9f8d61bee9761e56f99eca Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 10 Dec 2014 22:32:59 -0500 Subject: [PATCH 14/18] Remove duplicate order key. This was a mistake made in 4b6dba0. Fixes #5376 --- lib/Cake/Model/Behavior/TreeBehavior.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Model/Behavior/TreeBehavior.php b/lib/Cake/Model/Behavior/TreeBehavior.php index 7c0afedf1..cedf215e2 100644 --- a/lib/Cake/Model/Behavior/TreeBehavior.php +++ b/lib/Cake/Model/Behavior/TreeBehavior.php @@ -494,8 +494,8 @@ class TreeBehavior extends ModelBehavior { $item = $result[0]; $results = $Model->find('all', array( 'conditions' => array($scope, $Model->escapeField($left) . ' <=' => $item[$left], $Model->escapeField($right) . ' >=' => $item[$right]), - 'fields' => $fields, 'order' => array($Model->escapeField($left) => 'asc'), - 'order' => false, + 'fields' => $fields, + 'order' => array($Model->escapeField($left) => 'asc'), 'recursive' => $recursive )); return $results; From c58e7da6676e190cc19aa0ddd1f673eaee94e86e Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 13 Dec 2014 15:04:11 -0500 Subject: [PATCH 15/18] Handle exception when RequestHandler::startup() fails. In the case that there is a request data type parser raises an exception, or startup() otherwise fails the error page should be created correctly. While I'm not able to write a test case for this, manual testing confirmed the fix. Refs #5311 --- lib/Cake/Error/ExceptionRenderer.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Error/ExceptionRenderer.php b/lib/Cake/Error/ExceptionRenderer.php index 3da88679e..0a8490208 100644 --- a/lib/Cake/Error/ExceptionRenderer.php +++ b/lib/Cake/Error/ExceptionRenderer.php @@ -153,9 +153,14 @@ class ExceptionRenderer { try { $controller = new CakeErrorController($request, $response); $controller->startupProcess(); + $startup = true; } catch (Exception $e) { - if (!empty($controller) && $controller->Components->enabled('RequestHandler')) { + $startup = false; + } + if ($startup === false && !empty($controller) && $controller->Components->enabled('RequestHandler')) { + try { $controller->RequestHandler->startup($controller); + } catch (Exception $e) { } } } From f19916bccf627535e77e496c95fd4e0e20e8ea46 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 13 Dec 2014 22:25:52 -0500 Subject: [PATCH 16/18] Add comments for possibly confusing code. --- lib/Cake/Error/ExceptionRenderer.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Error/ExceptionRenderer.php b/lib/Cake/Error/ExceptionRenderer.php index 0a8490208..ad36fea3e 100644 --- a/lib/Cake/Error/ExceptionRenderer.php +++ b/lib/Cake/Error/ExceptionRenderer.php @@ -157,7 +157,13 @@ class ExceptionRenderer { } catch (Exception $e) { $startup = false; } - if ($startup === false && !empty($controller) && $controller->Components->enabled('RequestHandler')) { + // Retry RequestHandler, as another aspect of startupProcess() + // could have failed. Ignore any exceptions out of startup, as + // there could be userland input data parsers. + if ($startup === false && + !empty($controller) && + $controller->Components->enabled('RequestHandler') + ) { try { $controller->RequestHandler->startup($controller); } catch (Exception $e) { From ae8a540101976d38d9114d2e62bd424dc34513b1 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 14 Dec 2014 18:05:20 -0500 Subject: [PATCH 17/18] Remove trailing whitespace. --- lib/Cake/Error/ExceptionRenderer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Error/ExceptionRenderer.php b/lib/Cake/Error/ExceptionRenderer.php index ad36fea3e..04190eba5 100644 --- a/lib/Cake/Error/ExceptionRenderer.php +++ b/lib/Cake/Error/ExceptionRenderer.php @@ -158,7 +158,7 @@ class ExceptionRenderer { $startup = false; } // Retry RequestHandler, as another aspect of startupProcess() - // could have failed. Ignore any exceptions out of startup, as + // could have failed. Ignore any exceptions out of startup, as // there could be userland input data parsers. if ($startup === false && !empty($controller) && From 2637d355432023a52dd2e7272446ede9b4d69503 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 15 Dec 2014 21:28:55 -0500 Subject: [PATCH 18/18] Don't quit bake when a table is missing. When a table is missing print a warning to stderr but don't exit. This allows people to use `bake fixture all` with non-conventional tables. Refs #5377 --- lib/Cake/Console/Command/Task/FixtureTask.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Console/Command/Task/FixtureTask.php b/lib/Cake/Console/Command/Task/FixtureTask.php index 099fe9516..65404fb1c 100644 --- a/lib/Cake/Console/Command/Task/FixtureTask.php +++ b/lib/Cake/Console/Command/Task/FixtureTask.php @@ -242,8 +242,8 @@ class FixtureTask extends BakeTask { $this->_Schema = new CakeSchema(); $data = $this->_Schema->read(array('models' => false, 'connection' => $this->connection)); if (!isset($data['tables'][$useTable])) { - $this->error('Could not find your selected table ' . $useTable); - return false; + $this->err("Warning: Could not find the '${useTable}' table for ${model}."); + return; } $tableInfo = $data['tables'][$useTable];