lithium\tests\cases\util\SetTest::testFormat PHP Method

testFormat() public method

public testFormat ( )
    public function testFormat()
    {
        $data = array(array('Person' => array('first_name' => 'Nate', 'last_name' => 'Abele', 'city' => 'Queens', 'state' => 'NY', 'something' => '42')), array('Person' => array('first_name' => 'Joel', 'last_name' => 'Perras', 'city' => 'Montreal', 'state' => 'Quebec', 'something' => '{0}')), array('Person' => array('first_name' => 'Garrett', 'last_name' => 'Woodworth', 'city' => 'Venice Beach', 'state' => 'CA', 'something' => '{1}')));
        $result = Set::format($data, '{1}, {0}', array('/Person/first_name', '/Person/last_name'));
        $expected = array('Abele, Nate', 'Perras, Joel', 'Woodworth, Garrett');
        $this->assertEqual($expected, $result);
        $result = Set::format($data, '{0}, {1}', array('/Person/last_name', '/Person/first_name'));
        $this->assertEqual($expected, $result);
        $result = Set::format($data, '{0}, {1}', array('/Person/city', '/Person/state'));
        $expected = array('Queens, NY', 'Montreal, Quebec', 'Venice Beach, CA');
        $this->assertEqual($expected, $result);
        $result = Set::format($data, '{{0}, {1}}', array('/Person/city', '/Person/state'));
        $expected = array('{Queens, NY}', '{Montreal, Quebec}', '{Venice Beach, CA}');
        $this->assertEqual($expected, $result);
        $result = Set::format($data, '{{0}, {1}}', array('/Person/something', '/Person/something'));
        $expected = array('{42, 42}', '{{0}, {0}}', '{{1}, {1}}');
        $this->assertEqual($expected, $result);
        $result = Set::format($data, '{%2$d, %1$s}', array('/Person/something', '/Person/something'));
        $expected = array('{42, 42}', '{0, {0}}', '{0, {1}}');
        $this->assertEqual($expected, $result);
        $result = Set::format($data, '{%1$s, %1$s}', array('/Person/something', '/Person/something'));
        $expected = array('{42, 42}', '{{0}, {0}}', '{{1}, {1}}');
        $this->assertEqual($expected, $result);
        $result = Set::format($data, '%2$d, %1$s', array('/Person/first_name', '/Person/something'));
        $expected = array('42, Nate', '0, Joel', '0, Garrett');
        $this->assertEqual($expected, $result);
        $result = Set::format($data, '%1$s, %2$d', array('/Person/first_name', '/Person/something'));
        $expected = array('Nate, 42', 'Joel, 0', 'Garrett, 0');
        $this->assertEqual($expected, $result);
    }