function test_should_establish_multiple_connections()
    {
        if(AK_PHP5){
            $db_settings = Ak::convert('yaml', 'array', AK_CONFIG_DIR.DS.'database.yml');
            $db_settings['sqlite_databases'] = array(
                    'database_file' => AK_TMP_DIR.DS.'testing_sqlite_database.sqlite',
                    'type' => 'sqlite'
                    );
            file_put_contents(AK_CONFIG_DIR.DS.'database.yml', Ak::convert('array', 'yaml', $db_settings));
        
       
            $this->installAndIncludeModels(array('TestOtherConnection'));

            Ak::import('test_other_connection');
            $OtherConnection = new TestOtherConnection(array('name'=>'Delia'));
            $this->assertTrue($OtherConnection->save());
        
        
            $this->installAndIncludeModels(array('DummyModel'=>'id,name'));
            $Dummy = new DummyModel();
        
            $this->assertNotEqual($Dummy->getConnection(), $OtherConnection->getConnection());
        
            unset($db_settings['sqlite_databases']);
            file_put_contents(AK_CONFIG_DIR.DS.'database.yml', Ak::convert('array', 'yaml', $db_settings));
        }
    }
Example #2
0
 public function _getMenuOptionsForControllersInModule($type = 'admin')
 {
     $controllers = AkFileSystem::dir(AK_CONTROLLERS_DIR . DS . $this->_controller->getModuleName(), array('dirs' => false));
     sort($controllers);
     $menu_options = array();
     foreach ($controllers as $controller) {
         $controller_name = substr($controller, 0, -15);
         $menu_options[AkInflector::titleize($controller_name)] = array('id' => $controller_name, 'url' => array('controller' => $controller_name));
     }
     $options_file = $this->_getMenuOptionsFile($type);
     if (!file_exists($options_file)) {
         AkFileSystem::file_put_contents(AK_CONFIG_DIR . DS . $options_file, Ak::convert('array', 'yaml', array('default' => $menu_options)));
     }
     return $menu_options;
 }
Example #3
0
 public function convert($options)
 {
     static $_tags = array();
     $header = !isset($options['header']) ? "<?xml version=\"1.0\"?>\r\n" : $options['header'];
     $parent = !isset($options['parent']) ? 'EMPTY_TAG' : $options['parent'];
     $xml = $header;
     foreach ($this->source as $key => $value) {
         $key = is_numeric($key) ? $parent : $key;
         $value = is_array($value) ? "\r\n" . Ak::convert('array', 'xml', $this->source, array('header' => '', 'parent' => $parent)) : $value;
         $_tags[$key] = $key;
         $xml .= sprintf("<%s>%s</%s>\r\n", $key, $value, $key);
         $parent = $key;
     }
     foreach ($_tags as $_tag) {
         $xml = str_replace(array("<{$_tag}>\r\n<{$_tag}>", "</{$_tag}>\r\n</{$_tag}>"), array("<{$_tag}>", "</{$_tag}>"), $xml);
     }
     return $xml;
 }
Example #4
0
    function populateTables()
    {
        $args = func_get_args();
        $tables = !empty($args) ? (is_array($args[0]) ? $args[0] : (count($args) > 1 ? $args : Ak::toArray($args))) : array();
        foreach ($tables as $table){
            $file = AK_TEST_DIR.DS.'fixtures'.DS.'data'.DS.(empty($this->module)?'':$this->module.DS).Ak::sanitize_include($table).'.yaml';
            if(!file_exists($file)){
                continue;
            }
            $class_name = AkInflector::modulize($table);
            if($this->instantiateModel($class_name)){
                $items = Ak::convert('yaml','array',file_get_contents($file));
                foreach ($items as $item){
                    $this->{$class_name}->create($item);
                }
            }

        }
    }
Example #5
0
 public function test_should_establish_multiple_connections()
 {
     $db_file_existed = false;
     if (file_exists(AkConfig::getDir('config') . DS . 'database.yml')) {
         $db_file_existed = true;
         $db_settings = Ak::convert('yaml', 'array', AkConfig::getDir('config') . DS . 'database.yml');
     }
     $db_settings['sqlite_databases'] = array('database_file' => AK_TMP_DIR . DS . 'testing_sqlite_database.sqlite', 'type' => 'sqlite');
     file_put_contents(AkConfig::getDir('config') . DS . 'database.yml', Ak::convert('array', 'yaml', $db_settings));
     @unlink(AK_TMP_DIR . DS . 'testing_sqlite_database.sqlite');
     $this->installAndIncludeModels(array('TestOtherConnection'));
     Ak::import('test_other_connection');
     $OtherConnection = new TestOtherConnection(array('name' => 'Delia'));
     $this->assertTrue($OtherConnection->save());
     $this->installAndIncludeModels(array('DummyModel' => 'id,name'));
     $Dummy = new DummyModel();
     $this->assertNotEqual($Dummy->getConnection(), $OtherConnection->getConnection());
     unset($db_settings['sqlite_databases']);
     if ($db_file_existed) {
         file_put_contents(AkConfig::getDir('config') . DS . 'database.yml', Ak::convert('array', 'yaml', $db_settings));
     } else {
         unlink(AkConfig::getDir('config') . DS . 'database.yml');
     }
 }
Example #6
0
 function populateTables()
 {
     
     $args = func_get_args();
     $tables = !empty($args) ? (is_array($args[0]) ? $args[0] : (count($args) > 1 ? $args : Ak::toArray($args))) : array();
     foreach ($tables as $table){
         $file = AK_TEST_DIR.DS.'fixtures'.DS.'data'.DS.(empty($this->module)?'':$this->module.DS).Ak::sanitize_include($table).'.yaml';
         if(!file_exists($file)){
             continue;
         }
         $class_name = AkInflector::classify($table);
         if($this->instantiateModel($class_name)){
             $contents = &Ak::getStaticVar('yaml_fixture_'.$file);
             if (!$contents) {
                 ob_start();
                 require_once($file);
                 $contents = ob_get_clean();
                 Ak::setStaticVar('yaml_fixture_'.$file, $contents);
             }
             $items = Ak::convert('yaml','array',$contents);
             foreach ($items as $item){
                 
                 $obj=&$this->{$class_name}->create($item);
                 if (isset($item['created_at'])) {
                     $obj->updateAttribute('created_at',$item['created_at']);
                 } else if (isset($item['created_on'])) {
                     $obj->updateAttribute('created_on',$item['created_on']);
                 }
             }
         }
     }
 }
Example #7
0
 function _loadDbDesignerDbSchema()
 {
     if($path = $this->_getDbDesignerFilePath()){
         $this->db_designer_schema = Ak::convert('DBDesigner','AkelosDatabaseDesign', Ak::file_get_contents($path));
         return !empty($this->db_designer_schema);
     }
     return false;
 }
Example #8
0
 /**
  * converts to yaml-strings
  *
  * examples:
  * User::toYaml($users->find('all'));
  * $Bermi->toYaml();
  *
  * @param array of ActiveRecords[optional] $data
  */
 function toYaml($data = null)
 {
     return Ak::convert('active_record', 'yaml', empty($data) ? $this : $data);
 }
 public function parseXml($xml_string)
 {
     return Ak::convert('xml', 'params_array', $xml_string);
 }
Example #10
0
 private function parseMessageBody($data)
 {
     if (empty($data)) {
         return array();
     }
     $content_type = $this->getContentType();
     switch ($this->lookupMimeType($content_type)) {
         case 'html':
             $as_array = array();
             parse_str($data, $as_array);
             return $as_array;
         case 'xml':
             return Ak::convert('xml', 'params_array', $data);
             break;
         case 'json':
             return json_decode($data, true);
         default:
             return array('put_body' => $data);
             break;
     }
 }
Example #11
0
    public function test_html_to_text_using_smartipants()
    {
        $html = <<<EOF
"I'm completelly agree"
EOF;
        $markdown = <<<EOF
“I’m completelly agree”
EOF;
        $this->assertEqual(Ak::convert('html', 'text', $html), $markdown);
    }
Example #12
0
 /**
  * Performs an update of available cached plugins.
  * 
  * @return boolean   
  * @access private
  */
 function _updateRemotePluginsList()
 {
     $new_plugins = array();
     foreach ($this->getAvailableRepositories() as $repository){
         $this->_addAvailablePlugins_($repository, $new_plugins);
     }
     if(empty($new_plugins)){
         trigger_error(Ak::t('Could not fetch remote plugins from one of these repositories: %repositories', array('%repositories' => "\n".join("\n", $this->getAvailableRepositories()))), E_USER_NOTICE);
         return false;
     }
     return Ak::file_put_contents($this->_getRepositoriesCahePath(), Ak::convert('array', 'yaml', $new_plugins));
 }
Example #13
0
 static function getPossibleCases($options = array())
 {
     $default_options = array('config' => AK_TEST_DIR . DS . (AK_UNIT_TEST_SUITE_GLOBAL_NAMESPACE == 'Akelos' ? 'core_tests' : AkInflector::underscore(AK_UNIT_TEST_SUITE_GLOBAL_NAMESPACE)) . '.yml', 'base_path' => AK_TEST_DIR);
     $options = array_merge($default_options, $options);
     return array_map(array('AkInflector', 'camelize'), (array) array_keys(Ak::convert('yaml', 'array', file_get_contents($options['config']))));
 }
Example #14
0
 function loadFixture($model_name)
 {
     if (!($fixture_file_name = $this->findFixtureForModel($model_name))) {
         return false;
     }
     $Model = new $model_name();
     $Fixture = array();
     $items = Ak::convert('yaml', 'array', file_get_contents($fixture_file_name));
     foreach ($items as $id => $item) {
         $Record = $Model->create($item);
         #we replace the 'id' with the returned value from the db
         $item['id'] = $Record->getId();
         $Fixture[$id] = new FixedActiveRecord($item, $Model);
     }
     return $this->{AkInflector::pluralize($model_name)} = $Fixture;
 }
 private function _compareXml($expected, $given)
 {
     $expected = Ak::convert('xml', 'array', $expected);
     $given = Ak::convert('xml', 'array', $given);
     $this->assertEqual($expected, $given);
 }
Example #16
0
 /**
  * Performs an update of available cached plugins.
  *
  * @return boolean
  * @access private
  */
 private function _updateRemotePluginsList()
 {
     $new_plugins = array();
     foreach ($this->getAvailableRepositories() as $repository) {
         $this->_addAvailablePlugins_($repository, $new_plugins);
     }
     if (empty($new_plugins)) {
         AkConsole::displayError(Ak::t('Could not fetch remote plugins from one of these repositories: %repositories', array('%repositories' => "\n" . join("\n", $this->getAvailableRepositories()))), true);
     }
     return AkFileSystem::file_put_contents($this->_getRepositoriesCahePath(), Ak::convert('array', 'yaml', $new_plugins));
 }
Example #17
0
 function testConverterAcceptsXmlObjectAsInput()
 {
     $xml_string = '<person><name>Steve</name></person>';
     $xml = new SimpleXMLElement($xml_string);
     $expected = array('person' => array('name' => 'Steve'));
     $this->assertEquals($expected, Ak::convert('Xml', 'ParamsArray', $xml));
 }
Example #18
0
 function toYaml()
 {
     return Ak::convert('active_record', 'yaml', $this);
 }