Upgrade CakePHP from 2.2.5 to 2.9.5

This commit is contained in:
Brm Ko 2017-02-26 15:29:44 +01:00
parent 5a580df460
commit 235a541597
793 changed files with 60746 additions and 23753 deletions

View file

@ -1,21 +1,33 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Utility
* @since CakePHP(tm) v 2.2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('Hash', 'Utility');
/**
* HashTest
*
* @package Cake.Utility
*/
class HashTest extends CakeTestCase {
/**
* Data provider
*
* @return array
*/
public static function articleData() {
return array(
array(
@ -129,6 +141,11 @@ class HashTest extends CakeTestCase {
);
}
/**
* Data provider
*
* @return array
*/
public static function userData() {
return array(
array(
@ -167,10 +184,21 @@ class HashTest extends CakeTestCase {
/**
* Test get()
*
* return void
* @return void
*/
public function testGet() {
$data = self::articleData();
$data = array('abc', 'def');
$result = Hash::get($data, '0');
$this->assertEquals('abc', $result);
$result = Hash::get($data, 0);
$this->assertEquals('abc', $result);
$result = Hash::get($data, '1');
$this->assertEquals('def', $result);
$data = static::articleData();
$result = Hash::get(array(), '1.Article.title');
$this->assertNull($result);
@ -187,6 +215,10 @@ class HashTest extends CakeTestCase {
$result = Hash::get($data, '5.Article.title');
$this->assertNull($result);
$default = array('empty');
$this->assertEquals($default, Hash::get($data, '5.Article.title', $default));
$this->assertEquals($default, Hash::get(array(), '5.Article.title', $default));
$result = Hash::get($data, '1.Article.title.not_there');
$this->assertNull($result);
@ -197,6 +229,42 @@ class HashTest extends CakeTestCase {
$this->assertEquals($data[1]['Article'], $result);
}
/**
* Test that get() can extract '' key data.
*
* @return void
*/
public function testGetEmptyKey() {
$data = array(
'' => 'some value'
);
$result = Hash::get($data, '');
$this->assertSame($data[''], $result);
}
/**
* Test get() with an invalid path
*
* @expectedException InvalidArgumentException
* @return void
*/
public function testGetInvalidPath() {
Hash::get(array('one' => 'two'), true);
}
/**
* Test testGetNullPath()
*
* @return void
*/
public function testGetNullPath() {
$result = Hash::get(array('one' => 'two'), null, '-');
$this->assertEquals('-', $result);
$result = Hash::get(array('one' => 'two'), '', '-');
$this->assertEquals('-', $result);
}
/**
* Test dimensions.
*
@ -233,42 +301,37 @@ class HashTest extends CakeTestCase {
* @return void
*/
public function testMaxDimensions() {
$data = array();
$result = Hash::maxDimensions($data);
$this->assertEquals(0, $result);
$data = array('a', 'b');
$result = Hash::maxDimensions($data);
$this->assertEquals(1, $result);
$data = array('1' => '1.1', '2', '3' => array('3.1' => '3.1.1'));
$result = Hash::maxDimensions($data);
$this->assertEquals($result, 2);
$data = array('1' => array('1.1' => '1.1.1'), '2', '3' => array('3.1' => array('3.1.1' => '3.1.1.1')));
$data = array(
'1' => array('1.1' => '1.1.1'),
'2',
'3' => array('3.1' => array('3.1.1' => '3.1.1.1'))
);
$result = Hash::maxDimensions($data);
$this->assertEquals($result, 3);
$data = array(
'1' => array('1.1' => '1.1.1'),
array('2' => array('2.1' => array('2.1.1' => '2.1.1.1'))),
'3' => array('3.1' => array('3.1.1' => '3.1.1.1'))
);
$result = Hash::maxDimensions($data);
$this->assertEquals($result, 4);
$data = array(
'1' => array('1.1' => '1.1.1'),
array('2' => array('2.1' => array('2.1.1' => array('2.1.1.1')))),
'3' => array('3.1' => array('3.1.1' => '3.1.1.1'))
);
$result = Hash::maxDimensions($data);
$this->assertEquals($result, 5);
$data = array(
'1' => array('1.1' => '1.1.1'),
array('2' => array('2.1' => array('2.1.1' => array('2.1.1.1' => '2.1.1.1.1')))),
'3' => array('3.1' => array('3.1.1' => '3.1.1.1'))
);
$result = Hash::maxDimensions($data);
$this->assertEquals($result, 5);
$data = array(
'1' => array('1.1' => '1.1.1'),
array('2' => array('2.1' => array('2.1.1' => array('2.1.1.1' => '2.1.1.1.1')))),
'3' => array('3.1' => array('3.1.1' => '3.1.1.1'))
'1' => array(
'1.1' => '1.1.1',
'1.2' => array(
'1.2.1' => array(
'1.2.1.1',
array('1.2.2.1')
)
)
),
'2' => array('2.1' => '2.1.1')
);
$result = Hash::maxDimensions($data);
$this->assertEquals($result, 5);
@ -509,7 +572,7 @@ class HashTest extends CakeTestCase {
'Validator',
'Transactional'
);
$this->assertEquals(Hash::merge($a, $b), $expected);
$this->assertEquals($expected, Hash::merge($a, $b));
}
/**
@ -575,6 +638,12 @@ class HashTest extends CakeTestCase {
);
$this->assertTrue(Hash::contains($b, $a));
$this->assertFalse(Hash::contains($a, $b));
$a = array(0 => 'test', 'string' => null);
$this->assertTrue(Hash::contains($a, array('string' => null)));
$a = array(0 => 'test', 'string' => null);
$this->assertTrue(Hash::contains($a, array('test')));
}
/**
@ -641,6 +710,9 @@ class HashTest extends CakeTestCase {
$data = array('one', 2 => 'two', 3 => 'three', 4 => 'four', 'a' => 'five');
$this->assertFalse(Hash::numeric(array_keys($data)));
$data = array(2.4, 1, 0, -1, -2);
$this->assertTrue(Hash::numeric($data));
}
/**
@ -649,7 +721,7 @@ class HashTest extends CakeTestCase {
* @return void
*/
public function testExtractBasic() {
$data = self::articleData();
$data = static::articleData();
$result = Hash::extract($data, '');
$this->assertEquals($data, $result);
@ -659,6 +731,9 @@ class HashTest extends CakeTestCase {
$result = Hash::extract($data, '1.Article.title');
$this->assertEquals(array('Second Article'), $result);
$result = Hash::extract(array(false), '{n}.Something.another_thing');
$this->assertEquals(array(), $result);
}
/**
@ -667,7 +742,7 @@ class HashTest extends CakeTestCase {
* @return void
*/
public function testExtractNumericKey() {
$data = self::articleData();
$data = static::articleData();
$result = Hash::extract($data, '{n}.Article.title');
$expected = array(
'First Article', 'Second Article',
@ -746,7 +821,7 @@ class HashTest extends CakeTestCase {
* @return void
*/
public function testExtractStringKey() {
$data = self::articleData();
$data = static::articleData();
$result = Hash::extract($data, '{n}.{s}.user');
$expected = array(
'mariano',
@ -761,13 +836,39 @@ class HashTest extends CakeTestCase {
$this->assertEquals(array('foo'), $result);
}
/**
* Test wildcard matcher
*
* @return void
*/
public function testExtractWildcard() {
$data = array(
'02000009C5560001' => array('name' => 'Mr. Alphanumeric'),
'2300000918020101' => array('name' => 'Mr. Numeric'),
'390000096AB30001' => array('name' => 'Mrs. Alphanumeric'),
'stuff' => array('name' => 'Ms. Word'),
123 => array('name' => 'Mr. Number'),
true => array('name' => 'Ms. Bool'),
);
$result = Hash::extract($data, '{*}.name');
$expected = array(
'Mr. Alphanumeric',
'Mr. Numeric',
'Mrs. Alphanumeric',
'Ms. Word',
'Mr. Number',
'Ms. Bool',
);
$this->assertEquals($expected, $result);
}
/**
* Test the attribute presense selector.
*
* @return void
*/
public function testExtractAttributePresence() {
$data = self::articleData();
$data = static::articleData();
$result = Hash::extract($data, '{n}.Article[published]');
$expected = array($data[1]['Article']);
@ -784,7 +885,7 @@ class HashTest extends CakeTestCase {
* @return void
*/
public function testExtractAttributeEquality() {
$data = self::articleData();
$data = static::articleData();
$result = Hash::extract($data, '{n}.Article[id=3]');
$expected = array($data[2]['Article']);
@ -801,13 +902,75 @@ class HashTest extends CakeTestCase {
$this->assertEquals(5, $result[3]['id']);
}
/**
* Test extracting based on attributes with boolean values.
*
* @return void
*/
public function testExtractAttributeBoolean() {
$users = array(
array(
'id' => 2,
'username' => 'johndoe',
'active' => true
),
array(
'id' => 5,
'username' => 'kevin',
'active' => true
),
array(
'id' => 9,
'username' => 'samantha',
'active' => false
),
);
$result = Hash::extract($users, '{n}[active=0]');
$this->assertCount(1, $result);
$this->assertEquals($users[2], $result[0]);
$result = Hash::extract($users, '{n}[active=false]');
$this->assertCount(1, $result);
$this->assertEquals($users[2], $result[0]);
$result = Hash::extract($users, '{n}[active=1]');
$this->assertCount(2, $result);
$this->assertEquals($users[0], $result[0]);
$this->assertEquals($users[1], $result[1]);
$result = Hash::extract($users, '{n}[active=true]');
$this->assertCount(2, $result);
$this->assertEquals($users[0], $result[0]);
$this->assertEquals($users[1], $result[1]);
}
/**
* Test that attribute matchers don't cause errors on scalar data.
*
* @return void
*/
public function testExtractAttributeEqualityOnScalarValue() {
$data = array(
'Entity' => array(
'id' => 1,
'data1' => 'value',
)
);
$result = Hash::extract($data, 'Entity[id=1].data1');
$this->assertEquals(array('value'), $result);
$data = array('Entity' => false );
$result = Hash::extract($data, 'Entity[id=1].data1');
$this->assertEquals(array(), $result);
}
/**
* Test comparison operators.
*
* @return void
*/
public function testExtractAttributeComparison() {
$data = self::articleData();
$data = static::articleData();
$result = Hash::extract($data, '{n}.Comment.{n}[user_id > 2]');
$expected = array($data[0]['Comment'][1]);
@ -836,7 +999,7 @@ class HashTest extends CakeTestCase {
* @return void
*/
public function testExtractAttributeMultiple() {
$data = self::articleData();
$data = static::articleData();
$result = Hash::extract($data, '{n}.Comment.{n}[user_id > 2][id=1]');
$this->assertEmpty($result);
@ -853,15 +1016,21 @@ class HashTest extends CakeTestCase {
* @return void
*/
public function testExtractAttributePattern() {
$data = self::articleData();
$data = static::articleData();
$result = Hash::extract($data, '{n}.Article[title=/^First/]');
$expected = array($data[0]['Article']);
$this->assertEquals($expected, $result);
$result = Hash::extract($data, '{n}.Article[title=/^Fir[a-z]+/]');
$expected = array($data[0]['Article']);
$this->assertEquals($expected, $result);
}
/**
* Test that extract() + matching can hit null things.
*
* @return void
*/
public function testExtractMatchesNull() {
$data = array(
@ -928,7 +1097,7 @@ class HashTest extends CakeTestCase {
* @return void
*/
public function testSort() {
$result = Hash::sort(array(), '{n}.name', 'asc');
$result = Hash::sort(array(), '{n}.name');
$this->assertEquals(array(), $result);
$a = array(
@ -951,7 +1120,7 @@ class HashTest extends CakeTestCase {
'Friend' => array(array('name' => 'Nate'))
)
);
$a = Hash::sort($a, '{n}.Friend.{n}.name', 'asc');
$a = Hash::sort($a, '{n}.Friend.{n}.name');
$this->assertEquals($a, $b);
$b = array(
@ -1017,7 +1186,7 @@ class HashTest extends CakeTestCase {
1 => array('Person' => array('name' => 'Jeff')),
);
$a = Hash::sort($a, '{n}.Person.name', 'ASC', 'STRING');
$this->assertEquals($a, $b);
$this->assertSame($a, $b);
$names = array(
array('employees' => array(
@ -1040,7 +1209,38 @@ class HashTest extends CakeTestCase {
array('employees' => array(array('name' => array()))),
array('employees' => array(array('name' => array())))
);
$this->assertEquals($expected, $result);
$this->assertSame($expected, $result);
$a = array(
'SU' => array(
'total_fulfillable' => 2
),
'AA' => array(
'total_fulfillable' => 1
),
'LX' => array(
'total_fulfillable' => 0
),
'BL' => array(
'total_fulfillable' => 3
),
);
$expected = array(
'LX' => array(
'total_fulfillable' => 0
),
'AA' => array(
'total_fulfillable' => 1
),
'SU' => array(
'total_fulfillable' => 2
),
'BL' => array(
'total_fulfillable' => 3
),
);
$result = Hash::sort($a, '{s}.total_fulfillable', 'asc');
$this->assertSame($expected, $result);
}
/**
@ -1114,6 +1314,97 @@ class HashTest extends CakeTestCase {
$this->assertEquals($expected, $result);
}
/**
* Test natural sorting ignoring case.
*
* @return void
*/
public function testSortNaturalIgnoreCase() {
if (version_compare(PHP_VERSION, '5.4.0', '<')) {
$this->markTestSkipped('SORT_NATURAL is available since PHP 5.4.');
}
$items = array(
array('Item' => array('image' => 'img1.jpg')),
array('Item' => array('image' => 'img99.jpg')),
array('Item' => array('image' => 'Img12.jpg')),
array('Item' => array('image' => 'Img10.jpg')),
array('Item' => array('image' => 'img2.jpg')),
);
$result = Hash::sort($items, '{n}.Item.image', 'desc', array('type' => 'natural', 'ignoreCase' => true));
$expected = array(
array('Item' => array('image' => 'img99.jpg')),
array('Item' => array('image' => 'Img12.jpg')),
array('Item' => array('image' => 'Img10.jpg')),
array('Item' => array('image' => 'img2.jpg')),
array('Item' => array('image' => 'img1.jpg')),
);
$this->assertEquals($expected, $result);
$result = Hash::sort($items, '{n}.Item.image', 'asc', array('type' => 'natural', 'ignoreCase' => true));
$expected = array(
array('Item' => array('image' => 'img1.jpg')),
array('Item' => array('image' => 'img2.jpg')),
array('Item' => array('image' => 'Img10.jpg')),
array('Item' => array('image' => 'Img12.jpg')),
array('Item' => array('image' => 'img99.jpg')),
);
$this->assertEquals($expected, $result);
}
/**
* Test that sort() with 'natural' type will fallback to 'regular' as SORT_NATURAL is introduced in PHP 5.4
*
* @return void
*/
public function testSortNaturalFallbackToRegular() {
if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
$this->markTestSkipped('Skipping SORT_NATURAL fallback test on PHP >= 5.4');
}
$a = array(
0 => array('Person' => array('name' => 'Jeff')),
1 => array('Shirt' => array('color' => 'black'))
);
$b = array(
0 => array('Shirt' => array('color' => 'black')),
1 => array('Person' => array('name' => 'Jeff')),
);
$sorted = Hash::sort($a, '{n}.Person.name', 'asc', 'natural');
$this->assertEquals($sorted, $b);
}
/**
* Test sort() with locale option.
*
* @return void
*/
public function testSortLocale() {
// get the current locale
$oldLocale = setlocale(LC_COLLATE, '0');
$updated = setlocale(LC_COLLATE, 'de_DE.utf8');
$this->skipIf($updated === false, 'Could not set locale to de_DE.utf8, skipping test.');
$items = array(
array('Item' => array('entry' => 'Übergabe')),
array('Item' => array('entry' => 'Ostfriesland')),
array('Item' => array('entry' => 'Äpfel')),
array('Item' => array('entry' => 'Apfel')),
);
$result = Hash::sort($items, '{n}.Item.entry', 'asc', 'locale');
$expected = array(
array('Item' => array('entry' => 'Apfel')),
array('Item' => array('entry' => 'Äpfel')),
array('Item' => array('entry' => 'Ostfriesland')),
array('Item' => array('entry' => 'Übergabe')),
);
$this->assertEquals($expected, $result);
// change to the original locale
setlocale(LC_COLLATE, $oldLocale);
}
/**
* test sorting with out of order keys.
*
@ -1146,7 +1437,7 @@ class HashTest extends CakeTestCase {
*
* @return void
*/
public function testSortString() {
public function testSortStringKeys() {
$toSort = array(
'four' => array('number' => 4, 'some' => 'foursome'),
'six' => array('number' => 6, 'some' => 'sixsome'),
@ -1178,6 +1469,50 @@ class HashTest extends CakeTestCase {
$this->assertEquals($expected, $result);
}
/**
* test sorting with string ignoring case.
*
* @return void
*/
public function testSortStringIgnoreCase() {
$toSort = array(
array('Item' => array('name' => 'bar')),
array('Item' => array('name' => 'Baby')),
array('Item' => array('name' => 'Baz')),
array('Item' => array('name' => 'bat')),
);
$sorted = Hash::sort($toSort, '{n}.Item.name', 'asc', array('type' => 'string', 'ignoreCase' => true));
$expected = array(
array('Item' => array('name' => 'Baby')),
array('Item' => array('name' => 'bar')),
array('Item' => array('name' => 'bat')),
array('Item' => array('name' => 'Baz')),
);
$this->assertEquals($expected, $sorted);
}
/**
* test regular sorting ignoring case.
*
* @return void
*/
public function testSortRegularIgnoreCase() {
$toSort = array(
array('Item' => array('name' => 'bar')),
array('Item' => array('name' => 'Baby')),
array('Item' => array('name' => 'Baz')),
array('Item' => array('name' => 'bat')),
);
$sorted = Hash::sort($toSort, '{n}.Item.name', 'asc', array('type' => 'regular', 'ignoreCase' => true));
$expected = array(
array('Item' => array('name' => 'Baby')),
array('Item' => array('name' => 'bar')),
array('Item' => array('name' => 'bat')),
array('Item' => array('name' => 'Baz')),
);
$this->assertEquals($expected, $sorted);
}
/**
* Test insert()
*
@ -1202,6 +1537,13 @@ class HashTest extends CakeTestCase {
'pages' => array('name' => array()),
);
$this->assertEquals($expected, $result);
$a = array(
'foo' => array('bar' => 'baz')
);
$result = Hash::insert($a, 'some.0123.path', array('foo' => array('bar' => 'baz')));
$expected = array('foo' => array('bar' => 'baz'));
$this->assertEquals($expected, Hash::get($result, 'some.0123.path'));
}
/**
@ -1210,7 +1552,7 @@ class HashTest extends CakeTestCase {
* @return void
*/
public function testInsertMulti() {
$data = self::articleData();
$data = static::articleData();
$result = Hash::insert($data, '{n}.Article.insert', 'value');
$this->assertEquals('value', $result[0]['Article']['insert']);
@ -1219,6 +1561,23 @@ class HashTest extends CakeTestCase {
$result = Hash::insert($data, '{n}.Comment.{n}.insert', 'value');
$this->assertEquals('value', $result[0]['Comment'][0]['insert']);
$this->assertEquals('value', $result[0]['Comment'][1]['insert']);
$data = array(
0 => array('Item' => array('id' => 1, 'title' => 'first')),
1 => array('Item' => array('id' => 2, 'title' => 'second')),
2 => array('Item' => array('id' => 3, 'title' => 'third')),
3 => array('Item' => array('id' => 4, 'title' => 'fourth')),
4 => array('Item' => array('id' => 5, 'title' => 'fifth')),
);
$result = Hash::insert($data, '{n}.Item[id=/\b2|\b4/]', array('test' => 2));
$expected = array(
0 => array('Item' => array('id' => 1, 'title' => 'first')),
1 => array('Item' => array('id' => 2, 'title' => 'second', 'test' => 2)),
2 => array('Item' => array('id' => 3, 'title' => 'third')),
3 => array('Item' => array('id' => 4, 'title' => 'fourth', 'test' => 2)),
4 => array('Item' => array('id' => 5, 'title' => 'fifth')),
);
$this->assertEquals($expected, $result);
}
/**
@ -1282,6 +1641,35 @@ class HashTest extends CakeTestCase {
$result = Hash::remove($a, 'pages.2.vars');
$expected = $a;
$this->assertEquals($expected, $result);
$a = array(
0 => array(
'name' => 'pages'
),
1 => array(
'name' => 'files'
)
);
$result = Hash::remove($a, '{n}[name=files]');
$expected = array(
0 => array(
'name' => 'pages'
)
);
$this->assertEquals($expected, $result);
$array = array(
0 => 'foo',
1 => array(
0 => 'baz'
)
);
$expected = $array;
$result = Hash::remove($array, '{n}.part');
$this->assertEquals($expected, $result);
$result = Hash::remove($array, '{n}.{n}.part');
$this->assertEquals($expected, $result);
}
/**
@ -1290,7 +1678,7 @@ class HashTest extends CakeTestCase {
* @return void
*/
public function testRemoveMulti() {
$data = self::articleData();
$data = static::articleData();
$result = Hash::remove($data, '{n}.Article.title');
$this->assertFalse(isset($result[0]['Article']['title']));
@ -1301,6 +1689,22 @@ class HashTest extends CakeTestCase {
$this->assertFalse(isset($result[0]['Article']['user_id']));
$this->assertFalse(isset($result[0]['Article']['title']));
$this->assertFalse(isset($result[0]['Article']['body']));
$data = array(
0 => array('Item' => array('id' => 1, 'title' => 'first')),
1 => array('Item' => array('id' => 2, 'title' => 'second')),
2 => array('Item' => array('id' => 3, 'title' => 'third')),
3 => array('Item' => array('id' => 4, 'title' => 'fourth')),
4 => array('Item' => array('id' => 5, 'title' => 'fifth')),
);
$result = Hash::remove($data, '{n}.Item[id=/\b2|\b4/]');
$expected = array(
0 => array('Item' => array('id' => 1, 'title' => 'first')),
2 => array('Item' => array('id' => 3, 'title' => 'third')),
4 => array('Item' => array('id' => 5, 'title' => 'fifth')),
);
$this->assertEquals($expected, $result);
}
/**
@ -1341,7 +1745,7 @@ class HashTest extends CakeTestCase {
$result = Hash::combine(array(), '{n}.User.id', '{n}.User.Data');
$this->assertTrue(empty($result));
$a = self::userData();
$a = static::userData();
$result = Hash::combine($a, '{n}.User.id');
$expected = array(2 => null, 14 => null, 25 => null);
@ -1366,13 +1770,41 @@ class HashTest extends CakeTestCase {
$this->assertEquals($expected, $result);
}
/**
* test combine() giving errors on key/value length mismatches.
*
* @expectedException CakeException
* @return void
*/
public function testCombineErrorMissingValue() {
$data = array(
array('User' => array('id' => 1, 'name' => 'mark')),
array('User' => array('name' => 'jose')),
);
Hash::combine($data, '{n}.User.id', '{n}.User.name');
}
/**
* test combine() giving errors on key/value length mismatches.
*
* @expectedException CakeException
* @return void
*/
public function testCombineErrorMissingKey() {
$data = array(
array('User' => array('id' => 1, 'name' => 'mark')),
array('User' => array('id' => 2)),
);
Hash::combine($data, '{n}.User.id', '{n}.User.name');
}
/**
* test combine() with a group path.
*
* @return void
*/
public function testCombineWithGroupPath() {
$a = self::userData();
$a = static::userData();
$result = Hash::combine($a, '{n}.User.id', '{n}.User.Data', '{n}.User.group_id');
$expected = array(
@ -1429,7 +1861,7 @@ class HashTest extends CakeTestCase {
* @return void
*/
public function testCombineWithFormatting() {
$a = self::userData();
$a = static::userData();
$result = Hash::combine(
$a,
@ -1495,7 +1927,7 @@ class HashTest extends CakeTestCase {
* @return void
*/
public function testFormat() {
$data = self::userData();
$data = static::userData();
$result = Hash::format(
$data,
@ -1555,15 +1987,20 @@ class HashTest extends CakeTestCase {
* @return void
*/
public function testMap() {
$data = self::articleData();
$data = static::articleData();
$result = Hash::map($data, '{n}.Article.id', array($this, 'mapCallback'));
$expected = array(2, 4, 6, 8, 10);
$this->assertEquals($expected, $result);
}
/**
* testApply
*
* @return void
*/
public function testApply() {
$data = self::articleData();
$data = static::articleData();
$result = Hash::apply($data, '{n}.Article.id', 'array_sum');
$this->assertEquals(15, $result);
@ -1575,7 +2012,7 @@ class HashTest extends CakeTestCase {
* @return void
*/
public function testReduce() {
$data = self::articleData();
$data = static::articleData();
$result = Hash::reduce($data, '{n}.Article.id', array($this, 'reduceCallback'));
$this->assertEquals(15, $result);
@ -1584,8 +2021,8 @@ class HashTest extends CakeTestCase {
/**
* testing method for map callbacks.
*
* @param mixed $value
* @return mixed.
* @param mixed $value Value
* @return mixed
*/
public function mapCallback($value) {
return $value * 2;
@ -1594,9 +2031,9 @@ class HashTest extends CakeTestCase {
/**
* testing method for reduce callbacks.
*
* @param mixed $one
* @param mixed $two
* @return mixed.
* @param mixed $one First param
* @param mixed $two Second param
* @return mixed
*/
public function reduceCallback($one, $two) {
return $one + $two;
@ -2018,6 +2455,25 @@ class HashTest extends CakeTestCase {
$this->assertEquals($input, $result);
}
/**
* Tests that nest() throws an InvalidArgumentException when providing an invalid input.
*
* @expectedException InvalidArgumentException
* @return void
*/
public function testNestInvalid() {
$input = array(
array(
'ParentCategory' => array(
'id' => '1',
'name' => 'Lorem ipsum dolor sit amet',
'parent_id' => '1'
)
)
);
Hash::nest($input);
}
/**
* testMergeDiff method
*
@ -2162,7 +2618,19 @@ class HashTest extends CakeTestCase {
)
)
);
$this->assertEquals($result, $expected);
$this->assertEquals($expected, $result);
$data = array('a.b.100.a' => null, 'a.b.200.a' => null);
$expected = array(
'a' => array(
'b' => array(
100 => array('a' => null),
200 => array('a' => null)
)
)
);
$result = Hash::expand($data);
$this->assertEquals($expected, $result);
}
/**
@ -2210,52 +2678,52 @@ class HashTest extends CakeTestCase {
'Order.Item.0.Product.sizes.4.Size.qty' => '',
'Order.Item.0.Product.sizes.4.Size.size' => '12-18mo',
'Order.Item.0.Product.sizes.4.Size.id' => '42',
'Order.Item.0.Art.imprint_locations.0.id' => (int) 2,
'Order.Item.0.Art.imprint_locations.0.id' => 2,
'Order.Item.0.Art.imprint_locations.0.name' => 'Left Chest',
'Order.Item.0.Art.imprint_locations.0.imprint_type.id' => (int) 7,
'Order.Item.0.Art.imprint_locations.0.imprint_type.id' => 7,
'Order.Item.0.Art.imprint_locations.0.imprint_type.type' => 'Embroidery',
'Order.Item.0.Art.imprint_locations.0.art' => '',
'Order.Item.0.Art.imprint_locations.0.num_colors' => (int) 3,
'Order.Item.0.Art.imprint_locations.0.num_colors' => 3,
'Order.Item.0.Art.imprint_locations.0.description' => 'Wooo! This is Embroidery!!',
'Order.Item.0.Art.imprint_locations.0.lines.0' => 'Platen',
'Order.Item.0.Art.imprint_locations.0.lines.1' => 'Logo',
'Order.Item.0.Art.imprint_locations.0.height' => (int) 4,
'Order.Item.0.Art.imprint_locations.0.width' => (int) 5,
'Order.Item.0.Art.imprint_locations.0.height' => 4,
'Order.Item.0.Art.imprint_locations.0.width' => 5,
'Order.Item.0.Art.imprint_locations.0.stitch_density' => 'Light',
'Order.Item.0.Art.imprint_locations.0.metallic_thread' => true,
'Order.Item.0.Art.imprint_locations.1.id' => (int) 4,
'Order.Item.0.Art.imprint_locations.1.id' => 4,
'Order.Item.0.Art.imprint_locations.1.name' => 'Full Back',
'Order.Item.0.Art.imprint_locations.1.imprint_type.id' => (int) 6,
'Order.Item.0.Art.imprint_locations.1.imprint_type.id' => 6,
'Order.Item.0.Art.imprint_locations.1.imprint_type.type' => 'Screenprinting',
'Order.Item.0.Art.imprint_locations.1.art' => '',
'Order.Item.0.Art.imprint_locations.1.num_colors' => (int) 3,
'Order.Item.0.Art.imprint_locations.1.num_colors' => 3,
'Order.Item.0.Art.imprint_locations.1.description' => 'Wooo! This is Screenprinting!!',
'Order.Item.0.Art.imprint_locations.1.lines.0' => 'Platen',
'Order.Item.0.Art.imprint_locations.1.lines.1' => 'Logo',
'Order.Item.0.Art.imprint_locations.2.id' => (int) 26,
'Order.Item.0.Art.imprint_locations.2.id' => 26,
'Order.Item.0.Art.imprint_locations.2.name' => 'HS - JSY Name Below',
'Order.Item.0.Art.imprint_locations.2.imprint_type.id' => (int) 9,
'Order.Item.0.Art.imprint_locations.2.imprint_type.id' => 9,
'Order.Item.0.Art.imprint_locations.2.imprint_type.type' => 'Names',
'Order.Item.0.Art.imprint_locations.2.description' => 'Wooo! This is Names!!',
'Order.Item.0.Art.imprint_locations.2.sizes.S.0.active' => (int) 1,
'Order.Item.0.Art.imprint_locations.2.sizes.S.0.active' => 1,
'Order.Item.0.Art.imprint_locations.2.sizes.S.0.name' => 'Benjamin Talavera',
'Order.Item.0.Art.imprint_locations.2.sizes.S.0.color' => 'Red',
'Order.Item.0.Art.imprint_locations.2.sizes.S.0.height' => '3',
'Order.Item.0.Art.imprint_locations.2.sizes.S.0.layout' => 'Arched',
'Order.Item.0.Art.imprint_locations.2.sizes.S.0.style' => 'Classic',
'Order.Item.0.Art.imprint_locations.2.sizes.S.1.active' => (int) 0,
'Order.Item.0.Art.imprint_locations.2.sizes.S.1.active' => 0,
'Order.Item.0.Art.imprint_locations.2.sizes.S.1.name' => 'Rishi Narayan',
'Order.Item.0.Art.imprint_locations.2.sizes.S.1.color' => 'Cardinal',
'Order.Item.0.Art.imprint_locations.2.sizes.S.1.height' => '4',
'Order.Item.0.Art.imprint_locations.2.sizes.S.1.layout' => 'Straight',
'Order.Item.0.Art.imprint_locations.2.sizes.S.1.style' => 'Team US',
'Order.Item.0.Art.imprint_locations.2.sizes.M.0.active' => (int) 1,
'Order.Item.0.Art.imprint_locations.2.sizes.M.0.active' => 1,
'Order.Item.0.Art.imprint_locations.2.sizes.M.0.name' => 'Brandon Plasters',
'Order.Item.0.Art.imprint_locations.2.sizes.M.0.color' => 'Red',
'Order.Item.0.Art.imprint_locations.2.sizes.M.0.height' => '3',
'Order.Item.0.Art.imprint_locations.2.sizes.M.0.layout' => 'Arched',
'Order.Item.0.Art.imprint_locations.2.sizes.M.0.style' => 'Classic',
'Order.Item.0.Art.imprint_locations.2.sizes.M.1.active' => (int) 0,
'Order.Item.0.Art.imprint_locations.2.sizes.M.1.active' => 0,
'Order.Item.0.Art.imprint_locations.2.sizes.M.1.name' => 'Andrew Reed',
'Order.Item.0.Art.imprint_locations.2.sizes.M.1.color' => 'Cardinal',
'Order.Item.0.Art.imprint_locations.2.sizes.M.1.height' => '4',
@ -2280,10 +2748,10 @@ class HashTest extends CakeTestCase {
'Order.QualityControl' => '0',
'Order.Receiving' => '0',
'Order.ScreenPrinting' => '0',
'Order.Stage.art_approval' => (int) 0,
'Order.Stage.draft' => (int) 1,
'Order.Stage.quote' => (int) 1,
'Order.Stage.order' => (int) 1,
'Order.Stage.art_approval' => 0,
'Order.Stage.draft' => 1,
'Order.Stage.quote' => 1,
'Order.Stage.order' => 1,
'Order.StoreLiason' => '0',
'Order.Tag_UI_Email' => '',
'Order.Tags' => '',