Changeset 446 for branches


Ignore:
Timestamp:
Dec 11, 2013 6:09:07 PM (10 years ago)
Author:
anonymous
Message:

Wrapper script for phpunit. Changed logMsg SCREEN action to print to stderr.

Location:
branches/eli_branch
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branches/eli_branch/lib/App.inc.php

    r442 r446  
    44 * For details visit the project site: <http://trac.strangecode.com/codebase/>
    55 * Copyright 2001-2012 Strangecode, LLC
    6  * 
     6 *
    77 * This file is part of The Strangecode Codebase.
    88 *
     
    1111 * Free Software Foundation, either version 3 of the License, or (at your option)
    1212 * any later version.
    13  * 
     13 *
    1414 * The Strangecode Codebase is distributed in the hope that it will be useful, but
    1515 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1616 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    1717 * details.
    18  * 
     18 *
    1919 * You should have received a copy of the GNU General Public License along with
    2020 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
     
    3131
    3232//ob_start();
    33  
     33
    3434// Message Types.
    3535define('MSG_ERR', 1);
     
    8888        'session_name' => '_session',
    8989        'session_use_cookies' => true,
    90        
     90
    9191        // Pass the session-id through URLs if cookies are not enabled?
    9292        // Disable this to prevent session ID theft.
     
    192192        // Initialize default parameters.
    193193        $this->_params = array_merge($this->_params, $this->_param_defaults);
    194        
     194
    195195        // Begin timing script.
    196196        require_once dirname(__FILE__) . '/ScriptTimer.inc.php';
     
    246246
    247247        // Error reporting.
    248         /*
    249248        ini_set('error_reporting', $this->getParam('error_reporting'));
    250249        ini_set('display_errors', $this->getParam('display_errors'));
     
    253252            ini_set('error_log', $this->getParam('log_directory') . '/' . $this->getParam('php_error_log'));
    254253        }
    255 */
     254
    256255        // Set character set to use for multi-byte string functions.
    257256        mb_internal_encoding($this->getParam('character_set'));
     
    276275
    277276        if (true === $this->getParam('enable_db')) {
    278            
     277
    279278            // DB connection parameters taken from environment variables in the httpd.conf file, readable only by root.
    280279            if (!empty($_SERVER['DB_SERVER'])) {
     
    367366            $this->setParam(array('site_url' => sprintf('%s://%s', ('on' == getenv('HTTPS') ? 'https' : 'http'), getenv('HTTP_HOST'))));
    368367        }
    369        
     368
    370369        // In case site_email isn't set, use something halfway presentable.
    371370        if (isset($_SERVER['HTTP_HOST']) && '' != $_SERVER['HTTP_HOST'] && '' == $this->getParam('site_email')) {
     
    380379        // Character set. This should also be printed in the html header template.
    381380        //header('Content-type: text/html; charset=' . $this->getParam('character_set'));
    382        
     381
    383382        // Set the version of the codebase we're using.
    384383        $codebase_version_file = dirname(__FILE__) . '/../docs/version.txt';
     
    438437            return false;
    439438        }
    440        
     439
    441440        // Avoid duplicate full-stops..
    442441        $message = trim(preg_replace('/\.{2}$/', '.', $message));
     
    453452            );
    454453        }
    455        
     454
    456455        if (!in_array($type, array(MSG_NOTICE, MSG_SUCCESS, MSG_WARNING, MSG_ERR))) {
    457456            $this->logMsg(sprintf('Invalid MSG_* type: %s', $type), LOG_NOTICE, __FILE__, __LINE__);
    458457        }
    459458    }
    460    
     459
    461460    /**
    462461     * Returns an array of the raised messages.
     
    476475        return isset($_SESSION['_app'][$this->_ns]['messages']) ? $_SESSION['_app'][$this->_ns]['messages'] : array();
    477476    }
    478    
     477
    479478    /**
    480479     * Resets the message list.
     
    490489            return false;
    491490        }
    492        
     491
    493492        $_SESSION['_app'][$this->_ns]['messages'] = array();
    494493    }
     
    507506    public function printRaisedMessages($above='', $below='', $print_gotohash_js=false, $hash='sc-msg')
    508507    {
    509        
     508
    510509        if (!$this->running) {
    511510            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);
    512511            return false;
    513512        }
    514        
     513
    515514        $messages = $this->getRaisedMessages();
    516515        if (!empty($messages)) {
     
    595594            trigger_error(sprintf('Codebase error: log directory (%s) not found or writable.', $this->getParam('log_directory')), E_USER_NOTICE);
    596595        }
    597        
     596
    598597        // Before we get any further, let's see if ANY log events are configured to be reported.
    599598        if ((false === $this->getParam('log_file_priority') || $priority > $this->getParam('log_file_priority'))
     
    631630            $site_hash = md5(empty($_SERVER['SERVER_NAME']) ? $_SERVER['SCRIPT_FILENAME'] : $_SERVER['SERVER_NAME']);
    632631            $lock_dir = $this->getParam('tmp_dir') . "/codebase_msgs_$site_hash/";
    633             // Just use the file and line for the msg_id to limit the number of possible messages 
     632            // Just use the file and line for the msg_id to limit the number of possible messages
    634633            // (the message string itself shan't be used as it may contain innumerable combinations).
    635634            $lock_file = $lock_dir . md5($file . ':' . $line);
     
    652651            }
    653652        }
    654        
     653
    655654        // Data to be stored for a log event.
    656655        $event = array(
     
    690689            mb_send_mail($this->getParam('log_to_sms_address'), $subject, $sms_msg, $headers);
    691690        }
    692    
     691
    693692        // SCREEN ACTION
    694693        if (false !== $this->getParam('log_screen_priority') && $priority <= $this->getParam('log_screen_priority')) {
    695             echo "[{$event['type']}] [{$event['message']}]\n";
     694            file_put_contents('php://stderr', "[{$event['type']}] [{$event['message']}]\n", FILE_APPEND);
    696695        }
    697696
    698697        // Restore original locale.
    699698        setlocale(LC_TIME, $locale);
    700        
     699
    701700        return true;
    702701    }
     
    776775
    777776    /**
    778      * dropQuery() is the opposite of carryQuery(). The specified value will not appear in 
     777     * dropQuery() is the opposite of carryQuery(). The specified value will not appear in
    779778     * url()/ohref()/printHiddenSession() modified URLs unless explicitly written in.
    780      * 
     779     *
    781780     * @access  public
    782781     * @param   mixed   $query_key  The key (or keys, as an array) of the query argument to remove.
  • branches/eli_branch/tests/AppTest.php

    r442 r446  
    44 * For details visit the project site: <http://trac.strangecode.com/codebase/>
    55 * Copyright 2001-2012 Strangecode, LLC
    6  * 
     6 *
    77 * This file is part of The Strangecode Codebase.
    88 *
     
    1111 * Free Software Foundation, either version 3 of the License, or (at your option)
    1212 * any later version.
    13  * 
     13 *
    1414 * The Strangecode Codebase is distributed in the hope that it will be useful, but
    1515 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1616 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    1717 * details.
    18  * 
     18 *
    1919 * You should have received a copy of the GNU General Public License along with
    2020 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
     
    3030 * Created with PHPUnit_Skeleton on 2005-08-09
    3131 */
    32 //
    3332
    3433class AppTest extends PHPUnit_Framework_TestCase {
    3534
    3635    var $App;
    37    
     36
    3837    static $shared_session;
    3938
     
    9695    {
    9796        $db =& DB::getInstance();
    98    
     97
    9998        $qid = $db->query("SELECT 2 + 2");
    10099        list($result) = mysql_fetch_row($qid);
  • branches/eli_branch/tests/AuthSQLTest.php

    r442 r446  
    44 * For details visit the project site: <http://trac.strangecode.com/codebase/>
    55 * Copyright 2001-2012 Strangecode, LLC
    6  * 
     6 *
    77 * This file is part of The Strangecode Codebase.
    88 *
     
    1111 * Free Software Foundation, either version 3 of the License, or (at your option)
    1212 * any later version.
    13  * 
     13 *
    1414 * The Strangecode Codebase is distributed in the hope that it will be useful, but
    1515 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1616 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    1717 * details.
    18  * 
     18 *
    1919 * You should have received a copy of the GNU General Public License along with
    2020 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
     
    3333
    3434    var $Auth_SQL;
    35    
     35
    3636    static $shared_session;
    37    
     37
    3838    function setUp()
    3939    {
     
    7676    {
    7777        $db =& DB::getInstance();
    78    
     78
    7979        unset($this->Auth_SQL);
    8080        $db->query("DROP TABLE IF EXISTS test_user_tbl");
     
    145145        $after_logged_in = $this->Auth_SQL->isloggedin();
    146146        $this->assertFalse($after_logged_in, '3. User is still logged in but should not be.');
    147        
     147
    148148        // Testing wrong password.
    149149        $login2 = $this->Auth_SQL->login('testuser', 'wrongpass');
     
    164164    {
    165165        $db =& DB::getInstance();
    166    
     166
    167167        $this->Auth_SQL->login('testuser', 'testpass');
    168168        $this->Auth_SQL->blockaccount(null, 'blocktestuser');
     
    178178    {
    179179        $db =& DB::getInstance();
    180    
     180
    181181        $db->query("
    182182            UPDATE test_user_tbl SET blocked_reason = 'blocktestuser'
     
    240240    {
    241241        $db =& DB::getInstance();
    242    
     242
    243243        $this->Auth_SQL->setParam(array('encryption_type' => AUTH_ENCRYPT_SHA1_HARDENED));
    244244        $this->Auth_SQL->setpassword(null, '123');
     
    255255        $result = $this->Auth_SQL->resetpassword(1, 'Because this is a test.');
    256256        $this->assertInternalType('array', $result);
    257        
     257
    258258    }
    259259
  • branches/eli_branch/tests/Auth_FileTest.php

    r438 r446  
    44 * For details visit the project site: <http://trac.strangecode.com/codebase/>
    55 * Copyright 2001-2012 Strangecode, LLC
    6  * 
     6 *
    77 * This file is part of The Strangecode Codebase.
    88 *
     
    1111 * Free Software Foundation, either version 3 of the License, or (at your option)
    1212 * any later version.
    13  * 
     13 *
    1414 * The Strangecode Codebase is distributed in the hope that it will be useful, but
    1515 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1616 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    1717 * details.
    18  * 
     18 *
    1919 * You should have received a copy of the GNU General Public License along with
    2020 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
  • branches/eli_branch/tests/Auth_SQLTest.php

    r438 r446  
    3030 * Created with PHPUnit_Skeleton on 2005-08-09
    3131 */
    32 require_once 'PHPUnit.php';
     32
    3333class Auth_SQLTest extends PHPUnit_TestCase {
    3434
  • branches/eli_branch/tests/_config.inc.php

    r442 r446  
    44 * For details visit the project site: <http://trac.strangecode.com/codebase/>
    55 * Copyright 2001-2012 Strangecode, LLC
    6  * 
     6 *
    77 * This file is part of The Strangecode Codebase.
    88 *
     
    1111 * Free Software Foundation, either version 3 of the License, or (at your option)
    1212 * any later version.
    13  * 
     13 *
    1414 * The Strangecode Codebase is distributed in the hope that it will be useful, but
    1515 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1616 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    1717 * details.
    18  * 
     18 *
    1919 * You should have received a copy of the GNU General Public License along with
    2020 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
     
    2828*/
    2929require_once '../lib/App.inc.php';
    30 
    31 $_SERVER['DB_SERVER'] = 'localhost';
    32 $_SERVER['DB_USER'] = 'sc';
    33 $_SERVER['DB_NAME'] = 'sc_db';
    34 $_SERVER['DB_PASS'] = '1234';
    3530
    3631$app =& App::getInstance('testapp');
  • branches/eli_branch/tests/bootstrap.php

    r442 r446  
    11<?php
    2 session_start();
    3 //set_include_path(get_include_path() . PATH_SEPARATOR . '../..');
    4 ini_set('include_path',get_include_path().PATH_SEPARATOR.'/opt'.PATH_SEPARATOR.'..');
    5 //die(get_include_path());
     2// session_start();
     3// //set_include_path(get_include_path() . PATH_SEPARATOR . '../..');
     4// ini_set('include_path',get_include_path().PATH_SEPARATOR.'/opt'.PATH_SEPARATOR.'..');
     5// //die(get_include_path());
  • branches/eli_branch/tests/phpunit.xml

    r442 r446  
    1 <php
     1<!--
     2For config options see:
     3http://phpunit.de/manual/current/en/appendixes.configuration.html
     4
     5Run all scripts by executing ./run_tests.sh
     6-->
     7<phpunit
    28convertErrorsToExceptions="false"
    39convertNoticesToExceptions="false"
    410convertWarningsToExceptions="false"
    511bootstrap="bootstrap.php"
     12strict="true"
     13verbose="true"
     14debug="true"
     15tap="true"
     16stopOnError="true"
     17stopOnFailure="true"
     18stopOnIncomplete="false"
     19stopOnSkipped="true"
    620>
    7   <includePath>.</includePath>
    8   <includePath>/opt</includePath>
    9   <env name="DB_NAME" value="sc_db"/>
    10   <env name="DB_USER" value="sc"/>
    11   <env name="DB_PASS" value="1234"/> 
    12   <env name="DB_SERVER" value="localhost"/>
    13   <testsuites>
    14     <testsuite name="Codebase_Tests">
    15       <file>AppTest.php</file>
    16       <file>AuthFileTest.php</file>
    17       <file>AuthorizeNetTest.php</file>
    18       <file>AuthSQLTest.php</file>
    19       <file>CSSTest.php</file>
    20       <file>DBSessionHandlerTest.php</file>
    21       <file>EmailTest.php</file>
    22       <file>FormValidatorTest.php</file>
    23       <file>LockTest.php</file>
    24       <file>PayPalTest.php</file>
    25       <file>VersionTest.php</file>
    26     </testsuite>
    27   </testsuites>
    28 </php>
     21    <includePath>.</includePath>
     22    <includePath>/opt</includePath>
     23    <testsuites>
     24        <testsuite name="Codebase_Tests">
     25            <file>AppTest.php</file>
     26            <file>AuthFileTest.php</file>
     27            <file>AuthorizeNetTest.php</file>
     28            <file>AuthSQLTest.php</file>
     29            <file>CSSTest.php</file>
     30            <file>DBSessionHandlerTest.php</file>
     31            <file>EmailTest.php</file>
     32            <file>FormValidatorTest.php</file>
     33            <file>LockTest.php</file>
     34            <file>PayPalTest.php</file>
     35            <file>VersionTest.php</file>
     36        </testsuite>
     37    </testsuites>
     38</phpunit>
  • branches/eli_branch/tests/run_tests.sh

    r399 r446  
    11#!/bin/sh
     2
     3# This script sets-up the test environment and runs all tests.
     4# You'll want to define your local mysql credentials for a test
     5# database as environment variables, e.g., in ~/.bash_profile:
     6#  export DB_NAME="test"
     7#  export DB_USER="test"
     8#  export DB_PASS="..."
    29
    310# Be in the directory with all the tests.
    411cd `dirname $0`;
    512
     13# Get required ENV variables.
     14if [[ -z "$DB_USER$DB_PASS$DB_NAME" ]]; then
     15    echo "MySQL test DB credential environment variables are missing.\nSet these in ~/.bash_profile to avoid seeing these prompts each time.";
     16fi
     17for E in DB_USER DB_PASS DB_NAME; do
     18    while [[ -z ${!E} ]]; do
     19        read -p "$E: " $E;
     20    done
     21    export $E;
     22done
     23
    624# Create database.
    725mysql -e 'CREATE DATABASE IF NOT EXISTS `test`';
    826
    9 # Run tests sequentially.
    10 for foo in *Test.php;
    11 do
    12     php $foo;
    13 done;
     27# Go!
     28echo "Running the tests!";
     29echo "You'll want to 'tail -f /tmp/codebase_test_log' and watch for errors.";
     30
     31# Config options go in phpunit.xml
     32# phpunit --tap | grep -v '^ok '
     33phpunit
Note: See TracChangeset for help on using the changeset viewer.