Menu

Tests

2007-09-05
2013-03-21
  • Mick Faraday

    Mick Faraday - 2007-09-05

    I've written a small test environment using PHPUnit3 that I would like to contribute to this awesome project. Basically it consists of two test suites and three test cases. Currently it is not more than a first try, but I will contribute further test cases in the near future.

    The file structure is as follows:

    OFBUnitTests/
      BrowserTests/
        AllBrowserTests.php
        BasicTest.php
        MakeDirTest.php
      Common/
        OfbTestCase.php
        OfbTestSuite.php
      AllTests.php
      README.txt

    README.txt contains further information and describes the installation.

     
    • Mick Faraday

      Mick Faraday - 2007-09-05

      <?php

      // PHPUnit
      require_once 'PHPUnit/Framework.php';

      // OFB Unittests
      require_once 'Common/OfbTestCase.php';
      require_once 'Common/OfbTestSuite.php';

      // Browser Tests
      require_once 'BrowserTests/AllBrowserTests.php';

      /** Suite with all tests.
        *
        * @author Mick Faraday (farad@users.sourceforge.net)
        * @license http://www.opensource.org/licenses/mit-license.php The MIT License
        */
      class AllTests extends OfbTestSuite {

          /** Creates a test suite.
            *
            */
          public static function suite() {
              $suite = new OfbTestSuite('OFB');
             
              // BrowserTests
              $suite->addTest(AllBrowserTests::suite());

              return $suite;
          }
      }

      ?>

       
    • Mick Faraday

      Mick Faraday - 2007-09-05

      Table of Contents                Last Update: 2007-09-05

      * Requirements
      * OFB Installation
      * OFBUnitTests (OFBUT) Installation
      * Running all Tests
      * License

      Requirements

      1. Proper OFB installation as described in section 'OFB Installation'.
      2. Installation of OFBUnitTests as described in section
         'OFBUnitTests (OFBUT) Installation'
      3. Installed PHPUnit 3.1.8

      OFB Installation

      1. Download and extract OFB
      2. Create uploads folder
          mkdir $OFB_HOME/uploads
      2. Adjust conf/system.properties:
          browser.root=uploads
          authentication.enforce=false
      3. Set permissions:
          chown -R $HTTPD_USER:$HTTPD_GROUP $OFB_HOME/logs/
          chown -R $HTTPD_USER:$HTTPD_GROUP $OFB_HOME/uploads/
          chown -R $HTTPD_USER:$HTTPD_GROUP $OFB_HOME/tpl/default/cache/
          chown -R $HTTPD_USER:$HTTPD_GROUP $OFB_HOME/tpl/default/templates_c/

      OFBUnitTests (OFBUT) Installation

      Please make sure that the directory 'OFBUnitTests' is in the directory
      $OFB_HOME/tests (You will need to create the directory tests/ first).

      Sample directory structure:
      /opt/lampp/htdocs
          filebrowser-0.1.7.2/                # $OFB_HOME
              class/
              conf/
              ...
              tests/
                  OFBUnitTests/            # $OFBUT_HOME

      Running all Tests

      user#> cd $OFBUNITTESTS_HOME
      user#> phpunit AllTests.php

      The last line of the output should be:
          OK (xyz tests)

      License

      The MIT License

      see http://www.opensource.org/licenses/mit-license.php

       
    • Mick Faraday

      Mick Faraday - 2007-09-05

      <?php

      /** Base class of all test cases.
        *
        * @author Mick Faraday (farad@users.sourceforge.net)
        * @license http://www.opensource.org/licenses/mit-license.php The MIT License
        */
      class OfbTestCase extends PHPUnit_Framework_TestCase {
          /** Instance of OnlineFileBrowser (OFB).
            *
            */
          protected $_filebrowser = null;
         
          /** Creates an instance of OFB.
            *
            */
          public function __construct() {
              parent::__construct();
             
              $this->setUpOfb();
              $this->_filebrowser = new Browser();
          }

          /** Initializes and configures OnlineFileBrowser.
            *
            */   
          private function setUpOfb() {
              // start session and buffer
              //session_start();
              ob_start();
             
              /**
                * Browser base folder that contains all files.
                */
              define('BROWSER_BASE', dirname(__FILE__) . '/../../..');
             
              /**
                * File system path separator.
                */
              define('BROWSER_SEPARATOR', "/");
             
              /**
                * Browser properties files.
                */
              define('BROWSER_PROPERTIES_FILE', "conf".BROWSER_SEPARATOR."system.properties");
                     
              /**
                * Browser log level.
                */
              define('BROWSER_LOG_LEVEL', "INFO");

              /**
                * Browser log file. It will be located in log directory.
                */
              define('BROWSER_LOG_FILE', "log.txt");
                     
              /**
                * It is required to keep in session information about authenticated user. If session doesn't contain that information then it imply that
                * there is no authenticated user.
                */
              define('BROWSER_AUTHENTICATED_USER', 'AUTHENTICATED_USER');
             
              /**
                * Custom root location for user, this variable should be set only if user's root is different then default one.
                */
              define('BROWSER_AUTHENTICATED_USER_ROOT', 'AUTHENTICATED_USER_ROOT');
                     
              /**
                * Name of URL parameter which defines start location for OFB.
                */
              define('REQUEST_START_LOCATION', 'path');
                     
              /**
                * Core Browser utilities
                */
              require_once (BROWSER_BASE.BROWSER_SEPARATOR.'class'.BROWSER_SEPARATOR.'Browser_Utilities.php');

              /**
                * Browser configuration.
                */
              global $_BROWSER_CONFIGURATION;
              $_BROWSER_CONFIGURATION = Browser_Utilities :: loadProperites(BROWSER_BASE.BROWSER_SEPARATOR.BROWSER_PROPERTIES_FILE);
             
              /* define class directory */
              global $_INCLUDE_DIR;
              $_INCLUDE_DIR = array ();
              $_INCLUDE_DIR[] = BROWSER_BASE.BROWSER_SEPARATOR.'class';
              $_INCLUDE_DIR[] = BROWSER_BASE.BROWSER_SEPARATOR.'class'.BROWSER_SEPARATOR.'actions'.BROWSER_SEPARATOR.'ActionTemplate.php';
              $_INCLUDE_DIR[] = BROWSER_BASE.BROWSER_SEPARATOR.'class'.BROWSER_SEPARATOR.'actions';
              $_INCLUDE_DIR[] = BROWSER_BASE.BROWSER_SEPARATOR.'lib';
             
              /**
                * include all dependencies
                */
              Browser_Utilities :: includeRequiredClasses($_INCLUDE_DIR);
          }
      }

      ?>

       
    • Mick Faraday

      Mick Faraday - 2007-09-05

      <?php

      // PHPUnit
      require_once 'PHPUnit/TextUI/TestRunner.php';

      /** Base class of all test suites.
        *
        * @author Mick Faraday (farad@users.sourceforge.net)
        * @license http://www.opensource.org/licenses/mit-license.php The MIT License
        */
      class OfbTestSuite extends PHPUnit_Framework_TestSuite {

          /** Runs all tests.
            *
            */
          public static function main() {
              PHPUnit_TextUI_TestRunner::run(self::suite());
          }
      }

      ?>

       
    • Mick Faraday

      Mick Faraday - 2007-09-05

      <?php

      // Browser Tests
      require_once 'BasicTest.php';
      require_once 'MakeDirTest.php';

      /** Suite with all Browser tests.
        *
        * @author Mick Faraday (farad@users.sourceforge.net)
        * @license http://www.opensource.org/licenses/mit-license.php The MIT License
        */
      class AllBrowserTests extends OfbTestSuite {

          /** Creates a test suite.
            *
            */
          public static function suite() {
              $suite = new OfbTestSuite('OFB');
              $suite->addTest(new OfbTestSuite('BasicTest'));
              $suite->addTest(new OfbTestSuite('MakeDirTest'));

              return $suite;
          }
      }

      ?>

       
    • Mick Faraday

      Mick Faraday - 2007-09-05

      <?php

      /** Basic tests.
        *
        * @author Mick Faraday (farad@users.sourceforge.net)
        * @license http://www.opensource.org/licenses/mit-license.php The MIT License
        */
      class BasicTest extends OfbTestCase {

          /** Checks whether OFB has been initialized correctly.
            *
            */
          public function testFileBrowserInstance() {
              $this->assertNotNull($this->_filebrowser);
          }

          /** Ensures that OFB's root dir is a directory named 'uploads'.
            *
            */   
          public function testBasePath() {
              $basepath = $this->_filebrowser->basepath;
             
              $this->assertEquals('uploads', basename($basepath));
          }
      }
      ?>

       
    • Mick Faraday

      Mick Faraday - 2007-09-05

      <?php

      /** Tests for the function Browser.php::makeDir(.)
        *
        * @author Mick Faraday (farad@users.sourceforge.net)
        * @license http://www.opensource.org/licenses/mit-license.php The MIT License
        */
      class MakeDirTest extends OfbTestCase {
         
          /** Checks OFB's makeDir function.
            *
            * @see Browser.php :: makeDir()
            */
          public function testMakeDir() {
              $dirname = 'test';
             
              // make dir
              $this->_filebrowser->makeDir($dirname);
             
              // check dir
              $dir = $this->_filebrowser->basepath . '/' . $dirname;
              $exists = file_exists($dir);
              $this->assertTrue($exists);
             
              // delete dir
              rmdir($dir);
          }
      }
      ?>

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.