Remove duplicated test code.

This commit is contained in:
mark_story 2012-04-10 22:26:33 -04:00
parent a4f0399f74
commit f677bfea7d

View file

@ -80,67 +80,24 @@ class SetTest extends CakeTestCase {
/** /**
* testFilter method * testFilter method
* *
* @see Hash test cases, as Set::filter() is just a proxy.
* @return void * @return void
*/ */
public function testFilter() { public function testFilter() {
$result = Set::filter(array('0', false, true, 0, array('one thing', 'I can tell you', 'is you got to be', false))); $result = Set::filter(array('0', false, true, 0, array('one thing', 'I can tell you', 'is you got to be', false)));
$expected = array('0', 2 => true, 3 => 0, 4 => array('one thing', 'I can tell you', 'is you got to be')); $expected = array('0', 2 => true, 3 => 0, 4 => array('one thing', 'I can tell you', 'is you got to be'));
$this->assertSame($expected, $result); $this->assertSame($expected, $result);
$result = Set::filter(array(1, array(false)));
$expected = array(1);
$this->assertEquals($expected, $result);
$result = Set::filter(array(1, array(false, false)));
$expected = array(1);
$this->assertEquals($expected, $result);
$result = Set::filter(array(1, array('empty', false)));
$expected = array(1, array('empty'));
$this->assertEquals($expected, $result);
$result = Set::filter(array(1, array('2', false, array(3, null))));
$expected = array(1, array('2', 2 => array(3)));
$this->assertEquals($expected, $result);
$this->assertSame(array(), Set::filter(array()));
} }
/** /**
* testNumericArrayCheck method * testNumericArrayCheck method
* *
* @see Hash test cases, as Set::numeric() is just a proxy.
* @return void * @return void
*/ */
public function testNumericArrayCheck() { public function testNumericArrayCheck() {
$data = array('one'); $data = array('one');
$this->assertTrue(Set::numeric(array_keys($data))); $this->assertTrue(Set::numeric(array_keys($data)));
$data = array(1 => 'one');
$this->assertFalse(Set::numeric($data));
$data = array('one');
$this->assertFalse(Set::numeric($data));
$data = array('one' => 'two');
$this->assertFalse(Set::numeric($data));
$data = array('one' => 1);
$this->assertTrue(Set::numeric($data));
$data = array(0);
$this->assertTrue(Set::numeric($data));
$data = array('one', 'two', 'three', 'four', 'five');
$this->assertTrue(Set::numeric(array_keys($data)));
$data = array(1 => 'one', 2 => 'two', 3 => 'three', 4 => 'four', 5 => 'five');
$this->assertTrue(Set::numeric(array_keys($data)));
$data = array('1' => 'one', 2 => 'two', 3 => 'three', 4 => 'four', 5 => 'five');
$this->assertTrue(Set::numeric(array_keys($data)));
$data = array('one', 2 => 'two', 3 => 'three', 4 => 'four', 'a' => 'five');
$this->assertFalse(Set::numeric(array_keys($data)));
} }
/** /**
@ -1660,6 +1617,7 @@ class SetTest extends CakeTestCase {
/** /**
* testInsert method * testInsert method
* *
* @see Hash tests, as Set::insert() is just a proxy.
* @return void * @return void
*/ */
public function testInsert() { public function testInsert() {
@ -1669,55 +1627,8 @@ class SetTest extends CakeTestCase {
$result = Set::insert($a, 'files', array('name' => 'files')); $result = Set::insert($a, 'files', array('name' => 'files'));
$expected = array( $expected = array(
'pages' => array('name' => 'page'), 'pages' => array('name' => 'page'),
'files' => array('name' => 'files') 'files' => array('name' => 'files')
);
$this->assertEquals($expected, $result);
$a = array(
'pages' => array('name' => 'page')
);
$result = Set::insert($a, 'pages.name', array());
$expected = array(
'pages' => array('name' => array()),
);
$this->assertEquals($expected, $result);
$a = array(
'pages' => array(
0 => array('name' => 'main'),
1 => array('name' => 'about')
)
);
$result = Set::insert($a, 'pages.1.vars', array('title' => 'page title'));
$expected = array(
'pages' => array(
0 => array('name' => 'main'),
1 => array('name' => 'about', 'vars' => array('title' => 'page title'))
)
);
$this->assertEquals($expected, $result);
}
/**
* Test that insert() can insert data over a string value.
*
* @return void
*/
public function testInsertOverwriteStringValue() {
$data = array(
'Some' => array(
'string' => 'value'
)
);
$result = Set::insert($data, 'Some.string.value', array('values'));
$expected = array(
'Some' => array(
'string' => array(
'value' => array( 'values')
)
)
); );
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
} }
@ -1729,8 +1640,8 @@ class SetTest extends CakeTestCase {
*/ */
public function testRemove() { public function testRemove() {
$a = array( $a = array(
'pages' => array('name' => 'page'), 'pages' => array('name' => 'page'),
'files' => array('name' => 'files') 'files' => array('name' => 'files')
); );
$result = Set::remove($a, 'files'); $result = Set::remove($a, 'files');
@ -1738,26 +1649,6 @@ class SetTest extends CakeTestCase {
'pages' => array('name' => 'page') 'pages' => array('name' => 'page')
); );
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
$a = array(
'pages' => array(
0 => array('name' => 'main'),
1 => array('name' => 'about', 'vars' => array('title' => 'page title'))
)
);
$result = Set::remove($a, 'pages.1.vars');
$expected = array(
'pages' => array(
0 => array('name' => 'main'),
1 => array('name' => 'about')
)
);
$this->assertEquals($expected, $result);
$result = Set::remove($a, 'pages.2.vars');
$expected = $a;
$this->assertEquals($expected, $result);
} }
/** /**
@ -3132,26 +3023,6 @@ class SetTest extends CakeTestCase {
$data[9] = 'Shemp'; $data[9] = 'Shemp';
$result = Set::flatten($data); $result = Set::flatten($data);
$this->assertEquals($data, $result); $this->assertEquals($data, $result);
$data = array(
array(
'Post' => array('id' => '1', 'author_id' => '1', 'title' => 'First Post'),
'Author' => array('id' => '1', 'user' => 'nate', 'password' => 'foo'),
),
array(
'Post' => array('id' => '2', 'author_id' => '3', 'title' => 'Second Post', 'body' => 'Second Post Body'),
'Author' => array('id' => '3', 'user' => 'larry', 'password' => null),
)
);
$result = Set::flatten($data);
$expected = array(
'0.Post.id' => '1', '0.Post.author_id' => '1', '0.Post.title' => 'First Post', '0.Author.id' => '1',
'0.Author.user' => 'nate', '0.Author.password' => 'foo', '1.Post.id' => '2', '1.Post.author_id' => '3',
'1.Post.title' => 'Second Post', '1.Post.body' => 'Second Post Body', '1.Author.id' => '3',
'1.Author.user' => 'larry', '1.Author.password' => null
);
$this->assertEquals($expected, $result);
} }
/** /**
@ -3164,40 +3035,6 @@ class SetTest extends CakeTestCase {
$flat = Set::flatten($data); $flat = Set::flatten($data);
$result = Set::expand($flat); $result = Set::expand($flat);
$this->assertEqual($data, $result); $this->assertEqual($data, $result);
$data = array(
'0.Post.id' => '1', '0.Post.author_id' => '1', '0.Post.title' => 'First Post', '0.Author.id' => '1',
'0.Author.user' => 'nate', '0.Author.password' => 'foo', '1.Post.id' => '2', '1.Post.author_id' => '3',
'1.Post.title' => 'Second Post', '1.Post.body' => 'Second Post Body', '1.Author.id' => '3',
'1.Author.user' => 'larry', '1.Author.password' => null
);
$result = Set::expand($data);
$expected = array(
array(
'Post' => array('id' => '1', 'author_id' => '1', 'title' => 'First Post'),
'Author' => array('id' => '1', 'user' => 'nate', 'password' => 'foo'),
),
array(
'Post' => array('id' => '2', 'author_id' => '3', 'title' => 'Second Post', 'body' => 'Second Post Body'),
'Author' => array('id' => '3', 'user' => 'larry', 'password' => null),
)
);
$this->assertEqual($result, $expected);
$data = array(
'0/Post/id' => 1,
'0/Post/name' => 'test post'
);
$result = Set::expand($data, '/');
$expected = array(
array(
'Post' => array(
'id' => 1,
'name' => 'test post'
)
)
);
$this->assertEqual($result, $expected);
} }
/** /**