Phalcon\Test\Unit\Mvc\ModelTest::testMassAssignmentRenamed PHP Method

testMassAssignmentRenamed() public method

    public function testMassAssignmentRenamed()
    {
        $this->specify("Models can't properly assign properties using a column map", function () {
            $robot = new Robotters();
            $success = $robot->save(["theType" => "mechanical", "theYear" => 2018]);
            expect($success)->false();
            expect($robot->theType)->equals("mechanical");
            expect($robot->theYear)->equals(2018);
            // assign uses column renaming
            $robot = new Robotters();
            $robot->assign(["theType" => "mechanical", "theYear" => 2018]);
            expect($robot->theType)->equals("mechanical");
            expect($robot->theYear)->equals(2018);
            // not assigns nonexistent fields
            $robot = new Robotters();
            $robot->assign(["field1" => "mechanical", "field2" => 2018]);
            expect(empty($robot->field1))->true();
            expect(empty($robot->field2))->true();
            // white list
            $robot = new Robotters();
            $robot->assign(["theType" => "mechanical", "theYear" => 2018], null, ["theType"]);
            expect($robot->theType)->equals("mechanical");
            expect(empty($robot->theYear))->true();
            // white list & custom mapping
            $robot = new Robotters();
            $robot->assign(["theTypeFromClient" => "mechanical", "theYearFromClient" => 2018], ["theTypeFromClient" => "theType", "theYearFromClient" => "theYear"], ["theType"]);
            expect($robot->theType)->equals("mechanical");
            expect(empty($robot->theYear))->true();
        });
    }