Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

UnitTest: Repair git add phpunit.sh

  • Loading branch information...
commit 3f4c6ba6482581994fed5f0701df791f0325b1dc 1 parent afb1802
@crumbjp crumbjp authored
View
389 src/utils/beaks/Cockatoo/BeakMysql.php
@@ -1,389 +0,0 @@
-<?php
-/**
- * BeakMysql.php - Beak driver : Mysql base storage
- *
- * @package ????
- * @access public
- * @author hiroaki.kubota <hiroaki.kubota@mail.rakuten.com>
- * @create 2012/01/24
- * @version $Id$
- * @copyright Copyright (C) 2012, rakuten
- */
-namespace Cockatoo;
-require_once(Config::COCKATOO_ROOT.'utils/beak.php');
-
-
-/**
- * ??????????
- *
- * @author hiroaki.kubota <hiroaki.kubota@mail.rakuten.com>
- */
-class BeakMysql extends Beak {
-// const KEY_TYPE = 'VARCHAR(4096)';
- const KEY_TYPE = 'VARCHAR(255)';
- const VAL_TYPE = 'MEDIUMBLOB';
- /**
- * Index name
- */
- protected $uniqueIndex;
- /**
- * Mysql
- */
- protected $pdo;
- /**
- * Constructor
- *
- * @see Action.php
- */
- public function __construct(&$brl,&$scheme,&$domain,&$collection,&$path,&$method,&$queries,&$comments,&$arg,&$hide) {
- parent::__construct($brl,$scheme,$domain,&$collection,$path,$method,$queries,$comments,$arg,$hide);
- $this->uniqueIndex = isset($this->queries[Beak::Q_UNIQUE_INDEX])?$this->queries[Beak::Q_UNIQUE_INDEX]:Beak::Q_UNIQUE_INDEX;
-// $indexes = isset($this->queries[Beak::Q_INDEXES])?$this->queries[Beak::Q_INDEXES]:'';
-// if ( $indexes ) {
-// $this->indexes = explode(',',$indexes);
-// }
-
- $this->beakLocation = BeakLocationGetter::singleton();
- $base_brl = $scheme . '://' . $domain . '/';
- $locations = $this->beakLocation->getLocation(array($base_brl),'');
- if ( ! $locations[$base_brl] ) {
- Log::debug(__CLASS__ . '::' . __FUNCTION__ . ' : No location-info ' . $base_brl);
- return ;
- }
- // @@@ user / password
- $location = explode(':',$locations[$base_brl][array_rand($locations[$base_brl])]);
- $connect = 'mysql:host='.$location[0].';port='.$location[1].';dbname='.$this->domain;
- try {
- $this->pdo = new \PDO($connect,'root','root',array(\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
- }catch(\PDOException $e ){
- Log::error(__CLASS__ . '::' . __FUNCTION__ . ' : ' . 'Mysql error : ' . $e->getMessage(),$e);
- return;
- }
- }
- private function ddlQuery(&$query){
- Log::trace(__CLASS__ . '::' . __FUNCTION__ . ' : ddl query : ' . $query);
- return (bool)$this->pdo->query($query);
- }
- private function fetchQuery(&$query,&$bind=array()){
- Log::trace(__CLASS__ . '::' . __FUNCTION__ . ' : fetch query : ' . $query);
- $stmt = $this->pdo->prepare($query);
- foreach($bind as $k => $v ) {
- $stmt->bindParam($k,$v[1],$v[0]);
- }
- $stmt->execute();
- return $stmt->fetchAll(\PDO::FETCH_COLUMN);
- }
- private function execQuery(&$query,&$bind=array()){
- Log::trace(__CLASS__ . '::' . __FUNCTION__ . ' : exec query : ' . $query);
- $stmt = $this->pdo->prepare($query);
- foreach($bind as $k => $v ) {
- $stmt->bindParam($k,$v[1],$v[0]);
- }
- $stmt->execute();
- return $stmt->rowCount();
- }
- private static function encode($data){
- return serialize($data);
- }
- private static function decode($data){
- return unserialize($data);
- }
- /**
- * Craete collection and Create index
- *
- * @see Action.php
- */
- public function createColQuery(){
- if ( $this->pdo ) {
- if ( $this->renew ) {
- $ddl = 'DROP TABLE '.$this->collection;
- $this->ddlQuery($ddl);
- }
- $ddl = 'CREATE TABLE '.$this->collection.' ('.$this->uniqueIndex.' '.self::KEY_TYPE.' CHARACTER SET utf8 ,D '.self::VAL_TYPE.',_R INT,PRIMARY KEY('.$this->uniqueIndex.'))';
- $this->ret = $this->ddlQuery($ddl);
- }
- }
-
- /**
- * Get all collections name
- *
- * @see Action.php
- */
- public function listColQuery() {
- if ( $this->pdo ) {
- $ddl = 'SHOW TABLES';
- $this->ret = $this->fetchQuery($ddl);
- }
- }
-
- /**
- * Get all keys containing the collection.
- *
- * @see Action.php
- */
- public function listKeyQuery() {
- if ( $this->pdo ) {
- $sql = 'SELECT '.$this->uniqueIndex.' FROM '.$this->collection.' WHERE '.$this->uniqueIndex.' LIKE :u';
- $bind = array(
- ':u'=>array(\PDO::PARAM_STR,$this->path.'%'));
- $this->ret = $this->fetchQuery($sql,$bind);
- }
- }
-
- /**
- * T.B.D @@@
- *
- * @see Action.php
- */
- public function getaQuery() {
- if ( $this->pdo ) {
- $bind = array();
- $sql = 'SELECT D FROM '.$this->collection.' WHERE '.$this->uniqueIndex.' IN(';
- $i = 1;
- foreach ( $this->arg[$this->uniqueIndex] as $cond ) {
- if ( $i !== 1 ) {
- $sql .= ',';
- }
- $sql .= ':'.$i;
- $bind[':'.$i]= array(\PDO::PARAM_STR,$cond);
- $i++;
- }
- $sql .= ')';
- $ret = $this->fetchQuery($sql,$bind);
- foreach( $ret as $d ) {
- $r = self::decode($d);
- if ( $r[Beak::ATTR_REV] === 0 ) {
- unset($r[Beak::ATTR_REV]); // @@@
- }
- $this->ret[$r[$this->uniqueIndex]] = $r;
- }
- }
- }
-
- private function getDoc($path){
- $sql = 'SELECT D FROM '.$this->collection.' WHERE '.$this->uniqueIndex.'=:u';
- $bind = array(
- ':u'=>array(\PDO::PARAM_STR,$path));
- $ret = $this->fetchQuery($sql,$bind);
- if ( isset($ret[0]) ) {
- return self::decode($ret[0]);
- }
- return null;
- }
- /**
- * Get document data
- *
- * @see Action.php
- */
- public function getQuery() {
- if ( $this->pdo ) {
- $this->ret = $this->getDoc($this->path);
- if ( $this->ret[Beak::ATTR_REV] === 0 ) {
- unset($this->ret[Beak::ATTR_REV]); // @@@
- }
- }
- }
- /**
- * T.B.D @@@
- *
- * @see Action.php
- */
- public function delQuery() {
- if ( $this->pdo ) {
- $sql = 'DELETE FROM ' . $this->collection . ' WHERE '.$this->uniqueIndex.'=:u AND (_R=:c OR :c=0)';
- $rev = 0;
- if ( $this->rev ) {
- if ( $this->arg[Beak::ATTR_REV] ) {
- $rev = $this->arg[Beak::ATTR_REV];
- }
- $this->arg[Beak::ATTR_REV] = (String)time();
- }else{
- $this->arg[Beak::ATTR_REV] = 0;
- }
- $bind = array(
- ':u'=>array(\PDO::PARAM_STR,$this->path),
- ':c'=>array(\PDO::PARAM_INT,$rev)
- );
- $this->ret = $this->execQuery($sql,$bind);
- }
- }
- /**
- * T.B.D @@@
- *
- * @see Action.php
- */
- public function delaQuery() {
- if ( $this->pdo ) {
- $sql = 'DELETE FROM ' . $this->collection . ' WHERE '.$this->uniqueIndex.' IN(';
- $i = 1;
- foreach ( $this->arg[$this->uniqueIndex] as $cond ) {
- if ( $i !== 1 ) {
- $sql .= ',';
- }
- $sql .= ':'.$i;
- $bind[':'.$i]= array(\PDO::PARAM_STR,$cond);
- $i++;
- }
- $sql .= ')';
- $this->ret = $this->execQuery($sql,$bind);
- }
- }
- /**
- * Set multi document datas
- *
- * @see Action.php
- */
- public function setaQuery(){
- if ( $this->pdo ) {
- $this->ret = array();
- foreach ( $this->arg as $arg ) {
- $path = &$arg[$this->uniqueIndex];
- $this->ret[$path] = $this->setDoc($path,$arg);
- }
- }
- }
- private function setDoc(&$path,&$arg){
- $ret = null;
- if ( $this->partial) {
- $cur = $this->getDoc($path);
- if ( $cur ) {
- $arg = array_merge($cur,$arg);
- }
- }
- $arg[$this->uniqueIndex] = &$path;
- $sql = 'UPDATE ' . $this->collection . ' SET _R=:r,D=:d WHERE '.$this->uniqueIndex.'=:u AND (_R=:c OR :c=0)';
- $rev = 0;
-
- if ( $this->rev ) {
- if ( $arg[Beak::ATTR_REV] ) {
- $rev = $arg[Beak::ATTR_REV];
- }
- $arg[Beak::ATTR_REV] = (String)time();
- }else{
- $arg[Beak::ATTR_REV] = 0;
- }
- $bind = array(
- ':u'=>array(\PDO::PARAM_STR,$path),
- ':r'=>array(\PDO::PARAM_INT,$arg[Beak::ATTR_REV]),
- ':d'=>array(\PDO::PARAM_LOB,self::encode($arg)),
- ':c'=>array(\PDO::PARAM_INT,$rev)
- );
- $ret = $this->execQuery($sql,$bind);
- if ( ! $ret ){
- $sql = 'INSERT INTO ' . $this->collection . '('.$this->uniqueIndex.',_R,D) VALUES(:u,:r,:d)';
- $bind = array(
- ':u'=>array(\PDO::PARAM_STR,$path),
- ':r'=>array(\PDO::PARAM_INT,$arg[Beak::ATTR_REV]),
- ':d'=>array(\PDO::PARAM_LOB,self::encode($arg))
- );
- $ret = $this->execQuery($sql,$bind);
- }
- return (bool)$ret; // @@@
- }
- /**
- * Set document data
- *
- * @see Action.php
- */
- public function setQuery() {
- if ( $this->pdo ) {
- $this->ret = $this->setDoc($this->path,$this->arg);
- }
- }
- /**
- * Move collection
- */
- public function mvColQuery() {
- if ( $this->pdo and $this->queries[Beak::Q_NEWNAME] ) {
- $ddl = 'DROP TABLE '.$this->queries[Beak::Q_NEWNAME];
- $this->ddlQuery($ddl);
- $ddl = 'RENAME TABLE ' . $this->collection . ' TO ' . $this->queries[Beak::Q_NEWNAME];
- $this->ret = $this->ddlQuery($ddl);
- }
- }
-
-
- /**
- * Get operation results
- *
- * @see Action.php
- */
- public function result() {
- return $this->ret;
- }
-}
-
-function dump_result($results) {
- foreach ($results as $k => $v){
- if ( is_array($v) ) {
- print "[$k] => " . var_export($v,1) . "\n";
- }else {
- print "[$k] => $v\n";
- }
- }
-}
-
-/*
-try {
-$COCKATOO_CONF=getenv('COCKATOO_CONF');
-require_once($COCKATOO_CONF);
-
-$results = BeakController::beakQuery(array('storage://wiki-storage/test/?ccol#renew'));
-dump_result($results);
-$results = BeakController::beakQuery(array('storage://wiki-storage/test/?cols'));
-dump_result($results);
-$results = BeakController::beakQuery(array(array('storage://wiki-storage/test/foo?set#rev',array('_u'=>'foo','val1'=>'FOO'))));
-dump_result($results);
-
-$results = BeakController::beakQuery(array(array('storage://wiki-storage/test/foo?set#rev',array('_u'=>'foo','val2'=>'BAR','@R'=>1))));
-dump_result($results);
-$results = BeakController::beakQuery(array('storage://wiki-storage/test/foo?get'));
-dump_result($results);
-sleep(1);
-$d = $results['storage://wiki-storage/test/foo?get'];
-$d['val3']='BAZ';
-$results = BeakController::beakQuery(array(array('storage://wiki-storage/test/foo?set#rev',$d)));
-dump_result($results);
-$results = BeakController::beakQuery(array('storage://wiki-storage/test/foo?get'));
-dump_result($results);
-$results = BeakController::beakQuery(array(array('storage://wiki-storage/test/bar?set',array('_u'=>'bar','val'=>'FOO'))));
-dump_result($results);
-$results = BeakController::beakQuery(array(array('storage://wiki-storage/test/bar?set',array('_u'=>'bar','val2'=>'BAR'))));
-dump_result($results);
-$results = BeakController::beakQuery(array(array('storage://wiki-storage/test/baz?set',array('_u'=>'baz','val1'=>'BAZ'))));
-dump_result($results);
-$results = BeakController::beakQuery(array(array('storage://wiki-storage/test/?setA',
- array('foobar' => array('_u'=>'foobar','val1'=>'FOOBAR'),
- 'xyzzy' => array('_u'=>'xyzzy','val1'=>'XYZZY'))
- )));
-dump_result($results);
-$results = BeakController::beakQuery(array('storage://wiki-storage/test/b?keys'));
-dump_result($results);
-$results = BeakController::beakGetsQuery(array('storage://wiki-storage/test/foo?get','storage://wiki-storage/test/bar?get','storage://wiki-storage/test/baz?get'));
-foreach ( $results as $result ) {
- dump_result($result);
-}
-$results = BeakController::beakQuery(array('storage://wiki-storage/test/?keys'));
-dump_result($results);
-$results = BeakController::beakQuery(array('storage://wiki-storage/test/baz?del'));
-dump_result($results);
-$results = BeakController::beakQuery(array('storage://wiki-storage/test/?keys'));
-dump_result($results);
-$results = BeakController::beakQuery(array(array('storage://wiki-storage/test/?delA',
- array('_u' => array('foobar','xyzzy')))));
-dump_result($results);
-$results = BeakController::beakQuery(array('storage://wiki-storage/test/?keys'));
-dump_result($results);
-
-
-$results = BeakController::beakQuery(array('storage://wiki-storage/test/?mcol&_new=test2'));
-dump_result($results);
-$results = BeakController::beakQuery(array('storage://wiki-storage/test2/?keys'));
-dump_result($results);
-
-}catch( \Exception $e ) {
- var_dump('@@@@@@@@');
- var_dump($e->getMessage());
- var_dump($e);
-}
-*/
View
11 test/phpunit.sh
@@ -4,17 +4,14 @@ rm -rf report
rm -f coverage.dat
export COCKATOO_CONF=`pwd`/config.php
export TZ=Asia/Tokyo
-#phpunit --process-isolation --coverage-html `pwd`/report --aggregate `pwd`/coverage.dat `pwd`/testcase
rm testcase/beak/BeakFileTest.php
rm testcase/beak/BeakMongoTest.php
rm testcase/beak/BeakMemcachedTest.php
-rm testcase/beak/BeakMysqlTest.php
bash testcase/beak/BeakFileTest.template > testcase/beak/BeakFileTest.php
bash testcase/beak/BeakMongoTest.template > testcase/beak/BeakMongoTest.php
bash testcase/beak/BeakMemcachedTest.template > testcase/beak/BeakMemcachedTest.php
-#bash testcase/beak/BeakMysqlTest.template > testcase/beak/BeakMysqlTest.php
-#phpunit --coverage-html `pwd`/report --aggregate `pwd`/coverage.dat `pwd`/testcase/beak
-phpunit `pwd`/testcase/beak
-
-# phpunit --coverage-html `pwd`/report --aggregate `pwd`/coverage.dat `pwd`/testcase/urlparse
+#phpunit --process-isolation --coverage-html `pwd`/report `pwd`/testcase/beak
+#phpunit --process-isolation --coverage-html `pwd`/report `pwd`/testcase/urlparse
+#phpunit --process-isolation --coverage-html `pwd`/report `pwd`/testcase/www
+phpunit --process-isolation --coverage-html `pwd`/report `pwd`/testcase
View
7 test/testcase/beak/BeakTest.php
@@ -5,13 +5,10 @@
class BeakTest extends \PHPUnit_Framework_TestCase
{
- public function __construct(){
- }
public function setUp(){
}
- // public function tearDown(){
- // print "tearDown\n";
- // }
+ public function tearDown(){
+ }
public static function tearDownAfterClass() {
}
View
188 test/testcase/urlparse/WikiUrlParserTest.php
@@ -0,0 +1,188 @@
+<?php
+namespace Cockatoo;
+require_once('/usr/local/cockatoo/def.php');
+require_once(Config::COCKATOO_ROOT.'utils/beak.php');
+require_once(Config::COCKATOO_ROOT.'wwwutils/core/reqparser.php');
+$CUR=dirname(__FILE__);
+require_once($CUR.'/../../wwwbootstrap.php');
+
+class WikiUrlParserTest extends \PHPUnit_Framework_TestCase
+{
+ public function setUp(){
+ }
+ public function tearDown(){
+ }
+ public function testFavicon(){
+ global $HEADER,$_SERVER,$_GET,$_COOKIE;
+ pre_www('index.php','/favicon.ico');
+ list($SERVICE,$DEVICE,$PATH,$ARGS,$SESSION_PATH) = parseRequest($HEADER,$_SERVER,$_GET,$_COOKIE);
+ $this->assertEquals('wiki',$SERVICE);
+ $this->assertEquals('default',$DEVICE);
+ $this->assertEquals('img',$PATH);
+ $this->assertEquals('/',$SESSION_PATH);
+ $this->assertEquals(array(
+ 'P' => 'Cockatoo PHP framework',
+ 'N' => 'logo.png',
+ ),$ARGS);
+ }
+ public function testTop(){
+ global $HEADER,$_SERVER,$_GET,$_COOKIE;
+ pre_www('index.php','/wiki/view/');
+ list($SERVICE,$DEVICE,$PATH,$ARGS,$SESSION_PATH) = parseRequest($HEADER,$_SERVER,$_GET,$_COOKIE);
+ $this->assertEquals('wiki',$SERVICE);
+ $this->assertEquals('default',$DEVICE);
+ $this->assertEquals('view',$PATH);
+ $this->assertEquals('/wiki',$SESSION_PATH);
+ $this->assertEquals(array(
+ 'P' => ''
+ ),$ARGS);
+ }
+ public function testPage(){
+ global $HEADER,$_SERVER,$_GET,$_COOKIE;
+ pre_www('index.php','/wiki/view/pagename');
+ list($SERVICE,$DEVICE,$PATH,$ARGS,$SESSION_PATH) = parseRequest($HEADER,$_SERVER,$_GET,$_COOKIE);
+ $this->assertEquals('wiki',$SERVICE);
+ $this->assertEquals('default',$DEVICE);
+ $this->assertEquals('view',$PATH);
+ $this->assertEquals('/wiki',$SESSION_PATH);
+ $this->assertEquals(array(
+ 'P' => 'pagename'
+ ),$ARGS);
+ }
+ public function testEdit(){
+ global $HEADER,$_SERVER,$_GET,$_COOKIE;
+ pre_www('index.php','/wiki/edit/pagename');
+ list($SERVICE,$DEVICE,$PATH,$ARGS,$SESSION_PATH) = parseRequest($HEADER,$_SERVER,$_GET,$_COOKIE);
+ $this->assertEquals('wiki',$SERVICE);
+ $this->assertEquals('default',$DEVICE);
+ $this->assertEquals('edit',$PATH);
+ $this->assertEquals('/wiki',$SESSION_PATH);
+ $this->assertEquals(array(
+ 'P' => 'pagename'
+ ),$ARGS);
+ }
+ public function testImg(){
+ global $HEADER,$_SERVER,$_GET,$_COOKIE;
+ pre_www('index.php','/wiki/img/pagename',array('n' => 'logo.png'));
+ list($SERVICE,$DEVICE,$PATH,$ARGS,$SESSION_PATH) = parseRequest($HEADER,$_SERVER,$_GET,$_COOKIE);
+ $this->assertEquals('wiki',$SERVICE);
+ $this->assertEquals('default',$DEVICE);
+ $this->assertEquals('img',$PATH);
+ $this->assertEquals('/wiki',$SESSION_PATH);
+ $this->assertEquals(array(
+ 'P' => 'pagename'
+ ),$ARGS);
+ }
+ public function testUpload(){
+ global $HEADER,$_SERVER,$_GET,$_COOKIE;
+ pre_www('index.php','/wiki/upload/pagename');
+ list($SERVICE,$DEVICE,$PATH,$ARGS,$SESSION_PATH) = parseRequest($HEADER,$_SERVER,$_GET,$_COOKIE);
+ $this->assertEquals('wiki',$SERVICE);
+ $this->assertEquals('default',$DEVICE);
+ $this->assertEquals('upload',$PATH);
+ $this->assertEquals('/wiki',$SESSION_PATH);
+ $this->assertEquals(array(
+ 'P' => 'pagename'
+ ),$ARGS);
+ }
+ public function testUploaded(){
+ global $HEADER,$_SERVER,$_GET,$_COOKIE;
+ pre_www('index.php','/wiki/uploaded/pagename');
+ list($SERVICE,$DEVICE,$PATH,$ARGS,$SESSION_PATH) = parseRequest($HEADER,$_SERVER,$_GET,$_COOKIE);
+ $this->assertEquals('wiki',$SERVICE);
+ $this->assertEquals('default',$DEVICE);
+ $this->assertEquals('uploaded',$PATH);
+ $this->assertEquals('/wiki',$SESSION_PATH);
+ $this->assertEquals(array(
+ 'P' => 'pagename'
+ ),$ARGS);
+ }
+ public function testOther(){
+ global $HEADER,$_SERVER,$_GET,$_COOKIE;
+ pre_www('index.php','/wiki/error');
+ list($SERVICE,$DEVICE,$PATH,$ARGS,$SESSION_PATH) = parseRequest($HEADER,$_SERVER,$_GET,$_COOKIE);
+ $this->assertEquals('wiki',$SERVICE);
+ $this->assertEquals('default',$DEVICE);
+ $this->assertEquals('error',$PATH);
+ $this->assertEquals('/wiki',$SESSION_PATH);
+ $this->assertEquals(array(),$ARGS);
+ }
+ public function testAndroidView1(){
+ global $HEADER,$_SERVER,$_GET,$_COOKIE;
+ pre_www('index.php','/wiki/android/view/pagename');
+ list($SERVICE,$DEVICE,$PATH,$ARGS,$SESSION_PATH) = parseRequest($HEADER,$_SERVER,$_GET,$_COOKIE);
+ $this->assertEquals('wiki',$SERVICE);
+ $this->assertEquals('android',$DEVICE);
+ $this->assertEquals('view',$PATH);
+ $this->assertEquals('/wiki',$SESSION_PATH);
+ $this->assertEquals(array(
+ 'P' => 'pagename'
+ ),$ARGS);
+ }
+ public function testAndroidView2(){
+ global $HEADER,$_SERVER,$_GET,$_COOKIE;
+ pre_www('index.php','/wiki/view/pagename',array(),array(),array(),array('User-Agent' => 'Mozilla/5.0 (Linux; U; Android 2.3.4; ja-jp; ISW11HT Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'));
+ list($SERVICE,$DEVICE,$PATH,$ARGS,$SESSION_PATH) = parseRequest($HEADER,$_SERVER,$_GET,$_COOKIE);
+ $this->assertEquals('wiki',$SERVICE);
+ $this->assertEquals('android',$DEVICE);
+ $this->assertEquals('view',$PATH);
+ $this->assertEquals('/wiki',$SESSION_PATH);
+ $this->assertEquals(array(
+ 'P' => 'pagename'
+ ),$ARGS);
+ }
+ public function testAndroidImg1(){
+ global $HEADER,$_SERVER,$_GET,$_COOKIE;
+ pre_www('index.php','/wiki/android/img/pagename',array('n' => 'logo.png'),array(),array(),array());
+ list($SERVICE,$DEVICE,$PATH,$ARGS,$SESSION_PATH) = parseRequest($HEADER,$_SERVER,$_GET,$_COOKIE);
+ $this->assertEquals('wiki',$SERVICE);
+ $this->assertEquals('android',$DEVICE);
+ $this->assertEquals('img',$PATH);
+ $this->assertEquals('/wiki',$SESSION_PATH);
+ $this->assertEquals(array(
+ 'P' => 'pagename'
+ ),$ARGS);
+ }
+ public function testAndroidImg2(){
+ global $HEADER,$_SERVER,$_GET,$_COOKIE;
+ pre_www('index.php','/wiki/img/pagename',array('n' => 'logo.png'),array(),array(),array('User-Agent' => 'Mozilla/5.0 (Linux; U; Android 2.3.4; ja-jp; ISW11HT Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'));
+ list($SERVICE,$DEVICE,$PATH,$ARGS,$SESSION_PATH) = parseRequest($HEADER,$_SERVER,$_GET,$_COOKIE);
+ $this->assertEquals('wiki',$SERVICE);
+ $this->assertEquals('android',$DEVICE);
+ $this->assertEquals('img',$PATH);
+ $this->assertEquals('/wiki',$SESSION_PATH);
+ $this->assertEquals(array(
+ 'P' => 'pagename'
+ ),$ARGS);
+ }
+ public function testAndroidOther(){
+ global $HEADER,$_SERVER,$_GET,$_COOKIE;
+ pre_www('index.php','/wiki/android/error');
+ list($SERVICE,$DEVICE,$PATH,$ARGS,$SESSION_PATH) = parseRequest($HEADER,$_SERVER,$_GET,$_COOKIE);
+ $this->assertEquals('wiki',$SERVICE);
+ $this->assertEquals('android',$DEVICE);
+ $this->assertEquals('error',$PATH);
+ $this->assertEquals('/wiki',$SESSION_PATH);
+ $this->assertEquals(array(),$ARGS);
+ }
+ public function testOtherService(){
+ global $HEADER,$_SERVER,$_GET,$_COOKIE;
+ pre_www('index.php','/yslowviewer/default/main');
+ list($SERVICE,$DEVICE,$PATH,$ARGS,$SESSION_PATH) = parseRequest($HEADER,$_SERVER,$_GET,$_COOKIE);
+ $this->assertEquals('yslowviewer',$SERVICE);
+ $this->assertEquals('default',$DEVICE);
+ $this->assertEquals('main',$PATH);
+ $this->assertEquals('/yslowviewer',$SESSION_PATH);
+ $this->assertEquals(array(),$ARGS);
+ }
+ public function testAnyOther(){
+ global $HEADER,$_SERVER,$_GET,$_COOKIE;
+ pre_www('index.php','/');
+ try{
+ list($SERVICE,$DEVICE,$PATH,$ARGS,$SESSION_PATH) = parseRequest($HEADER,$_SERVER,$_GET,$_COOKIE);
+ }catch(\Exception $e){
+ return; // Should be ERROR and Redirect to Config::ErrorRedirect
+ }
+ $this->assertTrue(false,'Unexpected parse');
+ }
+}
View
102 test/testcase/www/WwwTest.php
@@ -0,0 +1,102 @@
+<?php
+namespace Cockatoo;
+require_once('/usr/local/cockatoo/def.php');
+require_once(Config::COCKATOO_ROOT.'utils/beak.php');
+require_once(Config::COCKATOO_ROOT.'wwwutils/core/reqparser.php');
+$CUR=dirname(__FILE__);
+require_once($CUR.'/../../wwwbootstrap.php');
+
+class WwwTest extends \PHPUnit_Framework_TestCase {
+ public function setUp(){
+ }
+ public function tearDown(){
+ }
+ public function testTestHtml(){
+ global $HEADER,$_SERVER,$_GET,$_COOKIE;
+ $HTML = run_www('index.php','/fortest/default/main');
+ $EXPECTS=<<<__HTML__
+HTTP/1.1 200 OK
+Content-type: text/html
+X-FORTEST: 1
+X-FORTEST-MAIN:1
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+FORTEST HEADER
+MAIN header
+<link rel="stylesheet" type="text/css" media="all" href="/_s_/core/default/css/cockatoo.css"></link><link rel="stylesheet" type="text/css" media="all" href="/_s_/fortest/default/css/cockatoo.css"></link>
+<style type="text/css">
+<!--
+// TEST0 CSS
+// TEST2 CSS
+// TEST3 CSS
+// TEST1 CSS
+
+-->
+</style>
+</head>
+<body id="co-frame">
+ <div id="co-main">
+<div class=" co-Widget co-Horizontal" extra=""><div class="co-Wbody"><div id="test0" class=" co-Widget test0 co-Horizontal" extra=""><div class="co-Wbody">TEST0 body
+</div></div><div class=" co-Widget co-Horizontal" extra=""><div class="co-Wbody"><div id="test2" class=" co-Widget test2 co-Horizontal" extra=""><div class="co-Wbody">TEST2 body
+<div id="test3" class=" co-Widget test3 co-Horizontal" extra=""><div class="co-Wbody">TEST3 body
+</div></div></div></div></div></div><div id="test1" class=" co-Widget test1 co-Horizontal" extra=""><div class="co-Wbody">TEST1 body
+</div></div></div></div> </div>
+FORTEST body bottom
+MAIN body bottom
+<script type="text/javascript" src="/_s_/core/default/js/cockatoo.js"></script><script type="text/javascript" src="/_s_/fortest/default/js/cockatoo.js"></script>
+<script type="text/javascript">
+<!--
+// TEST0 JS
+// TEST2 JS
+// TEST3 JS
+// TEST1 JS
+
+-->
+</script>
+</body>
+</html>
+
+__HTML__;
+ $this->assertEquals($EXPECTS,$HTML);
+ }
+ public function testWikiTop(){
+ global $HEADER,$_SERVER,$_GET,$_COOKIE;
+ $HTML = run_www('index.php','/wiki/view');
+ $EXPECTS='cockatoo-wiki: Cockatoo PHP framework';
+
+ foreach( explode("\n",$HTML) as $line ){
+ if ( preg_match('@<title>(.*)</title>@',$line,$matches ) !== 0) {
+ $this->assertEquals($EXPECTS,$matches[1]);
+ return;
+ }
+ }
+ $this->assertTrue(false,'No page title');
+ }
+ public function testWikiRedirect(){
+ global $HEADER,$_SERVER,$_GET,$_COOKIE;
+ $HTML = run_www('index.php','/wiki/XXX');
+ $EXPECTS='/wiki/view'; // Error redirect
+
+ foreach( explode("\n",$HTML) as $line ){
+ if ( preg_match('@Location:\s*(.*)@',$line,$matches ) !== 0) {
+ $this->assertEquals($EXPECTS,$matches[1]);
+ return;
+ }
+ }
+ $this->assertTrue(false,'Unexpected page');
+ }
+
+ public function testWikiFallback(){
+ global $HEADER,$_SERVER,$_GET,$_COOKIE;
+ $BIN = run_www('index.php','/wiki/android/img/',array('n'=>'logo.png','debug'=>'1'));
+
+ foreach( explode("\n",$BIN) as $line ){
+ if ( preg_match('@- A\.wiki\.img\.\*bin@',$line,$matches ) !== 0) {
+ $this->assertTrue(true,'');
+ return;
+ }
+ }
+ $this->assertTrue(false,'Unexpected page');
+ }
+}
View
26 test/wwwbootstrap.php
@@ -1,7 +1,7 @@
<?php
namespace Cockatoo;
-$COCKATOO_CONF=getenv('COCKATOO_CONF');
-require_once($COCKATOO_CONF);
+require_once('/usr/local/cockatoo/def.php');
+require_once(Config::COCKATOO_ROOT.'utils/beak.php');
$_SERVER;
$HEADER;
@@ -61,19 +61,23 @@ function header($output){
print $output."\n";
}
-$OUTPUT;
-function run_www ($file,$uri,$get=array(),$post=array(),$server=array(),$header=array()){
- global $_GET,$_POST,$_SERVER,$HEADER,$OUTPUT,$COCKATOO_ROOT;
+function pre_www ($file,$uri,$get=array(),$post=array(),$server=array(),$header=array(),$cookie=array()){
+ global $_GET,$_POST,$_SERVER,$HEADER;
default_args();
- $PATH=$COCKATOO_ROOT.'www/';
+ $PATH=Config::COCKATOO_ROOT.'www/';
$_SERVER['SCRIPT_FILENAME'] = $PATH . $file;
$_SERVER['SCRIPT_NAME'] = $file;
$_SERVER['PHP_SELF'] = $file;
$_SERVER['REDIRECT_URL'] = $uri;
$ruri = $uri;
+ $token = '?';
+ if ( preg_match('@\?@',$ruri,$matches) !== 0 ) {
+ $token = '&';
+ }
foreach($get as $k => $v ) {
- $ruri.= '&' . $k . '=' . $v;
+ $ruri.= $token . $k . '=' . $v;
+ $token = '&';
}
$_SERVER['REQUEST_URI']=$ruri;
$_SERVER['QUERY_STRING'] = 'r='.$ruri;
@@ -85,7 +89,15 @@ function run_www ($file,$uri,$get=array(),$post=array(),$server=array(),$header=
$_POST = $post;
$_GET = $get;
$_GET['r'] = $uri;
+ $_COOKIE = $cookie;
+}
+
+$OUTPUT;
+function run_www ($file,$uri,$get=array(),$post=array(),$server=array(),$header=array(),$cookie=array()){
+ global $OUTPUT;
+ pre_www($file,$uri,$get,$post,$server,$header);
+ $PATH=Config::COCKATOO_ROOT.'www/';
$OUTPUT='';
ob_start("Cockatoo\www_output");
include($PATH . $file);
Please sign in to comment.
Something went wrong with that request. Please try again.