Exemple #1
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();
 }
Exemple #2
0
 protected function _preConfig()
 {
     parent::_preConfig();
     $dir = Solar_Class::dir('Mock_Solar_Access_Adapter');
     $file = $dir . 'access.txt';
     $this->_Test_Solar_Access_Adapter_File['file'] = $file;
 }
Exemple #3
0
 /**
  * 
  * Test -- Fetches config file values.
  * 
  */
 public function testFetch()
 {
     $file = Solar_Class::dir('Mock_Solar_Config') . 'fetch.php';
     $actual = Solar_Config::fetch($file);
     $expect = array('foo' => 'bar', 'baz' => 'sub', 'zim' => 'gir');
     $this->assertSame($actual, $expect);
 }
Exemple #4
0
 protected function _preConfig()
 {
     parent::_preConfig();
     $dir = Solar_Class::dir('Mock_Solar_Auth_Adapter_Htpasswd');
     $file = $dir . 'users.htpasswd';
     $this->_Test_Solar_Auth_Adapter_Htpasswd['file'] = $file;
 }
Exemple #5
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 #6
0
 public function testCallbacks_instanceMethod()
 {
     $file = Solar_Class::dir('Mock_Solar') . 'callbacks-instance-method.php';
     Solar_File::load($file);
     $instance = Solar::factory('Solar_Callbacks_Instance_Method');
     Solar::callbacks(array(array($instance, 'callback')));
     $this->assertTrue($GLOBALS['SOLAR_CALLBACKS_INSTANCE_METHOD']);
 }
Exemple #7
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 #8
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 #9
0
 public function setup()
 {
     $dir = Solar_Class::dir('Test_Solar_Auth_Adapter', '_support');
     $this->_config['file'] = $dir . 'users.ini';
     $this->_moniker = 'Paul M. Jones';
     $this->_email = '*****@*****.**';
     $this->_uri = 'http://paul-m-jones.com';
     parent::setup();
 }
Exemple #10
0
 public function testIsValid_failures()
 {
     $checker = Solar::factory('Solar_Json_Checker');
     $dir = Solar_Class::dir('Mock_Solar_Json');
     $tests = scandir($dir);
     natsort($tests);
     foreach ($tests as $file) {
         if (substr($file, 0, 4) == 'fail' && substr($file, -4) == 'json') {
             $this->diag($file);
             $before = file_get_contents($dir . $file);
             $this->assertFalse($checker->isValid($before));
         }
     }
 }
Exemple #11
0
 public function preTest()
 {
     parent::preTest();
     // create the table
     $cmd = "CREATE TABLE {$this->_config['table']} (\n            {$this->_config['handle_col']} VARCHAR(255),\n            {$this->_config['role_col']}   CHAR(32)\n        )";
     $this->_sql->query($cmd);
     // get the roles
     $dir = Solar_Class::dir('Mock_Solar_Role_Adapter_Sql');
     $file = $dir . 'roles.ini';
     $roles = parse_ini_file($file, true);
     // insert the roles
     foreach ($roles as $role => $val) {
         $handles = explode(',', $val['handles']);
         foreach ($handles as $handle) {
             $data[$this->_config['handle_col']] = trim($handle);
             $data[$this->_config['role_col']] = trim($role);
             $this->_sql->insert('roles', $data);
         }
     }
 }
Exemple #12
0
 public function setup()
 {
     $this->_sql = Solar::factory('Solar_Sql', array('adapter' => 'Solar_Sql_Adapter_Sqlite', 'name' => ':memory:'));
     $cmd = "CREATE TABLE members (" . "    handle VARCHAR(255)," . "    passwd CHAR(32)," . "    email VARCHAR(255)," . "    moniker VARCHAR(255)," . "    uri VARCHAR(255)" . ")";
     $this->_sql->query($cmd);
     $dir = Solar_Class::dir('Test_Solar_Auth_Adapter', '_support');
     $insert = parse_ini_file($dir . 'users.ini', true);
     foreach ($insert as $handle => $data) {
         $data['handle'] = $handle;
         $data['passwd'] = hash('md5', $data['passwd']);
         $this->_sql->insert('members', $data);
     }
     $this->_moniker = 'Paul M. Jones';
     $this->_email = '*****@*****.**';
     $this->_uri = 'http://paul-m-jones.com';
     $this->_config['sql'] = $this->_sql;
     $this->_config['table'] = 'members';
     $this->_config['email_col'] = 'email';
     $this->_config['moniker_col'] = 'moniker';
     $this->_config['uri_col'] = 'uri';
     parent::setup();
 }
Exemple #13
0
 /**
  * 
  * Creates the baseline PHP files in the Vendor directories from the 
  * skeleton files in `Data/*.txt`.
  * 
  * @return void
  * 
  */
 protected function _createFiles()
 {
     $system = Solar::$system;
     $data_dir = Solar_Class::dir($this, 'Data');
     $list = glob($data_dir . "*.txt");
     foreach ($list as $data_file) {
         $file = substr($data_file, strlen($data_dir));
         $file = str_replace('.txt', '.php', $file);
         $file = str_replace('_', '/', $file);
         $file = str_replace('-', '_', $file);
         $file = "{$system}/source/{$this->_dashes}/{$this->_studly}/{$file}";
         if (file_exists($file)) {
             $this->_outln("File {$file} exists.");
             continue;
         }
         $dirname = dirname($file);
         if (!is_dir($dirname)) {
             $this->_out("Making directory {$dirname} ... ");
             mkdir($dirname, 0755, true);
             $this->_outln("done.");
         }
         $text = file_get_contents($data_file);
         $text = str_replace('{:php}', '<?php', $text);
         $text = str_replace('{:vendor}', $this->_studly, $text);
         $this->_out("Writing {$file} ... ");
         file_put_contents($file, $text);
         $this->_outln("done.");
     }
     // write a "config/default.php" file (empty)
     $file = "{$system}/source/{$this->_dashes}/config/default.php";
     $text = "<?php // placeholder config file for {$this->_studly} classes\n";
     if (file_exists($file)) {
         $this->_outln("File {$file} exists.");
     } else {
         $this->_out("Writing {$file} ... ");
         file_put_contents($file, $text);
         $this->_outln("done.");
     }
     // write a "config/run-tests.php" file
     $file = "{$system}/source/{$this->_dashes}/config/run-tests.php";
     $text = "<?php\n\$config = array();\nreturn \$config;\n";
     if (file_exists($file)) {
         $this->_outln("File {$file} exists.");
     } else {
         $this->_out("Writing {$file} ... ");
         file_put_contents($file, $text);
         $this->_outln("done.");
     }
     // write a "vendor/Vendor/Cli/Help/Info/help.txt" file
     $file = "{$system}/source/{$this->_dashes}/{$this->_studly}/Cli/Help/Info/help.txt";
     $text = "{$this->_studly} command line tool." . PHP_EOL . PHP_EOL . "Usage: %*{$this->_dashes} <command> <options> <params>%n" . PHP_EOL . PHP_EOL . "Try '{$this->_dashes} help <command>' for help on a specific command." . PHP_EOL;
     if (file_exists($file)) {
         $this->_outln("File {$file} exists.");
     } else {
         $this->_out("Writing {$file} ... ");
         file_put_contents($file, $text);
         $this->_outln("done.");
     }
 }
Exemple #14
0
 /**
  * 
  * Setup; runs before each test method.
  * 
  */
 public function setup()
 {
     $dir = Solar_Class::dir('Test_Solar_Access_Adapter', '_support');
     $this->_config['file'] = $dir . 'access.txt';
     parent::setup();
 }
Exemple #15
0
 /**
  * 
  * Loads DocBook template files from the Data directory.
  * 
  * @return void
  * 
  */
 protected function _loadTemplates()
 {
     $dir = Solar_Class::dir($this, 'Data');
     $list = glob("{$dir}/*.xml");
     foreach ($list as $file) {
         $name = basename($file);
         $this->_templates[$name] = file_get_contents($file);
     }
 }
 /**
  * 
  * Creates the baseline PHP files in the Vendor directories from the 
  * skeleton files in `Data/*.txt`.
  * 
  * @return void
  * 
  */
 protected function _createFiles()
 {
     $system = Solar::$system;
     $data_dir = Solar_Class::dir($this, 'Data');
     $list = glob($data_dir . "*.txt");
     foreach ($list as $data_file) {
         $file = substr($data_file, strlen($data_dir));
         $file = str_replace('.txt', '.php', $file);
         $file = str_replace('_', '/', $file);
         $file = str_replace('-', '_', $file);
         $file = "{$system}/source/{$this->_dashes}/{$this->_studly}/{$file}";
         if (file_exists($file)) {
             $this->_outln("File {$file} exists.");
             continue;
         }
         $dirname = dirname($file);
         if (!is_dir($dirname)) {
             $this->_out("Making directory {$dirname} ... ");
             mkdir($dirname, 0755, true);
             $this->_outln("done.");
         }
         $text = file_get_contents($data_file);
         $text = str_replace('{:php}', '<?php', $text);
         $text = str_replace('{:vendor}', $this->_studly, $text);
         $this->_out("Writing {$file} ... ");
         file_put_contents($file, $text);
         $this->_outln("done.");
     }
     // write a "config/default.php" file
     $file = "{$system}/source/{$this->_dashes}/config/default.php";
     if (file_exists($file)) {
         $this->_outln("File {$file} exists.");
     } else {
         $text = "<?php\n\$config = array();\nreturn \$config;\n";
         $this->_out("Writing {$file} ... ");
         file_put_contents($file, $text);
         $this->_outln("done.");
     }
     // write a "config/run-tests.php" file
     $file = "{$system}/source/{$this->_dashes}/config/run-tests.php";
     if (file_exists($file)) {
         $this->_outln("File {$file} exists.");
     } else {
         $text = "<?php\n\$config = array();\nreturn \$config;\n";
         $this->_out("Writing {$file} ... ");
         file_put_contents($file, $text);
         $this->_outln("done.");
     }
 }
Exemple #17
0
 /**
  * 
  * Run a single test method from the test class.
  * 
  * @param Solar_Php $php The PHP execution object.
  * 
  * @param string $class The test class.
  * 
  * @param string $method The test method.
  * 
  * @return void
  * 
  */
 protected function _testMethod($php, $class, $method)
 {
     $this->_test_result = null;
     $file = Solar_Class::dir($this) . 'run-test.php';
     $php->setArgv(array($class, $method))->runSolar($file);
     $this->_done($php->getExitCode(), "{$class}::{$method}", $php->getLastLine());
 }
Exemple #18
0
 public function setup()
 {
     $dir = Solar_Class::dir('Test_Solar_Auth_Adapter', '_support');
     $this->_config['file'] = $dir . 'users.htpasswd';
     parent::setup();
 }
 /**
  * 
  * Loads the template array from skeleton files.
  * 
  * @return void
  * 
  */
 protected function _loadTemplates()
 {
     $this->_tpl = array();
     $dir = Solar_Class::dir($this, 'Data');
     $list = glob($dir . '*.php');
     foreach ($list as $file) {
         // strip .php off the end of the file name to get the key
         $key = substr(basename($file), 0, -4);
         // load the file template
         $this->_tpl[$key] = file_get_contents($file);
         // we need to add the php-open tag ourselves, instead of
         // having it in the template file, becuase the PEAR packager
         // complains about parsing the skeleton code.
         //
         // however, only do this on non-view files.
         if (substr($key, 0, 4) != 'view') {
             $this->_tpl[$key] = "<?php\n" . $this->_tpl[$key];
         }
     }
 }
Exemple #20
0
 public function testDir_object()
 {
     $actual = Solar_Class::dir($this);
     $expect = dirname(__FILE__) . '/Class/';
     // to avoid include-vs-source difference, compare only the tails
     $len = strlen(get_class($this)) * -1 - 1;
     $actual = substr($actual, $len);
     $expect = substr($expect, $len);
     $this->assertSame($actual, $expect);
 }
Exemple #21
0
 /**
  * 
  * Returns the path to a file under a specific class.
  * 
  * @param string|object $spec The class or object to use as the base path.
  * 
  * @param string $file Append this file path.
  * 
  * @return string The path to the file under the class.
  * 
  */
 public static function file($spec, $file)
 {
     $dir = Solar_Class::dir($spec);
     return Solar_File::exists($dir . $file);
 }
Exemple #22
0
 /**
  * 
  * Test -- Returns a final rendering of the processed text.
  * 
  */
 public function testRender()
 {
     if (!extension_loaded('tidy')) {
         $this->skip("Tidy extension not loaded");
     }
     $dir = Solar_Class::dir('Mock_Solar_Markdown_Wiki');
     $text_file = $dir . 'basic.text';
     $html_file = $dir . 'basic.html';
     $source = file_get_contents($text_file);
     $actual = $this->_tidy($this->_markdown->transform($source));
     $expect = $this->_tidy(file_get_contents($html_file));
     $this->assertSame($actual, $expect);
 }
Exemple #23
0
 protected function _postConstruct()
 {
     parent::_postConstruct();
     $this->_support_path = Solar_Class::dir('Mock_Solar_Path_Stack');
 }
Exemple #24
0
 protected function _preConfig()
 {
     $dir = Solar_Class::dir('Mock_Solar_Role_Adapter_File');
     $file = $dir . 'roles.txt';
     $this->_Test_Solar_Role_Adapter_File['file'] = $file;
 }
Exemple #25
0
 public function testDecode_compatFailure()
 {
     $pjson = $this->_newJson();
     $njson = $this->_newExtJson();
     $dir = Solar_Class::dir('Mock_Solar_Json');
     $tests = scandir($dir);
     natsort($tests);
     foreach ($tests as $file) {
         if ($file == 'fail18.json') {
             // skip this one, because the userland implementation can't
             // handle it, but ext/json can.
             continue;
         }
         if (substr($file, 0, 4) == 'fail' && substr($file, -4) == 'json') {
             $before = file_get_contents($dir . $file);
             $this->diag("p: {$file}");
             $this->assertNull($pjson->decode($before));
             $this->diag("n: {$file}");
             $this->assertNull($njson->decode($before));
         }
     }
 }
Exemple #26
0
 /**
  * 
  * Test -- Returns the path to the requested template script.
  * 
  */
 public function testTemplate()
 {
     $dir = Solar_Class::dir('Mock_Solar_View');
     $this->_view->addTemplatePath($dir);
     $actual = $this->_view->template('test.view.php');
     $expect = $dir . 'test.view.php';
     $this->assertSame($expect, $actual);
 }