Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 2001

Přidáno uživatelem David Raška před více než 11 roky(ů)

Nove:
closes #646 - Integrace Unit testovani pomoci PHPUnit v NetBeans
Opravy:
- pridani implementace abstraktnich metod u PVFree generatoru VS

Zobrazit rozdíly:

freenetis/branches/1.1/application/libraries/variable_key_generators/Pvfree_Variable_Key_Generator.php
return $identificator . sprintf('%02d', substr(hexdec(substr(md5($identificator), -2)), -2));
}
/*
* @override
*/
public function errorCheck($var_key)
{
$length = strlen($var_key);
$identificator = substr($var_key, 0, $length - 2);
$hash = substr($var_key, $length - 2);
return sprintf('%02d', substr(hexdec(substr(md5($identificator), -2)), -2)) == $hash;
}
/*
* @override
*/
public function errorCheckAvailable()
{
return TRUE;
}
/*
* @override
*/
public function errorCorrectionAvaiable()
{
return FALSE;
}
}
freenetis/branches/1.1/index.php
// $Id: index.php 1631 2007-12-28 00:11:38Z Shadowhand $
//
// Define the front controller name and docroot
define('DOCROOT', getcwd().DIRECTORY_SEPARATOR);
define('KOHANA', substr(__FILE__, strlen(DOCROOT)));
// Tests if system is running in unit testing mode
$unittest = (empty($_SERVER['SERVER_NAME']) && strpos(@$_SERVER['SCRIPT_NAME'], 'phpunit'));
// If unit testing change relative address of system and appplication folders
if ($unittest)
{
$kohana_application = dirname(__FILE__) . '/' . $kohana_application;
$kohana_system = dirname(__FILE__) . '/' . $kohana_system;
// Define the front controller name and docroot
define('DOCROOT', dirname(__FILE__) . '/');
define('KOHANA', substr(__FILE__, strlen(DOCROOT)));
}
else
{
// Define the front controller name and docroot
define('DOCROOT', getcwd().DIRECTORY_SEPARATOR);
define('KOHANA', substr(__FILE__, strlen(DOCROOT)));
}
// Define application and system paths
define('APPPATH', str_replace('\\', '/', realpath($kohana_application)).'/');
define('SYSPATH', str_replace('\\', '/', realpath($kohana_system)).'/');
......
// Mail to developers
define('DEVELOPER_EMAIL_ADDRESS', 'bugs@freenetis.org');
require SYSPATH.'core/Bootstrap'.EXT;
// If unit testing just initilize do not execute
if($unittest)
{
require 'tests/BootstrapPHPUnit'.EXT;
}
else
{
require SYSPATH.'core/Bootstrap'.EXT;
}
freenetis/branches/1.1/system/core/Config.php
if (self::$cache === NULL)
{
// Invalid config file
if (file_exists('config' . EXT))
if (file_exists(DOCROOT . 'config' . EXT))
{
require('config' . EXT);
require(DOCROOT . 'config' . EXT);
}
if (!isset($config))
freenetis/branches/1.1/tests/BootstrapPHPUnit.php
<?php defined('SYSPATH') or die('No direct script access.');
/**
* Kohana process control file, loaded by the front controller.
*
* $Id: Bootstrap.php 1968 2008-02-06 21:41:29Z Shadowhand $
*
* @package Core
* @author Kohana Team
* @copyright (c) 2007 Kohana Team
* @license http://kohanaphp.com/license.html
*/
define('KOHANA_VERSION', '2.1.1');
define('KOHANA_CODENAME', 'Schneefeier');
// Kohana benchmarks are prefixed by a random string to prevent collisions
define('SYSTEM_BENCHMARK', uniqid());
// Load benchmarking support
require SYSPATH.'core/Benchmark'.EXT;
// Start: total_execution
Benchmark::start(SYSTEM_BENCHMARK.'_total_execution');
// Start: kohana_loading
Benchmark::start(SYSTEM_BENCHMARK.'_kohana_loading');
// Define Kohana error constant
defined('E_KOHANA') or define('E_KOHANA', 42);
// Define 404 error constant
defined('E_PAGE_NOT_FOUND') or define('E_PAGE_NOT_FOUND', 43);
// Define database error constant
defined('E_DATABASE_ERROR') or define('E_DATABASE_ERROR', 44);
// Define extra E_RECOVERABLE_ERROR for PHP < 5.2
defined('E_RECOVERABLE_ERROR') or define('E_RECOVERABLE_ERROR', 4096);
// Load core files
require SYSPATH.'core/utf8'.EXT;
require SYSPATH.'core/Config'.EXT;
require SYSPATH.'core/Log'.EXT;
require SYSPATH.'core/Event'.EXT;
require SYSPATH.'core/Kohana'.EXT;
// End: kohana_loading
Benchmark::stop(SYSTEM_BENCHMARK.'_kohana_loading');
// Start: system_initialization
Benchmark::start(SYSTEM_BENCHMARK.'_system_initialization');
Event::run('system.ready');
//Event::run('system.routing');
// End: system_initialization
//Benchmark::stop(SYSTEM_BENCHMARK.'_system_initialization');
//Event::run('system.execute');
Event::run('system.shutdown');
freenetis/branches/1.1/tests/application/libraries/variable_key_generators/Checksum_Variable_Key_GeneratorTest.php
<?php
require_once dirname(__FILE__) . '/../../../../application/libraries/variable_key_generators/Checksum_Variable_Key_Generator.php';
/**
* Test class for Parity_Variable_Key_Generator.
* Generated by PHPUnit on 2013-06-05 at 14:39:59.
*/
class Checksum_Variable_Key_GeneratorTest extends PHPUnit_Framework_TestCase {
/**
* @var Parity_Variable_Key_Generator
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp() {
$this->object = new Checksum_Variable_Key_Generator;
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown() {
}
/**
* Test uniqe keys for member IDs 0 - 999999
* @covers Parity_Variable_Key_Generator::generate
*/
public function testGenerate() {
$variable_symbols = array();
for ($i = 0; $i < 999999; $i++)
{
$vs = $this->object->generate(strval($i));
$variable_symbols[$vs] = true;
$this->assertEquals(count($variable_symbols), $i+1);
}
}
/**
* Tests one error check
* @covers Parity_Variable_Key_Generator::errorCheck
*/
public function testOneErrorCheck() {
$vs = $this->object->generate(rand(1, 999999));
// one error in variable symbol
for ($i = 0; $i < 10; $i++) // move error position
{
for ($j = 0; $j < 10; $j++) // change value
{
$bad_vs = $vs;
$bad_vs[$i] = strval($j);
// skip no error test
if ($bad_vs == $vs)
{
continue;
}
$result = $this->object->errorCheck($bad_vs);
$this->assertFalse($result);
}
}
}
/**
* Tests two error check
* @covers Parity_Variable_Key_Generator::errorCheck
*/
public function testTwoErrorsCheck() {
$vs = $this->object->generate(rand(1, 999999));
// two errors in variable symbol
for ($i = 0; $i < 10; $i++) // move first error position
{
for ($j = 0; $j < 10; $j++) // change first value
{
for ($k = $i+1; $k < 10; $k++) // move second error position
{
for ($l = 0; $l < 10; $l++) // change second value
{
$bad_vs = $vs;
$bad_vs[$i] = strval($j);
$bad_vs[$k] = strval($l);
// skip no error test
if ($bad_vs == $vs)
{
continue;
}
$result = $this->object->errorCheck($bad_vs);
$this->assertFalse($result);
}
}
}
}
}
/**
* Tests one error correction
* @covers Parity_Variable_Key_Generator::errorCorrection
*/
public function testOneErrorCorrection() {
$vs = $this->object->generate(rand(1, 999999));
// one error in variable symbol
for ($i = 0; $i < 10; $i++) // move error position
{
for ($j = 0; $j < 10; $j++) // change value
{
$bad_vs = $vs;
$bad_vs[$i] = strval($j);
// skip no error test
if ($bad_vs == $vs)
{
continue;
}
$result = $this->object->errorCorrection($bad_vs);
$this->assertTrue($result['status']);
$this->assertEquals($result['corrected_variable_key'], $vs);
}
}
}
}

Také k dispozici: Unified diff