Ejemplo n.º 1
0
 protected function setUp()
 {
     $settings = array('config_dir' => dirname(__FILE__) . '/../config');
     Salama::bootstrap($settings);
     # 1. create models, database
     $runner = new SalamaRunner();
     $runner->build();
     User::raw("CREATE DATABASE IF NOT EXISTS `salamatest`")->goraw();
     $runner->syncdb();
     # 2. add test data
     SalamaSuite::$users = array(1 => 'good_bit', 2 => 'evil_bit');
     foreach (SalamaSuite::$users as $k => $username) {
         # transaction support
         #User::begin();
         $user = User::create();
         $user->username = $username;
         $user->login = $k;
         $user->save();
         $u = UserInfo::create();
         $u->total = $k;
         $u->user_id = $user->id;
         # @TODO when relational, this will be automatically set
         $u->save();
         for ($i = 0; $i < 2; $i++) {
             $u = UserComment::create();
             $u->user_id = $user->id;
             # @TODO when relational, this will be automatically set
             $u->comment = "Hello from {$username}!";
             $u->pub_date = $i;
             $u->save();
         }
         $tag = Tag::create();
         $tag->name = "Blue";
         $tag->save();
         $tu = TagUser::create();
         $tu->user_id = $user->id;
         $tu->tag_id = $tag->id;
         // @TODO $tu->tag = $t; should do the same thing
         $tu->golden_path = $username . " bets on " . rand();
         $tu->save();
         $tag2 = Tag::create();
         $tag2->name = "Yellow";
         $tag2->save();
         $tu = TagUser::create();
         $tu->user_id = $user->id;
         $tu->tag_id = $tag2->id;
         $tu->golden_path = $username . " bets on " . rand();
         $tu->save();
         #User::commit();
     }
 }
Ejemplo n.º 2
0
 public static function bootstrap($settings = array())
 {
     if (!isset($settings['config_dir'])) {
         $settings['config_dir'] = dirname(__FILE__) . '/../config';
     }
     # settings
     # @TODO convert settings.xml environment overrides into settings.php additions
     require_once $settings['config_dir'] . '/settings.php';
     Salama::$_settings = SalamaSettings::get_settings();
     # models
     require_once Salama::$_settings['config'] . '/models.php';
     # @TODO add DEBUG=True/False, and if True, re-generated always when doesn't exist.
     $required_build_file = Salama::$_settings['cache'] . "/SalamaData_" . Salama::$_settings['env'] . ".php";
     #if(!file_exists($required_build_file)) {
     $runner = new SalamaRunner();
     $runner->run('build');
     #}
     require_once $required_build_file;
     Salama::$bootstrapped = true;
 }