Exemple #1
0
 /**
  * 
  * Generates a link to the TypeKey login site.
  * 
  * @param string $text The text to display for the link.
  * 
  * @param array $attribs Attributes for the anchor.
  * 
  * @return string
  * 
  */
 public function typekeyLink($text = null, $attribs = null)
 {
     // get a URI processor; defaults to the current URI.
     $uri = Solar::factory('Solar_Uri');
     // do not retain the GET 'process' value on the current URI.
     // this prevents double-processing of actions submitted via GET.
     $key = $this->_config['process_key'];
     if (!empty($uri->query[$key])) {
         unset($uri->query[$key]);
     }
     // save the current URI as the return location after typekey.
     $return = $uri->get(true);
     // now reset the URI to point to the typekey service
     $uri->set($this->_config['href']);
     // add the typekey token
     if (empty($this->_config['token'])) {
         $uri->query['t'] = Solar_Config::get('Solar_Auth_Adapter_Typekey', 'token');
     } else {
         $uri->query['t'] = $this->_config['token'];
     }
     // convert need_email from true/false to 1/0 and add
     $uri->query['need_email'] = (int) $this->_config['need_email'];
     // add the return location
     $uri->query['_return'] = $return;
     if (empty($text)) {
         // Preserve behavior of returning only the link if no text is passed.
         return $uri->get(true);
     }
     // done!
     return $this->_view->anchor($uri->get(true), $text, $attribs);
 }
Exemple #2
0
 /**
  * 
  * Verifies set of credentials.
  *
  * @param array $credentials A list of credentials to verify
  * 
  * @return mixed An array of verified user information, or boolean false
  * if verification failed.
  * 
  */
 public function validateCredentials($credentials)
 {
     if (empty($credentials['handle'])) {
         return false;
     }
     if (empty($credentials['passwd'])) {
         return false;
     }
     $handle = $credentials['handle'];
     $passwd = $credentials['passwd'];
     // create an array of POST data
     $content = array($this->_config['handle'] => $handle, $this->_config['passwd'] => $passwd);
     // build the base request
     $request = Solar::factory('Solar_Http_Request');
     $request->setUri($this->_config['uri'])->setMethod('post')->setContent($content);
     // add custom headers
     foreach ((array) $this->_config['headers'] as $label => $value) {
         $request->setHeader($label, $value);
     }
     // fetch the response body content
     $response = $request->fetch();
     $reply = trim($response->content);
     // is the reply string a known reply, and set to true?
     $ok = array_key_exists($reply, $this->_config['replies']) && (bool) $this->_config['replies'][$reply];
     if ($ok) {
         return array('handle' => $handle);
     } else {
         return false;
     }
 }
Exemple #3
0
 /**
  * 
  * Tidy extension must be loaded.  This allows us to ignore
  * tag-level whitepspace differences.
  * 
  */
 public function setup()
 {
     if (!extension_loaded('tidy')) {
         $this->markTestSkipped("Tidy extension not loaded");
     }
     $this->_markdown = Solar::factory('Solar_Markdown_Wiki');
 }
Exemple #4
0
 /**
  * 
  * Displays a list of help options for a command, or the list of commands
  * if no command was requested.
  * 
  * @param string $cmd The requested command.
  * 
  * @return void
  * 
  */
 protected function _displayCommandHelp($cmd = null)
 {
     $this->_outln();
     // the list of known command-to-class mappings
     $list = $this->_console->getCommandList();
     // is this a known command?
     if (empty($list[$cmd])) {
         $this->_outln('ERR_UNKNOWN_COMMAND', 1, array('cmd' => $cmd));
         return;
     }
     $class = $list[$cmd];
     $obj = Solar::factory($class);
     $help = $obj->getInfoHelp();
     if ($help) {
         $this->_outln($help);
     } else {
         $this->_outln('ERR_NO_HELP');
     }
     $this->_outln();
     $opts = $obj->getInfoOptions();
     if ($opts) {
         $this->_outln('HELP_VALID_OPTIONS');
         $this->_outln();
         foreach ($opts as $key => $val) {
             $this->_outln($key);
             $val = str_replace("\n", "\n  ", wordwrap(": {$val}"));
             $this->_outln($val);
             $this->_outln();
         }
     }
 }
Exemple #5
0
 /**
  * 
  * Runs the tests for a class, descending into subdirectories unless
  * otherwise specified.
  * 
  * @param string $spec The Test_Class or Test_Class::testMethod to run.
  * 
  * @return void
  * 
  */
 protected function _exec($spec = null)
 {
     if (!$spec) {
         throw $this->_exception('ERR_NO_TEST_SPEC');
     }
     // look for a :: in the class name; if it's there, split into class
     // and method
     $pos = strpos($spec, '::');
     if ($pos) {
         $class = substr($spec, 0, $pos);
         $method = substr($spec, $pos + 2);
     } else {
         $class = $spec;
         $method = null;
     }
     // run just the one test?
     $only = (bool) $this->_options['only'];
     // look for a test-config file?
     $test_config = null;
     if ($this->_options['test_config']) {
         // find the real path to the test_config file
         $test_config = realpath($this->_options['test_config']);
         if ($test_config === false) {
             throw $this->_exception('ERR_TEST_CONFIG_REALPATH', array('file' => $this->_options['test_config']));
         }
     }
     // set up a test suite object
     $suite = Solar::factory('Solar_Test_Suite', array('verbose' => $this->_options['verbose'], 'test_config' => $test_config, 'stop_on_fail' => $this->_options['stop_on_fail']));
     // run the suite
     $suite->run($class, $method, $only);
 }
Exemple #6
0
 /**
  * 
  * Setup; runs before each test method.
  * 
  */
 public function setup()
 {
     $this->_sql = Solar::factory('Solar_Sql', array('adapter' => 'Solar_Sql_Adapter_Sqlite', 'name' => ':memory:'));
     // forcibly add sql to registry
     Solar_Registry::set('sql', $this->_sql);
     $cmd = "CREATE TABLE acl (" . "    flag VARCHAR(10)," . "    type CHAR(100)," . "    name VARCHAR(255)," . "    class_name VARCHAR(255)," . "    action_name VARCHAR(255)," . "    position VARCHAR(255)" . ")";
     $this->_sql->query($cmd);
     $dir = Solar_Class::dir('Test_Solar_Access_Adapter', '_support');
     $lines = file_get_contents($dir . 'access.txt');
     $rows = explode("\n", $lines);
     $pos = 0;
     foreach ($rows as $row) {
         $row = trim($row);
         // skip empty lines and comments
         if (empty($row) || substr($row, 0, 1) == '#') {
             continue;
         }
         $row = preg_replace('/[ \\t]{2,}/', ' ', $row);
         $row = explode(' ', $row);
         $data['flag'] = trim($row[0]);
         $data['type'] = trim($row[1]);
         $data['name'] = trim($row[2]);
         $data['class_name'] = trim($row[3]);
         $data['action_name'] = trim($row[4]);
         $data['position'] = $pos;
         $this->_sql->insert('acl', $data);
         $pos++;
     }
     parent::setup();
 }
 /**
  * 
  * Write out a series of dirs and symlinks for a new Vendor source.
  * 
  * @param string $vendor The Vendor name.
  * 
  * @return void
  * 
  */
 protected function _exec($vendor = null)
 {
     // we need a vendor name, at least
     if (!$vendor) {
         throw $this->_exception('ERR_NO_VENDOR');
     }
     $this->_outln("Making links for vendor '{$vendor}' ...");
     // build "foo-bar" and "FooBar" versions of the vendor name.
     $this->_inflect = Solar_Registry::get('inflect');
     $this->_dashes = $this->_inflect->camelToDashes($vendor);
     $this->_studly = $this->_inflect->dashesToStudly($this->_dashes);
     $links = array(array('dir' => "include", 'tgt' => $this->_studly, 'src' => "../source/{$this->_dashes}/{$this->_studly}"), array('dir' => "include/Test", 'tgt' => $this->_studly, 'src' => "../../source/{$this->_dashes}/tests/Test/{$this->_studly}"), array('dir' => "include/Mock", 'tgt' => $this->_studly, 'src' => "../../source/{$this->_dashes}/tests/Mock/{$this->_studly}"), array('dir' => "include/Fixture", 'tgt' => $this->_studly, 'src' => "../../source/{$this->_dashes}/tests/Fixture/{$this->_studly}"), array('dir' => "script", 'tgt' => $this->_dashes, 'src' => "../source/solar/script/solar"));
     $system = Solar::$system;
     foreach ($links as $link) {
         // $dir, $src, $tgt
         extract($link);
         // make it
         $this->_out("    Making link '{$dir}/{$tgt}' ... ");
         try {
             Solar_Symlink::make($src, $tgt, "{$system}/{$dir}");
             $this->_outln("done.");
         } catch (Exception $e) {
             $this->_out($e->getMessage());
             $this->_outln(" ... failed.");
         }
     }
     // done with this part
     $this->_outln("... done.");
     // make public links
     $link_public = Solar::factory('Solar_Cli_LinkPublic');
     $link_public->exec($vendor);
     // done for real
     $this->_outln("Remember to add '{$this->_studly}_App' to the " . "['Solar_Controller_Front']['classes'] element " . "in your config file so that it finds your apps.");
     $this->_outln("Remember to add '{$this->_studly}_Model' to the " . "['Solar_Sql_Model_Catalog']['classes'] element " . "in your config file so that it finds your models.");
 }
Exemple #8
0
 public function preTest()
 {
     parent::preTest();
     $this->_filter = Solar::factory('Solar_Filter');
     $this->_plugin = $this->_filter->getFilter($this->_plugin_name);
     $this->_filter->setRequire(true);
 }
Exemple #9
0
 /**
  * 
  * Runs each benchmark method for a certain number of loops.
  * 
  * @param int $loops Loop benchmark methods this number of times.
  * 
  * @return string The Solar_Debug_Timer profile table; smaller diffs
  * are better.
  * 
  */
 public function loop($loops = null)
 {
     if (empty($loops)) {
         $loops = $this->_config['loop'];
     }
     // get the list of bench*() methods
     $bench = $this->_getMethods();
     // get a timer object
     $timer = Solar::factory('Solar_Debug_Timer', array('auto_start' => false));
     // pre-run
     $this->setup();
     // start timing
     $timer->start();
     // run each benchmark method...
     foreach ($bench as $method) {
         // ... multiple times.
         for ($i = 0; $i < $loops; ++$i) {
             $this->{$method}();
         }
         // how long did the method run take?
         $timer->mark($method);
     }
     // stop timing
     $timer->stop();
     // post-run
     $this->teardown();
     // done!
     return $timer->fetch();
 }
Exemple #10
0
 /**
  * 
  * Test -- Constructor.
  * 
  */
 public function test__construct()
 {
     $view = Solar::factory('Solar_View');
     $class = substr(get_class($this), 5);
     $obj = Solar::factory($class, array('_view' => $view));
     $this->assertInstance($obj, $class);
 }
Exemple #11
0
 /**
  * insertPostTags
  *
  * @param $post_id
  * @param $post_data
  */
 public function insertPostTags($post_id, $tags)
 {
     $post_id = (int) $post_id;
     $tag_map = array();
     $tags_table = Solar::factory('Foresmo_Model_Tags');
     $existing_tags = $tags_table->fetchAllAsArray();
     foreach ($existing_tags as $existing_tag) {
         foreach ($tags as $tag) {
             if (strtolower($tag) == strtolower($existing_tag['tag'])) {
                 $tag_map[$tag] = $existing_tag['id'];
             }
         }
     }
     foreach ($tags as $tag) {
         if (array_key_exists($tag, $tag_map)) {
             $data = array('post_id' => $post_id, 'tag_id' => $tag_map[$tag]);
             $this->insert($data);
         } else {
             $data = array('tag' => $tag, 'tag_slug' => Foresmo::makeSlug($tag));
             $last_insert_id = $tags_table->insert($data);
             $data = array('post_id' => $post_id, 'tag_id' => $last_insert_id);
             $this->insert($data);
         }
     }
 }
Exemple #12
0
 public function testGetTextRaw_badLocaleKey()
 {
     Solar::start(false);
     $actual = $this->_view->getTextRaw('no such "locale" key');
     $expect = 'no such "locale" key';
     $this->assertSame($actual, $expect);
 }
Exemple #13
0
 /**
  * _postConstruct
  *
  * @param $model
  */
 protected function _postConstruct()
 {
     parent::_postConstruct();
     $this->_model = $this->_config['model'];
     $this->_view_path = Solar_Class::dir($this, 'View');
     $this->_view_file = 'index.php';
     $this->_view = Solar::factory('Solar_View', array('template_path' => $this->_view_path));
 }
Exemple #14
0
 /**
  * 
  * Post-construction tasks to complete object construction.
  * 
  * @return void
  * 
  */
 protected function _postConstruct()
 {
     parent::_postConstruct();
     // only set up the handler if it doesn't exist yet.
     if (!self::$_handler) {
         self::$_handler = Solar::dependency('Solar_Session_Handler', $this->_config['handler']);
     }
     $this->_request = Solar_Registry::get('request');
 }
Exemple #15
0
 protected function _postConstruct()
 {
     parent::_postConstruct();
     // "Test_Solar_View_Helper_" = 23
     $this->_helper_name = substr(get_class($this), 23);
     $this->_helper_class = substr(get_class($this), 5);
     $this->_request = Solar_Registry::get('request');
     $this->_view = Solar::factory('Solar_View');
 }
Exemple #16
0
 public function testHref_uri()
 {
     $uri = Solar::factory('Solar_Uri');
     $uri->setPath('/path/to/script.php');
     $uri->setQuery('page=1');
     $actual = $this->_view->href($uri);
     $expect = '/path/to/script.php?page=1';
     $this->assertSame($actual, $expect);
 }
Exemple #17
0
 /**
  * _postConstruct
  *
  * @param $model
  */
 protected function _postConstruct()
 {
     parent::_postConstruct();
     $this->_model = $this->_config['model'];
     $this->_view_path = Solar_Class::dir($this, 'View');
     $this->_view_file = 'index.php';
     $this->_view = Solar::factory('Solar_View', array('template_path' => $this->_view_path));
     $this->register = array('_preRender' => array('index' => array('main' => 'preRender')), '_postRender' => array('index' => array('main' => 'postRender')), '_preRun' => array('index' => array('main' => 'preRun')), '_postRun' => array('index' => array('main' => 'postRun')), '_postAction' => array('index' => array('main' => 'postAction')));
 }
Exemple #18
0
 public function testDeleteAll_recursive()
 {
     // change the config to turn off hashing
     $this->_config['hash'] = false;
     // rebuild the adapter
     $this->_adapter = Solar::factory($this->_adapter_class, $this->_config);
     // now try deleteAll() again
     $this->testDeleteAll();
 }
Exemple #19
0
 public function testSetEvents_string()
 {
     $log = Solar::factory($this->_adapter);
     $expect = array('debug', 'info', 'notice');
     $string = implode(', ', $expect);
     $log->setEvents($string);
     $actual = $log->getEvents();
     $this->assertSame($actual, $expect);
 }
Exemple #20
0
 public function testActionHref_uri()
 {
     $uri = Solar::factory('Solar_Uri_Action');
     $uri->setPath('/controller/action/id');
     $uri->setQuery('page=1');
     $actual = $this->_view->actionHref($uri);
     $expect = '/index.php/controller/action/id?page=1';
     $this->assertSame($expect, $actual);
 }
 public function test__construct_badData()
 {
     $struct = Solar::factory('Solar_Struct', array('data' => null));
     $this->assertSame($struct->toArray(), array());
     $struct = Solar::factory('Solar_Struct', array('data' => ''));
     $this->assertSame($struct->toArray(), array());
     $struct = Solar::factory('Solar_Struct', array('data' => 0));
     $this->assertSame($struct->toArray(), array());
 }
Exemple #22
0
 public function testPublicHref_uri()
 {
     $uri = Solar::factory('Solar_Uri_Public');
     $uri->setPath('/path/to/file');
     $uri->setQuery('page=1');
     $actual = $this->_view->publicHref($uri);
     $expect = '/public/path/to/file?page=1';
     $this->assertSame($actual, $expect);
 }
Exemple #23
0
 public function setup()
 {
     // limit Markdown to the one plugin we're testing
     $config['plugins'] = array($this->_class);
     $this->_markdown = Solar::factory('Solar_Markdown', $config);
     // build the plugin
     $config['markdown'] = $this->_markdown;
     $this->_plugin = Solar::factory($this->_class, $config);
 }
Exemple #24
0
 /**
  * 
  * Test -- Sets the base directory for the class map.
  * 
  */
 public function testSetBase()
 {
     $dir = Solar_Class::dir('Solar', '..');
     $base = Solar_Dir::fix(realpath($dir));
     $map = Solar::factory('Solar_Class_Map');
     $map->setBase($base);
     $actual = $map->getBase();
     $this->assertSame($actual, $base);
 }
Exemple #25
0
 public function testActionImage_uri()
 {
     $uri = Solar::factory('Solar_Uri_Action');
     $uri->setPath('/controller/action/id');
     $uri->setQuery('page=1');
     $src = '/images/example.gif';
     $actual = $this->_view->actionImage($uri, $src);
     $expect = '<a href="/index.php/controller/action/id?page=1">' . '<img src="/public/images/example.gif" alt="example.gif" /></a>';
     $this->assertSame($actual, $expect);
 }
Exemple #26
0
 /**
  * 
  * Establish state of this object prior to _setup().
  * 
  * @return void
  * 
  */
 protected function _preSetup()
 {
     // chain to parent
     parent::_preSetup();
     // use metadata generated from make-model
     $metadata = Solar::factory('Mock_Solar_Model_Users_Metadata');
     $this->_table_name = $metadata->table_name;
     $this->_table_cols = $metadata->table_cols;
     $this->_index_info = $metadata->index_info;
 }
Exemple #27
0
 /**
  * 
  * Overrides the general Solar_App setup so that we don't need a
  * database connection. This is because we want the simplest
  * possible hello-world example.
  * 
  * Thanks, Clay Loveless, for suggesting this.
  * 
  * @return void
  * 
  */
 protected function _setup()
 {
     // register a Solar_User object if not already.
     // this will trigger the authentication process.
     if (!Solar_Registry::exists('user')) {
         Solar_Registry::set('user', Solar::factory('Solar_User'));
     }
     // set the layout title
     $this->layout_head['title'] = get_class($this);
 }
Exemple #28
0
 /**
  * 
  * Post-construction tasks to complete object construction.
  * 
  * @return void
  * 
  */
 protected function _postConstruct()
 {
     parent::_postConstruct();
     $this->_response = Solar::dependency('Solar_Http_Response', $this->_config['response']);
     $this->_json = Solar::factory('Solar_Json');
     // Setup headers based on the wildfire standard
     $this->_response->setHeader('X-Wf-Protocol-1', 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2');
     $this->_response->setHeader('X-Wf-1-Plugin-1', 'http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3');
     $this->_response->setHeader('X-Wf-1-Structure-1', 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1');
 }
Exemple #29
0
 /**
  * 
  * Setup; runs before each test method.
  * 
  */
 public function setup()
 {
     parent::setup();
     // remove "Test_" prefix
     $this->_class = substr(get_class($this), 5);
     // get the request environment
     $this->_request = Solar_Registry::get('request');
     // get a new adapter
     $this->_auth = Solar::factory($this->_class, $this->_config);
 }
Exemple #30
0
 /**
  * 
  * Post-construction tasks to complete object construction.
  * 
  * @return void
  * 
  */
 protected function _postConstruct()
 {
     parent::_postConstruct();
     if (empty($this->_config['_view']) || !$this->_config['_view'] instanceof Solar_View) {
         // we need the parent view object
         throw Solar::exception(get_class($this), 'ERR_VIEW_NOT_SET', "Config key '_view' not set, or not Solar_View object");
     }
     $this->_view = $this->_config['_view'];
     unset($this->_config['_view']);
 }