atk4\data\tests\ConditionSQLTest::testBasic PHP Method

testBasic() public method

public testBasic ( )
    public function testBasic()
    {
        $a = ['user' => [1 => ['id' => 1, 'name' => 'John', 'gender' => 'M'], 2 => ['id' => 2, 'name' => 'Sue', 'gender' => 'F']]];
        $this->setDB($a);
        $db = new Persistence_SQL($this->db->connection);
        $m = new Model($db, 'user');
        $m->addFields(['name', 'gender']);
        $m->tryLoad(1);
        $this->assertEquals('John', $m['name']);
        $m->tryLoad(2);
        $this->assertEquals('Sue', $m['name']);
        $mm = clone $m;
        $mm->addCondition('gender', 'M');
        $mm->tryLoad(1);
        $this->assertEquals('John', $mm['name']);
        $mm->tryLoad(2);
        $this->assertEquals(null, $mm['name']);
        $this->assertEquals('select `id`,`name`,`gender` from `user` where `gender` = :a', $mm->action('select')->render());
        $mm = clone $m;
        $mm->withID(2);
        // = addCondition(id, 2)
        $mm->tryLoad(1);
        $this->assertEquals(null, $mm['name']);
        $mm->tryLoad(2);
        $this->assertEquals('Sue', $mm['name']);
    }