lithium\tests\cases\data\source\mongo_db\ExporterTest::testTypeCasting PHP Метод

testTypeCasting() публичный Метод

Tests handling type values based on specified schema settings.
public testTypeCasting ( )
    public function testTypeCasting()
    {
        $time = time();
        $data = array('_id' => '4c8f86167675abfabd970300', 'title' => 'Foo', 'tags' => 'test', 'comments' => array("4c8f86167675abfabdbe0300", "4c8f86167675abfabdbf0300", "4c8f86167675abfabdc00300"), 'empty_array' => array(), 'authors' => '4c8f86167675abfabdb00300', 'created' => $time, 'modified' => date('Y-m-d H:i:s', $time), 'rank_count' => '45', 'rank' => '3.45688');
        $model = $this->_model;
        $handlers = $this->_handlers;
        $options = compact('model', 'handlers');
        $schema = new Schema(array('fields' => $this->_schema));
        $result = $schema->cast(null, null, $data, $options);
        $this->assertEqual(array_keys($data), array_keys($result->data()));
        $this->assertInstanceOf('MongoId', $result->_id);
        $this->assertEqual('4c8f86167675abfabd970300', (string) $result->_id);
        $this->assertInstanceOf('lithium\\data\\collection\\DocumentSet', $result->comments);
        $this->assertCount(3, $result['comments']);
        $this->assertInstanceOf('MongoId', $result->comments[0]);
        $this->assertInstanceOf('MongoId', $result->comments[1]);
        $this->assertInstanceOf('MongoId', $result->comments[2]);
        $this->assertEqual('4c8f86167675abfabdbe0300', (string) $result->comments[0]);
        $this->assertEqual('4c8f86167675abfabdbf0300', (string) $result->comments[1]);
        $this->assertEqual('4c8f86167675abfabdc00300', (string) $result->comments[2]);
        $this->assertEqual($data['comments'], $result->comments->data());
        $this->assertEqual(array('test'), $result->tags->data());
        $this->assertEqual(array('4c8f86167675abfabdb00300'), $result->authors->data());
        $this->assertInstanceOf('MongoId', $result->authors[0]);
        $this->assertInstanceOf('MongoDate', $result->modified);
        $this->assertInstanceOf('MongoDate', $result->created);
        $this->assertGreaterThan($result->created->sec, 0);
        $this->assertInstanceOf('lithium\\data\\collection\\DocumentSet', $result->empty_array);
        $this->assertEqual($time, $result->modified->sec);
        $this->assertEqual($time, $result->created->sec);
        $this->assertIdentical(45, $result->rank_count);
        $this->assertIdentical(3.45688, $result->rank);
    }