TestController.php 1.71 KB
<?php
/**
 *
 * @author Adhidarma <adhisimon@gmail.com>
 */

class TestController extends Controller {
    function getModel() {
        return null;
    }

    protected function getModels() {
        $models[] = new UserModel();
        $models[] = new RoleModel();
        $models[] = new UserRoleModel();
        $models[] = new AgentModel();
        return $models;
    }

    function oke() {
        die('oke');
    }

    function nothing() {
    }

    function phpinfo() {
        phpinfo(); die;
    }

    function about($f3) {
        $f3->set('VIEW_FILE', 'about.html');
    }

    /**
     * install action.
     */
    function install() {
        $models = $this->getModels();

        foreach ($models as $model) {
            $model->install();
        }

        $this->disableAutoRender();
    }

    /**
     * uninstall action
     */
    function uninstall($f3) {
        $models = $this->getModels();

        foreach ($models as $model) {
            $model->uninstall();
        }

        $this->disableAutoRender();
    }

    /**
     * Test routines.
     */
    function test($f3) {
        $test = new Test();

        // UserRoleModel's test
        $user_role_model = new UserRoleModel();

        $test->expect(
            $user_role_model->doesRoleIdBelongsToUserId(1, 1),
            'User id 1 has role id 1'
        );

        $test->expect(
            !$user_role_model->doesRoleIdBelongsToUserId(200, 1),
            'User id 1 does not has role id 200'
        );

        $test->expect(
            !$user_role_model->doesRoleIdBelongsToUserId(10000, 10000),
            'User id 10000 does not has role id 10000'
        );

        $this->dumpTestResult($test);
        $this->disableAutoRender();
    }
}