Skip to content

Commit

Permalink
Adding tests for Set::normalize()
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Nov 21, 2010
1 parent 6d9b000 commit ef3cb0e
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions cake/tests/cases/libs/set.test.php
Expand Up @@ -2988,4 +2988,50 @@ function testFlatten() {
);
$this->assertEqual($result, $expected);
}

/**
* test normalization
*
* @return void
*/
function testNormalizeStrings() {
$result = Set::normalize('one,two,three');
$expected = array('one' => null, 'two' => null, 'three' => null);
$this->assertEqual($expected, $result);

$result = Set::normalize('one two three', true, ' ');
$expected = array('one' => null, 'two' => null, 'three' => null);
$this->assertEqual($expected, $result);

$result = Set::normalize('one , two , three ', true, ',', true);
$expected = array('one' => null, 'two' => null, 'three' => null);
$this->assertEqual($expected, $result);
}

/**
* test normalizing arrays
*
* @return void
*/
function testNormalizeArrays() {
$result = Set::normalize(array('one', 'two', 'three'));
$expected = array('one' => null, 'two' => null, 'three' => null);
$this->assertEqual($expected, $result);

$result = Set::normalize(array('one', 'two', 'three'), false);
$expected = array('one', 'two', 'three');
$this->assertEqual($expected, $result);

$result = Set::normalize(array('one' => 1, 'two' => 2, 'three' => 3, 'four'), false);
$expected = array('one' => 1, 'two' => 2, 'three' => 3, 'four' => null);
$this->assertEqual($expected, $result);

$result = Set::normalize(array('one' => 1, 'two' => 2, 'three' => 3, 'four'));
$expected = array('one' => 1, 'two' => 2, 'three' => 3, 'four' => null);
$this->assertEqual($expected, $result);

$result = Set::normalize(array('one' => array('a', 'b', 'c' => 'cee'), 'two' => 2, 'three'));
$expected = array('one' => array('a', 'b', 'c' => 'cee'), 'two' => 2, 'three' => null);
$this->assertEqual($expected, $result);
}
}

0 comments on commit ef3cb0e

Please sign in to comment.