Merge branch 'master' into calendar_repeat
This commit is contained in:
commit
f7366de673
|
@ -1,9 +1,5 @@
|
||||||
ErrorDocument 403 /core/templates/403.php
|
ErrorDocument 403 /core/templates/403.php
|
||||||
ErrorDocument 404 /core/templates/404.php
|
ErrorDocument 404 /core/templates/404.php
|
||||||
Redirect 301 /apps/calendar/caldav.php /remote.php/caldav/
|
|
||||||
Redirect 301 /apps/contacts/carddav.php /remote.php/carddav/
|
|
||||||
Redirect 301 /apps/files/webdav.php /remote.php/webdav/
|
|
||||||
Redirect 301 /files/webdav.php /remote.php/webdav/
|
|
||||||
<IfModule mod_php5.c>
|
<IfModule mod_php5.c>
|
||||||
php_value upload_max_filesize 512M
|
php_value upload_max_filesize 512M
|
||||||
php_value post_max_size 512M
|
php_value post_max_size 512M
|
||||||
|
@ -18,6 +14,8 @@ RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
|
||||||
RewriteRule ^.well-known/host-meta /public.php?service=host-meta [QSA,L]
|
RewriteRule ^.well-known/host-meta /public.php?service=host-meta [QSA,L]
|
||||||
RewriteRule ^.well-known/carddav /remote.php/carddav/ [R]
|
RewriteRule ^.well-known/carddav /remote.php/carddav/ [R]
|
||||||
RewriteRule ^.well-known/caldav /remote.php/caldav/ [R]
|
RewriteRule ^.well-known/caldav /remote.php/caldav/ [R]
|
||||||
|
RewriteRule ^apps/calendar/caldav.php remote.php/caldav/ [QSA,L]
|
||||||
|
RewriteRule ^apps/contacts/carddav.php remote.php/carddav/ [QSA,L]
|
||||||
RewriteRule ^apps/([^/]*)/(.*\.(css|php))$ index.php?app=$1&getfile=$2 [QSA,L]
|
RewriteRule ^apps/([^/]*)/(.*\.(css|php))$ index.php?app=$1&getfile=$2 [QSA,L]
|
||||||
RewriteRule ^remote/(.*) remote.php [QSA,L]
|
RewriteRule ^remote/(.*) remote.php [QSA,L]
|
||||||
</IfModule>
|
</IfModule>
|
||||||
|
|
|
@ -577,7 +577,7 @@ class Archive_Tar extends PEAR
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----- Get the arguments
|
// ----- Get the arguments
|
||||||
$v_att_list = &func_get_args();
|
$v_att_list = func_get_args();
|
||||||
|
|
||||||
// ----- Read the attributes
|
// ----- Read the attributes
|
||||||
$i=0;
|
$i=0;
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -42,7 +42,7 @@
|
||||||
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
||||||
// +----------------------------------------------------------------------+
|
// +----------------------------------------------------------------------+
|
||||||
//
|
//
|
||||||
// $Id: Date.php 208329 2006-03-01 12:15:38Z lsmith $
|
// $Id$
|
||||||
//
|
//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
||||||
// +----------------------------------------------------------------------+
|
// +----------------------------------------------------------------------+
|
||||||
//
|
//
|
||||||
// $Id: Common.php 300551 2010-06-17 21:54:16Z quipo $
|
// $Id$
|
||||||
|
|
||||||
require_once 'MDB2/LOB.php';
|
require_once 'MDB2/LOB.php';
|
||||||
|
|
||||||
|
@ -263,7 +263,11 @@ class MDB2_Driver_Datatype_Common extends MDB2_Module_Common
|
||||||
*/
|
*/
|
||||||
function convertResultRow($types, $row, $rtrim = true)
|
function convertResultRow($types, $row, $rtrim = true)
|
||||||
{
|
{
|
||||||
$types = $this->_sortResultFieldTypes(array_keys($row), $types);
|
//$types = $this->_sortResultFieldTypes(array_keys($row), $types);
|
||||||
|
$keys = array_keys($row);
|
||||||
|
if (is_int($keys[0])) {
|
||||||
|
$types = $this->_sortResultFieldTypes($keys, $types);
|
||||||
|
}
|
||||||
foreach ($row as $key => $value) {
|
foreach ($row as $key => $value) {
|
||||||
if (empty($types[$key])) {
|
if (empty($types[$key])) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -515,9 +519,6 @@ class MDB2_Driver_Datatype_Common extends MDB2_Module_Common
|
||||||
$default = ' DEFAULT ' . $this->quote($field['default'], $field['type']);
|
$default = ' DEFAULT ' . $this->quote($field['default'], $field['type']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (empty($default) && empty($notnull)) {
|
|
||||||
$default = ' DEFAULT NULL';
|
|
||||||
}
|
|
||||||
|
|
||||||
$collation = empty($field['collation']) ? '' :
|
$collation = empty($field['collation']) ? '' :
|
||||||
' '.$this->_getCollationFieldDeclaration($field['collation']);
|
' '.$this->_getCollationFieldDeclaration($field['collation']);
|
||||||
|
@ -1382,7 +1383,7 @@ class MDB2_Driver_Datatype_Common extends MDB2_Module_Common
|
||||||
if (PEAR::isError($db)) {
|
if (PEAR::isError($db)) {
|
||||||
return $db;
|
return $db;
|
||||||
}
|
}
|
||||||
if (isset($db->function) && is_a($db->function, 'MDB2_Driver_Function_Common')) {
|
if (isset($db->function) && is_object($this->function) && is_a($db->function, 'MDB2_Driver_Function_Common')) {
|
||||||
return $db->function->now('date');
|
return $db->function->now('date');
|
||||||
}
|
}
|
||||||
return 'CURRENT_DATE';
|
return 'CURRENT_DATE';
|
||||||
|
@ -1411,7 +1412,7 @@ class MDB2_Driver_Datatype_Common extends MDB2_Module_Common
|
||||||
if (PEAR::isError($db)) {
|
if (PEAR::isError($db)) {
|
||||||
return $db;
|
return $db;
|
||||||
}
|
}
|
||||||
if (isset($db->function) && is_a($db->function, 'MDB2_Driver_Function_Common')) {
|
if (isset($db->function) && is_object($this->function) && is_a($db->function, 'MDB2_Driver_Function_Common')) {
|
||||||
return $db->function->now('timestamp');
|
return $db->function->now('timestamp');
|
||||||
}
|
}
|
||||||
return 'CURRENT_TIMESTAMP';
|
return 'CURRENT_TIMESTAMP';
|
||||||
|
@ -1440,7 +1441,7 @@ class MDB2_Driver_Datatype_Common extends MDB2_Module_Common
|
||||||
if (PEAR::isError($db)) {
|
if (PEAR::isError($db)) {
|
||||||
return $db;
|
return $db;
|
||||||
}
|
}
|
||||||
if (isset($db->function) && is_a($db->function, 'MDB2_Driver_Function_Common')) {
|
if (isset($db->function) && is_object($this->function) && is_a($db->function, 'MDB2_Driver_Function_Common')) {
|
||||||
return $db->function->now('time');
|
return $db->function->now('time');
|
||||||
}
|
}
|
||||||
return 'CURRENT_TIME';
|
return 'CURRENT_TIME';
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
||||||
// +----------------------------------------------------------------------+
|
// +----------------------------------------------------------------------+
|
||||||
//
|
//
|
||||||
// $Id: mysql.php 295587 2010-02-28 17:16:38Z quipo $
|
// $Id$
|
||||||
//
|
//
|
||||||
|
|
||||||
require_once 'MDB2/Driver/Datatype/Common.php';
|
require_once 'MDB2/Driver/Datatype/Common.php';
|
||||||
|
@ -88,6 +88,35 @@ class MDB2_Driver_Datatype_mysql extends MDB2_Driver_Datatype_Common
|
||||||
return 'COLLATE '.$collation;
|
return 'COLLATE '.$collation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// {{{ getDeclaration()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtain DBMS specific SQL code portion needed to declare
|
||||||
|
* of the given type
|
||||||
|
*
|
||||||
|
* @param string $type type to which the value should be converted to
|
||||||
|
* @param string $name name the field to be declared.
|
||||||
|
* @param string $field definition of the field
|
||||||
|
*
|
||||||
|
* @return string DBMS-specific SQL code portion that should be used to
|
||||||
|
* declare the specified field.
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function getDeclaration($type, $name, $field)
|
||||||
|
{
|
||||||
|
// MySQL DDL syntax forbids combining NOT NULL with DEFAULT NULL.
|
||||||
|
// To get a default of NULL for NOT NULL columns, omit it.
|
||||||
|
if ( isset($field['notnull'])
|
||||||
|
&& !empty($field['notnull'])
|
||||||
|
&& array_key_exists('default', $field) // do not use isset() here!
|
||||||
|
&& null === $field['default']
|
||||||
|
) {
|
||||||
|
unset($field['default']);
|
||||||
|
}
|
||||||
|
return parent::getDeclaration($type, $name, $field);
|
||||||
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ getTypeDeclaration()
|
// {{{ getTypeDeclaration()
|
||||||
|
|
||||||
|
@ -179,7 +208,15 @@ class MDB2_Driver_Datatype_mysql extends MDB2_Driver_Datatype_Common
|
||||||
case 'timestamp':
|
case 'timestamp':
|
||||||
return 'DATETIME';
|
return 'DATETIME';
|
||||||
case 'float':
|
case 'float':
|
||||||
return 'DOUBLE';
|
$l = '';
|
||||||
|
if (!empty($field['length'])) {
|
||||||
|
$l = '(' . $field['length'];
|
||||||
|
if (!empty($field['scale'])) {
|
||||||
|
$l .= ',' . $field['scale'];
|
||||||
|
}
|
||||||
|
$l .= ')';
|
||||||
|
}
|
||||||
|
return 'DOUBLE' . $l;
|
||||||
case 'decimal':
|
case 'decimal':
|
||||||
$length = !empty($field['length']) ? $field['length'] : 18;
|
$length = !empty($field['length']) ? $field['length'] : 18;
|
||||||
$scale = !empty($field['scale']) ? $field['scale'] : $db->options['decimal_places'];
|
$scale = !empty($field['scale']) ? $field['scale'] : $db->options['decimal_places'];
|
||||||
|
@ -513,6 +550,9 @@ class MDB2_Driver_Datatype_mysql extends MDB2_Driver_Datatype_Common
|
||||||
case 'real':
|
case 'real':
|
||||||
$type[] = 'float';
|
$type[] = 'float';
|
||||||
$unsigned = preg_match('/ unsigned/i', $field['type']);
|
$unsigned = preg_match('/ unsigned/i', $field['type']);
|
||||||
|
if ($decimal !== false) {
|
||||||
|
$length = $length.','.$decimal;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'unknown':
|
case 'unknown':
|
||||||
case 'decimal':
|
case 'decimal':
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
// | Author: Paul Cooper <pgc@ucecom.com> |
|
// | Author: Paul Cooper <pgc@ucecom.com> |
|
||||||
// +----------------------------------------------------------------------+
|
// +----------------------------------------------------------------------+
|
||||||
//
|
//
|
||||||
// $Id: pgsql.php 298763 2010-04-29 08:49:41Z afz $
|
// $Id$
|
||||||
|
|
||||||
require_once 'MDB2/Driver/Datatype/Common.php';
|
require_once 'MDB2/Driver/Datatype/Common.php';
|
||||||
|
|
||||||
|
@ -246,9 +246,11 @@ class MDB2_Driver_Datatype_pgsql extends MDB2_Driver_Datatype_Common
|
||||||
if (PEAR::isError($db)) {
|
if (PEAR::isError($db)) {
|
||||||
return $db;
|
return $db;
|
||||||
}
|
}
|
||||||
$value = $this->_readFile($value, $db->options['lob_allow_url_include']);
|
if ($db->options['lob_allow_url_include']) {
|
||||||
if (PEAR::isError($value)) {
|
$value = $this->_readFile($value);
|
||||||
return $value;
|
if (PEAR::isError($value)) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $this->_quoteText($value, $quote, $escape_wildcards);
|
return $this->_quoteText($value, $quote, $escape_wildcards);
|
||||||
}
|
}
|
||||||
|
@ -276,9 +278,11 @@ class MDB2_Driver_Datatype_pgsql extends MDB2_Driver_Datatype_Common
|
||||||
if (PEAR::isError($db)) {
|
if (PEAR::isError($db)) {
|
||||||
return $db;
|
return $db;
|
||||||
}
|
}
|
||||||
$value = $this->_readFile($value, $db->options['lob_allow_url_include']);
|
if ($db->options['lob_allow_url_include']) {
|
||||||
if (PEAR::isError($value)) {
|
$value = $this->_readFile($value);
|
||||||
return $value;
|
if (PEAR::isError($value)) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (version_compare(PHP_VERSION, '5.2.0RC6', '>=')) {
|
if (version_compare(PHP_VERSION, '5.2.0RC6', '>=')) {
|
||||||
$connection = $db->getConnection();
|
$connection = $db->getConnection();
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
||||||
// +----------------------------------------------------------------------+
|
// +----------------------------------------------------------------------+
|
||||||
//
|
//
|
||||||
// $Id: sqlite.php 295587 2010-02-28 17:16:38Z quipo $
|
// $Id$
|
||||||
//
|
//
|
||||||
|
|
||||||
require_once 'MDB2/Driver/Datatype/Common.php';
|
require_once 'MDB2/Driver/Datatype/Common.php';
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
||||||
// +----------------------------------------------------------------------+
|
// +----------------------------------------------------------------------+
|
||||||
//
|
//
|
||||||
// $Id: Common.php 295587 2010-02-28 17:16:38Z quipo $
|
// $Id$
|
||||||
//
|
//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
||||||
// +----------------------------------------------------------------------+
|
// +----------------------------------------------------------------------+
|
||||||
//
|
//
|
||||||
// $Id: mysql.php 295587 2010-02-28 17:16:38Z quipo $
|
// $Id$
|
||||||
//
|
//
|
||||||
|
|
||||||
require_once 'MDB2/Driver/Function/Common.php';
|
require_once 'MDB2/Driver/Function/Common.php';
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
// | Author: Paul Cooper <pgc@ucecom.com> |
|
// | Author: Paul Cooper <pgc@ucecom.com> |
|
||||||
// +----------------------------------------------------------------------+
|
// +----------------------------------------------------------------------+
|
||||||
//
|
//
|
||||||
// $Id: pgsql.php 296139 2010-03-13 04:15:22Z afz $
|
// $Id$
|
||||||
|
|
||||||
require_once 'MDB2/Driver/Function/Common.php';
|
require_once 'MDB2/Driver/Function/Common.php';
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
||||||
// +----------------------------------------------------------------------+
|
// +----------------------------------------------------------------------+
|
||||||
//
|
//
|
||||||
// $Id: sqlite.php 295587 2010-02-28 17:16:38Z quipo $
|
// $Id$
|
||||||
//
|
//
|
||||||
|
|
||||||
require_once 'MDB2/Driver/Function/Common.php';
|
require_once 'MDB2/Driver/Function/Common.php';
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
// | Lorenzo Alberton <l.alberton@quipo.it> |
|
// | Lorenzo Alberton <l.alberton@quipo.it> |
|
||||||
// +----------------------------------------------------------------------+
|
// +----------------------------------------------------------------------+
|
||||||
//
|
//
|
||||||
// $Id: Common.php 295587 2010-02-28 17:16:38Z quipo $
|
// $Id$
|
||||||
//
|
//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -385,7 +385,11 @@ class MDB2_Driver_Manager_Common extends MDB2_Module_Common
|
||||||
}
|
}
|
||||||
|
|
||||||
$name = $db->quoteIdentifier($name, true);
|
$name = $db->quoteIdentifier($name, true);
|
||||||
return $db->exec("DROP TABLE $name");
|
$result = $db->exec("DROP TABLE $name");
|
||||||
|
if (MDB2::isError($result)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
@ -407,7 +411,11 @@ class MDB2_Driver_Manager_Common extends MDB2_Module_Common
|
||||||
}
|
}
|
||||||
|
|
||||||
$name = $db->quoteIdentifier($name, true);
|
$name = $db->quoteIdentifier($name, true);
|
||||||
return $db->exec("DELETE FROM $name");
|
$result = $db->exec("DELETE FROM $name");
|
||||||
|
if (MDB2::isError($result)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
@ -761,7 +769,11 @@ class MDB2_Driver_Manager_Common extends MDB2_Module_Common
|
||||||
$fields[] = $db->quoteIdentifier($field, true);
|
$fields[] = $db->quoteIdentifier($field, true);
|
||||||
}
|
}
|
||||||
$query .= ' ('. implode(', ', $fields) . ')';
|
$query .= ' ('. implode(', ', $fields) . ')';
|
||||||
return $db->exec($query);
|
$result = $db->exec($query);
|
||||||
|
if (MDB2::isError($result)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
@ -783,7 +795,11 @@ class MDB2_Driver_Manager_Common extends MDB2_Module_Common
|
||||||
}
|
}
|
||||||
|
|
||||||
$name = $db->quoteIdentifier($db->getIndexName($name), true);
|
$name = $db->quoteIdentifier($db->getIndexName($name), true);
|
||||||
return $db->exec("DROP INDEX $name");
|
$result = $db->exec("DROP INDEX $name");
|
||||||
|
if (MDB2::isError($result)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
@ -895,7 +911,11 @@ class MDB2_Driver_Manager_Common extends MDB2_Module_Common
|
||||||
$query .= ' ('. implode(', ', $referenced_fields) . ')';
|
$query .= ' ('. implode(', ', $referenced_fields) . ')';
|
||||||
$query .= $this->_getAdvancedFKOptions($definition);
|
$query .= $this->_getAdvancedFKOptions($definition);
|
||||||
}
|
}
|
||||||
return $db->exec($query);
|
$result = $db->exec($query);
|
||||||
|
if (MDB2::isError($result)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
@ -919,7 +939,11 @@ class MDB2_Driver_Manager_Common extends MDB2_Module_Common
|
||||||
|
|
||||||
$table = $db->quoteIdentifier($table, true);
|
$table = $db->quoteIdentifier($table, true);
|
||||||
$name = $db->quoteIdentifier($db->getIndexName($name), true);
|
$name = $db->quoteIdentifier($db->getIndexName($name), true);
|
||||||
return $db->exec("ALTER TABLE $table DROP CONSTRAINT $name");
|
$result = $db->exec("ALTER TABLE $table DROP CONSTRAINT $name");
|
||||||
|
if (MDB2::isError($result)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
||||||
// +----------------------------------------------------------------------+
|
// +----------------------------------------------------------------------+
|
||||||
//
|
//
|
||||||
// $Id: mysql.php 302865 2010-08-29 10:30:55Z quipo $
|
// $Id$
|
||||||
//
|
//
|
||||||
|
|
||||||
require_once 'MDB2/Driver/Manager/Common.php';
|
require_once 'MDB2/Driver/Manager/Common.php';
|
||||||
|
@ -327,7 +327,11 @@ class MDB2_Driver_Manager_mysql extends MDB2_Driver_Manager_Common
|
||||||
}
|
}
|
||||||
|
|
||||||
$name = $db->quoteIdentifier($name, true);
|
$name = $db->quoteIdentifier($name, true);
|
||||||
return $db->exec("TRUNCATE TABLE $name");
|
$result = $db->exec("TRUNCATE TABLE $name");
|
||||||
|
if (MDB2::isError($result)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
@ -374,7 +378,10 @@ class MDB2_Driver_Manager_mysql extends MDB2_Driver_Manager_Common
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
if (!empty($options['analyze'])) {
|
if (!empty($options['analyze'])) {
|
||||||
return $db->exec('ANALYZE TABLE '.$table);
|
$result = $db->exec('ANALYZE TABLE '.$table);
|
||||||
|
if (MDB2::isError($result)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return MDB2_OK;
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
|
@ -561,7 +568,11 @@ class MDB2_Driver_Manager_mysql extends MDB2_Driver_Manager_Common
|
||||||
}
|
}
|
||||||
|
|
||||||
$name = $db->quoteIdentifier($name, true);
|
$name = $db->quoteIdentifier($name, true);
|
||||||
return $db->exec("ALTER TABLE $name $query");
|
$result = $db->exec("ALTER TABLE $name $query");
|
||||||
|
if (MDB2::isError($result)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
@ -832,7 +843,11 @@ class MDB2_Driver_Manager_mysql extends MDB2_Driver_Manager_Common
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$query .= ' ('. implode(', ', $fields) . ')';
|
$query .= ' ('. implode(', ', $fields) . ')';
|
||||||
return $db->exec($query);
|
$result = $db->exec($query);
|
||||||
|
if (MDB2::isError($result)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
@ -855,7 +870,11 @@ class MDB2_Driver_Manager_mysql extends MDB2_Driver_Manager_Common
|
||||||
|
|
||||||
$table = $db->quoteIdentifier($table, true);
|
$table = $db->quoteIdentifier($table, true);
|
||||||
$name = $db->quoteIdentifier($db->getIndexName($name), true);
|
$name = $db->quoteIdentifier($db->getIndexName($name), true);
|
||||||
return $db->exec("DROP INDEX $name ON $table");
|
$result = $db->exec("DROP INDEX $name ON $table");
|
||||||
|
if (MDB2::isError($result)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
@ -1015,7 +1034,11 @@ class MDB2_Driver_Manager_mysql extends MDB2_Driver_Manager_Common
|
||||||
|
|
||||||
if ($primary || strtolower($name) == 'primary') {
|
if ($primary || strtolower($name) == 'primary') {
|
||||||
$query = 'ALTER TABLE '. $db->quoteIdentifier($table, true) .' DROP PRIMARY KEY';
|
$query = 'ALTER TABLE '. $db->quoteIdentifier($table, true) .' DROP PRIMARY KEY';
|
||||||
return $db->exec($query);
|
$result = $db->exec($query);
|
||||||
|
if (MDB2::isError($result)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
//is it a FK constraint? If so, also delete the associated triggers
|
//is it a FK constraint? If so, also delete the associated triggers
|
||||||
|
@ -1031,13 +1054,21 @@ class MDB2_Driver_Manager_mysql extends MDB2_Driver_Manager_Common
|
||||||
$table = $db->quoteIdentifier($table, true);
|
$table = $db->quoteIdentifier($table, true);
|
||||||
$name = $db->quoteIdentifier($db->getIndexName($name), true);
|
$name = $db->quoteIdentifier($db->getIndexName($name), true);
|
||||||
$query = "ALTER TABLE $table DROP FOREIGN KEY $name";
|
$query = "ALTER TABLE $table DROP FOREIGN KEY $name";
|
||||||
return $db->exec($query);
|
$result = $db->exec($query);
|
||||||
|
if (MDB2::isError($result)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
$table = $db->quoteIdentifier($table, true);
|
$table = $db->quoteIdentifier($table, true);
|
||||||
$name = $db->quoteIdentifier($db->getIndexName($name), true);
|
$name = $db->quoteIdentifier($db->getIndexName($name), true);
|
||||||
$query = "ALTER TABLE $table DROP INDEX $name";
|
$query = "ALTER TABLE $table DROP INDEX $name";
|
||||||
return $db->exec($query);
|
$result = $db->exec($query);
|
||||||
|
if (MDB2::isError($result)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
@ -1390,7 +1421,11 @@ class MDB2_Driver_Manager_mysql extends MDB2_Driver_Manager_Common
|
||||||
}
|
}
|
||||||
|
|
||||||
$sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true);
|
$sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true);
|
||||||
return $db->exec("DROP TABLE $sequence_name");
|
$result = $db->exec("DROP TABLE $sequence_name");
|
||||||
|
if (MDB2::isError($result)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
// | Author: Paul Cooper <pgc@ucecom.com> |
|
// | Author: Paul Cooper <pgc@ucecom.com> |
|
||||||
// +----------------------------------------------------------------------+
|
// +----------------------------------------------------------------------+
|
||||||
//
|
//
|
||||||
// $Id: pgsql.php 299393 2010-05-14 17:49:49Z afz $
|
// $Id$
|
||||||
|
|
||||||
require_once 'MDB2/Driver/Manager/Common.php';
|
require_once 'MDB2/Driver/Manager/Common.php';
|
||||||
|
|
||||||
|
@ -193,7 +193,11 @@ class MDB2_Driver_Manager_pgsql extends MDB2_Driver_Manager_Common
|
||||||
}
|
}
|
||||||
|
|
||||||
$name = $db->quoteIdentifier($name, true);
|
$name = $db->quoteIdentifier($name, true);
|
||||||
return $db->exec("TRUNCATE TABLE $name");
|
$result = $db->exec("TRUNCATE TABLE $name");
|
||||||
|
if (MDB2::isError($result)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
@ -234,7 +238,11 @@ class MDB2_Driver_Manager_pgsql extends MDB2_Driver_Manager_Common
|
||||||
if (!empty($table)) {
|
if (!empty($table)) {
|
||||||
$query .= ' '.$db->quoteIdentifier($table, true);
|
$query .= ' '.$db->quoteIdentifier($table, true);
|
||||||
}
|
}
|
||||||
return $db->exec($query);
|
$result = $db->exec($query);
|
||||||
|
if (MDB2::isError($result)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
@ -505,7 +513,7 @@ class MDB2_Driver_Manager_pgsql extends MDB2_Driver_Manager_Common
|
||||||
* @return mixed array of view names on success, a MDB2 error on failure
|
* @return mixed array of view names on success, a MDB2 error on failure
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
function listViews()
|
function listViews($database = null)
|
||||||
{
|
{
|
||||||
$db = $this->getDBInstance();
|
$db = $this->getDBInstance();
|
||||||
if (PEAR::isError($db)) {
|
if (PEAR::isError($db)) {
|
||||||
|
@ -637,7 +645,7 @@ class MDB2_Driver_Manager_pgsql extends MDB2_Driver_Manager_Common
|
||||||
* @return mixed array of table names on success, a MDB2 error on failure
|
* @return mixed array of table names on success, a MDB2 error on failure
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
function listTables()
|
function listTables($database = null)
|
||||||
{
|
{
|
||||||
$db = $this->getDBInstance();
|
$db = $this->getDBInstance();
|
||||||
if (PEAR::isError($db)) {
|
if (PEAR::isError($db)) {
|
||||||
|
@ -801,11 +809,19 @@ class MDB2_Driver_Manager_pgsql extends MDB2_Driver_Manager_Common
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array($name, $unique)) {
|
if (in_array($name, $unique)) {
|
||||||
return $db->exec('DROP INDEX '.$db->quoteIdentifier($name, true));
|
$result = $db->exec('DROP INDEX '.$db->quoteIdentifier($name, true));
|
||||||
|
if (MDB2::isError($result)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
$idxname = $db->getIndexName($name);
|
$idxname = $db->getIndexName($name);
|
||||||
if (in_array($idxname, $unique)) {
|
if (in_array($idxname, $unique)) {
|
||||||
return $db->exec('DROP INDEX '.$db->quoteIdentifier($idxname, true));
|
$result = $db->exec('DROP INDEX '.$db->quoteIdentifier($idxname, true));
|
||||||
|
if (MDB2::isError($result)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
|
return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
|
||||||
$name . ' is not an existing constraint for table ' . $table, __FUNCTION__);
|
$name . ' is not an existing constraint for table ' . $table, __FUNCTION__);
|
||||||
|
@ -894,8 +910,12 @@ class MDB2_Driver_Manager_pgsql extends MDB2_Driver_Manager_Common
|
||||||
}
|
}
|
||||||
|
|
||||||
$sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true);
|
$sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true);
|
||||||
return $db->exec("CREATE SEQUENCE $sequence_name INCREMENT 1".
|
$result = $db->exec("CREATE SEQUENCE $sequence_name INCREMENT 1".
|
||||||
($start < 1 ? " MINVALUE $start" : '')." START $start");
|
($start < 1 ? " MINVALUE $start" : '')." START $start");
|
||||||
|
if (MDB2::isError($result)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
@ -916,7 +936,11 @@ class MDB2_Driver_Manager_pgsql extends MDB2_Driver_Manager_Common
|
||||||
}
|
}
|
||||||
|
|
||||||
$sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true);
|
$sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true);
|
||||||
return $db->exec("DROP SEQUENCE $sequence_name");
|
$result = $db->exec("DROP SEQUENCE $sequence_name");
|
||||||
|
if (MDB2::isError($result)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
@ -928,7 +952,7 @@ class MDB2_Driver_Manager_pgsql extends MDB2_Driver_Manager_Common
|
||||||
* @return mixed array of sequence names on success, a MDB2 error on failure
|
* @return mixed array of sequence names on success, a MDB2 error on failure
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
function listSequences()
|
function listSequences($database = null)
|
||||||
{
|
{
|
||||||
$db = $this->getDBInstance();
|
$db = $this->getDBInstance();
|
||||||
if (PEAR::isError($db)) {
|
if (PEAR::isError($db)) {
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
// | Lorenzo Alberton <l.alberton@quipo.it> |
|
// | Lorenzo Alberton <l.alberton@quipo.it> |
|
||||||
// +----------------------------------------------------------------------+
|
// +----------------------------------------------------------------------+
|
||||||
//
|
//
|
||||||
// $Id: sqlite.php 295587 2010-02-28 17:16:38Z quipo $
|
// $Id$
|
||||||
//
|
//
|
||||||
|
|
||||||
require_once 'MDB2/Driver/Manager/Common.php';
|
require_once 'MDB2/Driver/Manager/Common.php';
|
||||||
|
@ -405,7 +405,11 @@ class MDB2_Driver_Manager_sqlite extends MDB2_Driver_Manager_Common
|
||||||
}
|
}
|
||||||
|
|
||||||
$name = $db->quoteIdentifier($name, true);
|
$name = $db->quoteIdentifier($name, true);
|
||||||
return $db->exec("DROP TABLE $name");
|
$result = $db->exec("DROP TABLE $name");
|
||||||
|
if (MDB2::isError($result)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
@ -436,7 +440,11 @@ class MDB2_Driver_Manager_sqlite extends MDB2_Driver_Manager_Common
|
||||||
if (!empty($table)) {
|
if (!empty($table)) {
|
||||||
$query .= ' '.$db->quoteIdentifier($table, true);
|
$query .= ' '.$db->quoteIdentifier($table, true);
|
||||||
}
|
}
|
||||||
return $db->exec($query);
|
$result = $db->exec($query);
|
||||||
|
if (MDB2::isError($result)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
@ -964,11 +972,11 @@ class MDB2_Driver_Manager_sqlite extends MDB2_Driver_Manager_Common
|
||||||
}
|
}
|
||||||
|
|
||||||
$table = $db->quoteIdentifier($table, true);
|
$table = $db->quoteIdentifier($table, true);
|
||||||
$name = $db->getIndexName($name);
|
$name = $db->quoteIdentifier($db->getIndexName($name), true);
|
||||||
$query = "CREATE INDEX $name ON $table";
|
$query = "CREATE INDEX $name ON $table";
|
||||||
$fields = array();
|
$fields = array();
|
||||||
foreach ($definition['fields'] as $field_name => $field) {
|
foreach ($definition['fields'] as $field_name => $field) {
|
||||||
$field_string = $field_name;
|
$field_string = $db->quoteIdentifier($field_name, true);
|
||||||
if (!empty($field['sorting'])) {
|
if (!empty($field['sorting'])) {
|
||||||
switch ($field['sorting']) {
|
switch ($field['sorting']) {
|
||||||
case 'ascending':
|
case 'ascending':
|
||||||
|
@ -982,7 +990,11 @@ class MDB2_Driver_Manager_sqlite extends MDB2_Driver_Manager_Common
|
||||||
$fields[] = $field_string;
|
$fields[] = $field_string;
|
||||||
}
|
}
|
||||||
$query .= ' ('.implode(', ', $fields) . ')';
|
$query .= ' ('.implode(', ', $fields) . ')';
|
||||||
return $db->exec($query);
|
$result = $db->exec($query);
|
||||||
|
if (MDB2::isError($result)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
@ -1004,7 +1016,11 @@ class MDB2_Driver_Manager_sqlite extends MDB2_Driver_Manager_Common
|
||||||
}
|
}
|
||||||
|
|
||||||
$name = $db->getIndexName($name);
|
$name = $db->getIndexName($name);
|
||||||
return $db->exec("DROP INDEX $name");
|
$result = $db->exec("DROP INDEX $name");
|
||||||
|
if (MDB2::isError($result)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
@ -1112,7 +1128,11 @@ class MDB2_Driver_Manager_sqlite extends MDB2_Driver_Manager_Common
|
||||||
$fields[] = $field_string;
|
$fields[] = $field_string;
|
||||||
}
|
}
|
||||||
$query .= ' ('.implode(', ', $fields) . ')';
|
$query .= ' ('.implode(', ', $fields) . ')';
|
||||||
return $db->exec($query);
|
$result = $db->exec($query);
|
||||||
|
if (MDB2::isError($result)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
@ -1152,7 +1172,11 @@ class MDB2_Driver_Manager_sqlite extends MDB2_Driver_Manager_Common
|
||||||
}
|
}
|
||||||
|
|
||||||
$name = $db->getIndexName($name);
|
$name = $db->getIndexName($name);
|
||||||
return $db->exec("DROP INDEX $name");
|
$result = $db->exec("DROP INDEX $name");
|
||||||
|
if (MDB2::isError($result)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
@ -1321,7 +1345,11 @@ class MDB2_Driver_Manager_sqlite extends MDB2_Driver_Manager_Common
|
||||||
}
|
}
|
||||||
|
|
||||||
$sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true);
|
$sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true);
|
||||||
return $db->exec("DROP TABLE $sequence_name");
|
$result = $db->exec("DROP TABLE $sequence_name");
|
||||||
|
if (MDB2::isError($result)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
||||||
// +----------------------------------------------------------------------+
|
// +----------------------------------------------------------------------+
|
||||||
//
|
//
|
||||||
// $Id: Common.php 242348 2007-09-09 13:47:36Z quipo $
|
// $Id$
|
||||||
//
|
//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
||||||
// +----------------------------------------------------------------------+
|
// +----------------------------------------------------------------------+
|
||||||
//
|
//
|
||||||
// $Id: mysql.php 215004 2006-06-18 21:59:05Z lsmith $
|
// $Id$
|
||||||
//
|
//
|
||||||
|
|
||||||
require_once 'MDB2/Driver/Native/Common.php';
|
require_once 'MDB2/Driver/Native/Common.php';
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
// | Author: Paul Cooper <pgc@ucecom.com> |
|
// | Author: Paul Cooper <pgc@ucecom.com> |
|
||||||
// +----------------------------------------------------------------------+
|
// +----------------------------------------------------------------------+
|
||||||
//
|
//
|
||||||
// $Id: pgsql.php 295587 2010-02-28 17:16:38Z quipo $
|
// $Id$
|
||||||
|
|
||||||
require_once 'MDB2/Driver/Native/Common.php';
|
require_once 'MDB2/Driver/Native/Common.php';
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
||||||
// +----------------------------------------------------------------------+
|
// +----------------------------------------------------------------------+
|
||||||
//
|
//
|
||||||
// $Id: sqlite.php 215004 2006-06-18 21:59:05Z lsmith $
|
// $Id$
|
||||||
//
|
//
|
||||||
|
|
||||||
require_once 'MDB2/Driver/Native/Common.php';
|
require_once 'MDB2/Driver/Native/Common.php';
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
||||||
// +----------------------------------------------------------------------+
|
// +----------------------------------------------------------------------+
|
||||||
//
|
//
|
||||||
// $Id: Common.php 295587 2010-02-28 17:16:38Z quipo $
|
// $Id$
|
||||||
//
|
//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
||||||
// +----------------------------------------------------------------------+
|
// +----------------------------------------------------------------------+
|
||||||
//
|
//
|
||||||
// $Id: mysql.php 295587 2010-02-28 17:16:38Z quipo $
|
// $Id$
|
||||||
//
|
//
|
||||||
|
|
||||||
require_once 'MDB2/Driver/Reverse/Common.php';
|
require_once 'MDB2/Driver/Reverse/Common.php';
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
// | Lorenzo Alberton <l.alberton@quipo.it> |
|
// | Lorenzo Alberton <l.alberton@quipo.it> |
|
||||||
// +----------------------------------------------------------------------+
|
// +----------------------------------------------------------------------+
|
||||||
//
|
//
|
||||||
// $Id: pgsql.php 295587 2010-02-28 17:16:38Z quipo $
|
// $Id$
|
||||||
|
|
||||||
require_once 'MDB2/Driver/Reverse/Common.php';
|
require_once 'MDB2/Driver/Reverse/Common.php';
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
// | Lorenzo Alberton <l.alberton@quipo.it> |
|
// | Lorenzo Alberton <l.alberton@quipo.it> |
|
||||||
// +----------------------------------------------------------------------+
|
// +----------------------------------------------------------------------+
|
||||||
//
|
//
|
||||||
// $Id: sqlite.php 295587 2010-02-28 17:16:38Z quipo $
|
// $Id$
|
||||||
//
|
//
|
||||||
|
|
||||||
require_once 'MDB2/Driver/Reverse/Common.php';
|
require_once 'MDB2/Driver/Reverse/Common.php';
|
||||||
|
@ -95,7 +95,7 @@ class MDB2_Driver_Reverse_sqlite extends MDB2_Driver_Reverse_Common
|
||||||
return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
|
return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
|
||||||
'unexpected empty table column definition list', __FUNCTION__);
|
'unexpected empty table column definition list', __FUNCTION__);
|
||||||
}
|
}
|
||||||
$regexp = '/^\s*([^\s]+) +(CHAR|VARCHAR|VARCHAR2|TEXT|BOOLEAN|SMALLINT|INT|INTEGER|DECIMAL|BIGINT|DOUBLE|FLOAT|DATETIME|DATE|TIME|LONGTEXT|LONGBLOB)( ?\(([1-9][0-9]*)(:([1-9][0-9]*))?\))?( NULL| NOT NULL)?( UNSIGNED)?( NULL| NOT NULL)?( PRIMARY KEY)?( DEFAULT (\'[^\']*\'|[^ ]+))?( NULL| NOT NULL)?( PRIMARY KEY)?(\s*\-\-.*)?$/i';
|
$regexp = '/^\s*([^\s]+) +(CHAR|VARCHAR|VARCHAR2|TEXT|BOOLEAN|SMALLINT|INT|INTEGER|DECIMAL|TINYINT|BIGINT|DOUBLE|FLOAT|DATETIME|DATE|TIME|LONGTEXT|LONGBLOB)( ?\(([1-9][0-9]*)(:([1-9][0-9]*))?\))?( NULL| NOT NULL)?( UNSIGNED)?( NULL| NOT NULL)?( PRIMARY KEY)?( DEFAULT (\'[^\']*\'|[^ ]+))?( NULL| NOT NULL)?( PRIMARY KEY)?(\s*\-\-.*)?$/i';
|
||||||
$regexp2 = '/^\s*([^ ]+) +(PRIMARY|UNIQUE|CHECK)$/i';
|
$regexp2 = '/^\s*([^ ]+) +(PRIMARY|UNIQUE|CHECK)$/i';
|
||||||
for ($i=0, $j=0; $i<$count; ++$i) {
|
for ($i=0, $j=0; $i<$count; ++$i) {
|
||||||
if (!preg_match($regexp, trim($column_sql[$i]), $matches)) {
|
if (!preg_match($regexp, trim($column_sql[$i]), $matches)) {
|
||||||
|
@ -128,6 +128,8 @@ class MDB2_Driver_Reverse_sqlite extends MDB2_Driver_Reverse_Common
|
||||||
$default = null;
|
$default = null;
|
||||||
}
|
}
|
||||||
$columns[$j]['default'] = $default;
|
$columns[$j]['default'] = $default;
|
||||||
|
} else {
|
||||||
|
$columns[$j]['default'] = null;
|
||||||
}
|
}
|
||||||
if (isset($matches[7]) && strlen($matches[7])) {
|
if (isset($matches[7]) && strlen($matches[7])) {
|
||||||
$columns[$j]['notnull'] = ($matches[7] === ' NOT NULL');
|
$columns[$j]['notnull'] = ($matches[7] === ' NOT NULL');
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
||||||
// +----------------------------------------------------------------------+
|
// +----------------------------------------------------------------------+
|
||||||
//
|
//
|
||||||
// $Id: mysql.php 302867 2010-08-29 11:22:07Z quipo $
|
// $Id$
|
||||||
//
|
//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,21 +57,30 @@ class MDB2_Driver_mysql extends MDB2_Driver_Common
|
||||||
{
|
{
|
||||||
// {{{ properties
|
// {{{ properties
|
||||||
|
|
||||||
var $string_quoting = array('start' => "'", 'end' => "'", 'escape' => '\\', 'escape_pattern' => '\\');
|
public $string_quoting = array(
|
||||||
|
'start' => "'",
|
||||||
|
'end' => "'",
|
||||||
|
'escape' => '\\',
|
||||||
|
'escape_pattern' => '\\',
|
||||||
|
);
|
||||||
|
|
||||||
var $identifier_quoting = array('start' => '`', 'end' => '`', 'escape' => '`');
|
public $identifier_quoting = array(
|
||||||
|
'start' => '`',
|
||||||
|
'end' => '`',
|
||||||
|
'escape' => '`',
|
||||||
|
);
|
||||||
|
|
||||||
var $sql_comments = array(
|
public $sql_comments = array(
|
||||||
array('start' => '-- ', 'end' => "\n", 'escape' => false),
|
array('start' => '-- ', 'end' => "\n", 'escape' => false),
|
||||||
array('start' => '#', 'end' => "\n", 'escape' => false),
|
array('start' => '#', 'end' => "\n", 'escape' => false),
|
||||||
array('start' => '/*', 'end' => '*/', 'escape' => false),
|
array('start' => '/*', 'end' => '*/', 'escape' => false),
|
||||||
);
|
);
|
||||||
|
|
||||||
var $server_capabilities_checked = false;
|
protected $server_capabilities_checked = false;
|
||||||
|
|
||||||
var $start_transaction = false;
|
protected $start_transaction = false;
|
||||||
|
|
||||||
var $varchar_max_length = 255;
|
protected $varchar_max_length = 255;
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ constructor
|
// {{{ constructor
|
||||||
|
@ -1370,7 +1379,9 @@ class MDB2_Result_mysql extends MDB2_Result_Common
|
||||||
if ($fetchmode == MDB2_FETCHMODE_DEFAULT) {
|
if ($fetchmode == MDB2_FETCHMODE_DEFAULT) {
|
||||||
$fetchmode = $this->db->fetchmode;
|
$fetchmode = $this->db->fetchmode;
|
||||||
}
|
}
|
||||||
if ($fetchmode & MDB2_FETCHMODE_ASSOC) {
|
if ( $fetchmode == MDB2_FETCHMODE_ASSOC
|
||||||
|
|| $fetchmode == MDB2_FETCHMODE_OBJECT
|
||||||
|
) {
|
||||||
$row = @mysql_fetch_assoc($this->result);
|
$row = @mysql_fetch_assoc($this->result);
|
||||||
if (is_array($row)
|
if (is_array($row)
|
||||||
&& $this->db->options['portability'] & MDB2_PORTABILITY_FIX_CASE
|
&& $this->db->options['portability'] & MDB2_PORTABILITY_FIX_CASE
|
||||||
|
@ -1401,8 +1412,16 @@ class MDB2_Result_mysql extends MDB2_Result_Common
|
||||||
if ($mode) {
|
if ($mode) {
|
||||||
$this->db->_fixResultArrayValues($row, $mode);
|
$this->db->_fixResultArrayValues($row, $mode);
|
||||||
}
|
}
|
||||||
if (!empty($this->types)) {
|
if ( ( $fetchmode != MDB2_FETCHMODE_ASSOC
|
||||||
|
&& $fetchmode != MDB2_FETCHMODE_OBJECT)
|
||||||
|
&& !empty($this->types)
|
||||||
|
) {
|
||||||
$row = $this->db->datatype->convertResultRow($this->types, $row, $rtrim);
|
$row = $this->db->datatype->convertResultRow($this->types, $row, $rtrim);
|
||||||
|
} elseif (($fetchmode == MDB2_FETCHMODE_ASSOC
|
||||||
|
|| $fetchmode == MDB2_FETCHMODE_OBJECT)
|
||||||
|
&& !empty($this->types_assoc)
|
||||||
|
) {
|
||||||
|
$row = $this->db->datatype->convertResultRow($this->types_assoc, $row, $rtrim);
|
||||||
}
|
}
|
||||||
if (!empty($this->values)) {
|
if (!empty($this->values)) {
|
||||||
$this->_assignBindColumns($row);
|
$this->_assignBindColumns($row);
|
||||||
|
@ -1600,7 +1619,7 @@ class MDB2_Statement_mysql extends MDB2_Statement_Common
|
||||||
* a MDB2 error on failure
|
* a MDB2 error on failure
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function _execute($result_class = true, $result_wrap_class = false)
|
function _execute($result_class = true, $result_wrap_class = true)
|
||||||
{
|
{
|
||||||
if (is_null($this->statement)) {
|
if (is_null($this->statement)) {
|
||||||
$result = parent::_execute($result_class, $result_wrap_class);
|
$result = parent::_execute($result_class, $result_wrap_class);
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
// | Author: Paul Cooper <pgc@ucecom.com> |
|
// | Author: Paul Cooper <pgc@ucecom.com> |
|
||||||
// +----------------------------------------------------------------------+
|
// +----------------------------------------------------------------------+
|
||||||
//
|
//
|
||||||
// $Id: pgsql.php 295587 2010-02-28 17:16:38Z quipo $
|
// $Id$
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MDB2 PostGreSQL driver
|
* MDB2 PostGreSQL driver
|
||||||
|
@ -652,7 +652,7 @@ class MDB2_Driver_pgsql extends MDB2_Driver_Common
|
||||||
if ($is_manip) {
|
if ($is_manip) {
|
||||||
$result = $this->_affectedRows($connection, $result);
|
$result = $this->_affectedRows($connection, $result);
|
||||||
} else {
|
} else {
|
||||||
$result =& $this->_wrapResult($result, $types, true, false, $limit, $offset);
|
$result = $this->_wrapResult($result, $types, true, true, $limit, $offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -959,17 +959,18 @@ class MDB2_Driver_pgsql extends MDB2_Driver_Common
|
||||||
$pgtypes[] = 'text';
|
$pgtypes[] = 'text';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (($key_parameter = array_search($name, $positions))) {
|
if (($key_parameter = array_search($name, $positions)) !== false) {
|
||||||
$next_parameter = 1;
|
//$next_parameter = 1;
|
||||||
foreach ($positions as $key => $value) {
|
$parameter = $key_parameter + 1;
|
||||||
if ($key_parameter == $key) {
|
//foreach ($positions as $key => $value) {
|
||||||
break;
|
// if ($key_parameter == $key) {
|
||||||
}
|
// break;
|
||||||
++$next_parameter;
|
// }
|
||||||
}
|
// ++$next_parameter;
|
||||||
|
//}
|
||||||
} else {
|
} else {
|
||||||
++$parameter;
|
++$parameter;
|
||||||
$next_parameter = $parameter;
|
//$next_parameter = $parameter;
|
||||||
$positions[] = $name;
|
$positions[] = $name;
|
||||||
}
|
}
|
||||||
$query = substr_replace($query, '$'.$parameter, $position, $length);
|
$query = substr_replace($query, '$'.$parameter, $position, $length);
|
||||||
|
@ -1178,7 +1179,9 @@ class MDB2_Result_pgsql extends MDB2_Result_Common
|
||||||
if ($fetchmode == MDB2_FETCHMODE_DEFAULT) {
|
if ($fetchmode == MDB2_FETCHMODE_DEFAULT) {
|
||||||
$fetchmode = $this->db->fetchmode;
|
$fetchmode = $this->db->fetchmode;
|
||||||
}
|
}
|
||||||
if ($fetchmode & MDB2_FETCHMODE_ASSOC) {
|
if ( $fetchmode == MDB2_FETCHMODE_ASSOC
|
||||||
|
|| $fetchmode == MDB2_FETCHMODE_OBJECT
|
||||||
|
) {
|
||||||
$row = @pg_fetch_array($this->result, null, PGSQL_ASSOC);
|
$row = @pg_fetch_array($this->result, null, PGSQL_ASSOC);
|
||||||
if (is_array($row)
|
if (is_array($row)
|
||||||
&& $this->db->options['portability'] & MDB2_PORTABILITY_FIX_CASE
|
&& $this->db->options['portability'] & MDB2_PORTABILITY_FIX_CASE
|
||||||
|
@ -1208,8 +1211,16 @@ class MDB2_Result_pgsql extends MDB2_Result_Common
|
||||||
if ($mode) {
|
if ($mode) {
|
||||||
$this->db->_fixResultArrayValues($row, $mode);
|
$this->db->_fixResultArrayValues($row, $mode);
|
||||||
}
|
}
|
||||||
if (!empty($this->types)) {
|
if ( ( $fetchmode != MDB2_FETCHMODE_ASSOC
|
||||||
|
&& $fetchmode != MDB2_FETCHMODE_OBJECT)
|
||||||
|
&& !empty($this->types)
|
||||||
|
) {
|
||||||
$row = $this->db->datatype->convertResultRow($this->types, $row, $rtrim);
|
$row = $this->db->datatype->convertResultRow($this->types, $row, $rtrim);
|
||||||
|
} elseif (($fetchmode == MDB2_FETCHMODE_ASSOC
|
||||||
|
|| $fetchmode == MDB2_FETCHMODE_OBJECT)
|
||||||
|
&& !empty($this->types_assoc)
|
||||||
|
) {
|
||||||
|
$row = $this->db->datatype->convertResultRow($this->types_assoc, $row, $rtrim);
|
||||||
}
|
}
|
||||||
if (!empty($this->values)) {
|
if (!empty($this->values)) {
|
||||||
$this->_assignBindColumns($row);
|
$this->_assignBindColumns($row);
|
||||||
|
@ -1429,7 +1440,7 @@ class MDB2_Statement_pgsql extends MDB2_Statement_Common
|
||||||
* a MDB2 error on failure
|
* a MDB2 error on failure
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function _execute($result_class = true, $result_wrap_class = false)
|
function _execute($result_class = true, $result_wrap_class = true)
|
||||||
{
|
{
|
||||||
if (null === $this->statement) {
|
if (null === $this->statement) {
|
||||||
return parent::_execute($result_class, $result_wrap_class);
|
return parent::_execute($result_class, $result_wrap_class);
|
||||||
|
@ -1544,5 +1555,29 @@ class MDB2_Statement_pgsql extends MDB2_Statement_Common
|
||||||
parent::free();
|
parent::free();
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* drop an existing table
|
||||||
|
*
|
||||||
|
* @param string $name name of the table that should be dropped
|
||||||
|
* @return mixed MDB2_OK on success, a MDB2 error on failure
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function dropTable($name)
|
||||||
|
{
|
||||||
|
$db = $this->getDBInstance();
|
||||||
|
if (PEAR::isError($db)) {
|
||||||
|
return $db;
|
||||||
|
}
|
||||||
|
|
||||||
|
$name = $db->quoteIdentifier($name, true);
|
||||||
|
$result = $db->exec("DROP TABLE $name");
|
||||||
|
|
||||||
|
if (PEAR::isError($result)) {
|
||||||
|
$result = $db->exec("DROP TABLE $name CASCADE");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
|
@ -43,7 +43,7 @@
|
||||||
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
||||||
// +----------------------------------------------------------------------+
|
// +----------------------------------------------------------------------+
|
||||||
//
|
//
|
||||||
// $Id: sqlite.php 295587 2010-02-28 17:16:38Z quipo $
|
// $Id$
|
||||||
//
|
//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -142,6 +142,7 @@ class MDB2_Driver_sqlite extends MDB2_Driver_Common
|
||||||
'/is not unique/' => MDB2_ERROR_CONSTRAINT,
|
'/is not unique/' => MDB2_ERROR_CONSTRAINT,
|
||||||
'/columns .* are not unique/i' => MDB2_ERROR_CONSTRAINT,
|
'/columns .* are not unique/i' => MDB2_ERROR_CONSTRAINT,
|
||||||
'/uniqueness constraint failed/' => MDB2_ERROR_CONSTRAINT,
|
'/uniqueness constraint failed/' => MDB2_ERROR_CONSTRAINT,
|
||||||
|
'/violates .*constraint/' => MDB2_ERROR_CONSTRAINT,
|
||||||
'/may not be NULL/' => MDB2_ERROR_CONSTRAINT_NOT_NULL,
|
'/may not be NULL/' => MDB2_ERROR_CONSTRAINT_NOT_NULL,
|
||||||
'/^no such column:/' => MDB2_ERROR_NOSUCHFIELD,
|
'/^no such column:/' => MDB2_ERROR_NOSUCHFIELD,
|
||||||
'/no column named/' => MDB2_ERROR_NOSUCHFIELD,
|
'/no column named/' => MDB2_ERROR_NOSUCHFIELD,
|
||||||
|
@ -893,7 +894,9 @@ class MDB2_Result_sqlite extends MDB2_Result_Common
|
||||||
if ($fetchmode == MDB2_FETCHMODE_DEFAULT) {
|
if ($fetchmode == MDB2_FETCHMODE_DEFAULT) {
|
||||||
$fetchmode = $this->db->fetchmode;
|
$fetchmode = $this->db->fetchmode;
|
||||||
}
|
}
|
||||||
if ($fetchmode & MDB2_FETCHMODE_ASSOC) {
|
if ( $fetchmode == MDB2_FETCHMODE_ASSOC
|
||||||
|
|| $fetchmode == MDB2_FETCHMODE_OBJECT
|
||||||
|
) {
|
||||||
$row = @sqlite_fetch_array($this->result, SQLITE_ASSOC);
|
$row = @sqlite_fetch_array($this->result, SQLITE_ASSOC);
|
||||||
if (is_array($row)
|
if (is_array($row)
|
||||||
&& $this->db->options['portability'] & MDB2_PORTABILITY_FIX_CASE
|
&& $this->db->options['portability'] & MDB2_PORTABILITY_FIX_CASE
|
||||||
|
@ -923,8 +926,16 @@ class MDB2_Result_sqlite extends MDB2_Result_Common
|
||||||
if ($mode) {
|
if ($mode) {
|
||||||
$this->db->_fixResultArrayValues($row, $mode);
|
$this->db->_fixResultArrayValues($row, $mode);
|
||||||
}
|
}
|
||||||
if (!empty($this->types)) {
|
if ( ( $fetchmode != MDB2_FETCHMODE_ASSOC
|
||||||
|
&& $fetchmode != MDB2_FETCHMODE_OBJECT)
|
||||||
|
&& !empty($this->types)
|
||||||
|
) {
|
||||||
$row = $this->db->datatype->convertResultRow($this->types, $row, $rtrim);
|
$row = $this->db->datatype->convertResultRow($this->types, $row, $rtrim);
|
||||||
|
} elseif (($fetchmode == MDB2_FETCHMODE_ASSOC
|
||||||
|
|| $fetchmode == MDB2_FETCHMODE_OBJECT)
|
||||||
|
&& !empty($this->types_assoc)
|
||||||
|
) {
|
||||||
|
$row = $this->db->datatype->convertResultRow($this->types_assoc, $row, $rtrim);
|
||||||
}
|
}
|
||||||
if (!empty($this->values)) {
|
if (!empty($this->values)) {
|
||||||
$this->_assignBindColumns($row);
|
$this->_assignBindColumns($row);
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
||||||
// +----------------------------------------------------------------------+
|
// +----------------------------------------------------------------------+
|
||||||
//
|
//
|
||||||
// $Id: Extended.php 302784 2010-08-25 23:29:16Z quipo $
|
// $Id$
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @package MDB2
|
* @package MDB2
|
||||||
|
@ -645,6 +645,9 @@ class MDB2_Extended extends MDB2_Module_Common
|
||||||
*/
|
*/
|
||||||
function executeMultiple($stmt, $params = null)
|
function executeMultiple($stmt, $params = null)
|
||||||
{
|
{
|
||||||
|
if (MDB2::isError($stmt)) {
|
||||||
|
return $stmt;
|
||||||
|
}
|
||||||
for ($i = 0, $j = count($params); $i < $j; $i++) {
|
for ($i = 0, $j = count($params); $i < $j; $i++) {
|
||||||
$result = $stmt->execute($params[$i]);
|
$result = $stmt->execute($params[$i]);
|
||||||
if (PEAR::isError($result)) {
|
if (PEAR::isError($result)) {
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
||||||
// +----------------------------------------------------------------------+
|
// +----------------------------------------------------------------------+
|
||||||
//
|
//
|
||||||
// $Id: Iterator.php 295586 2010-02-28 17:04:17Z quipo $
|
// $Id$
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PHP5 Iterator
|
* PHP5 Iterator
|
||||||
|
@ -54,6 +54,9 @@
|
||||||
class MDB2_Iterator implements Iterator
|
class MDB2_Iterator implements Iterator
|
||||||
{
|
{
|
||||||
protected $fetchmode;
|
protected $fetchmode;
|
||||||
|
/**
|
||||||
|
* @var MDB2_Result_Common
|
||||||
|
*/
|
||||||
protected $result;
|
protected $result;
|
||||||
protected $row;
|
protected $row;
|
||||||
|
|
||||||
|
@ -62,7 +65,7 @@ class MDB2_Iterator implements Iterator
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
public function __construct($result, $fetchmode = MDB2_FETCHMODE_DEFAULT)
|
public function __construct(MDB2_Result_Common $result, $fetchmode = MDB2_FETCHMODE_DEFAULT)
|
||||||
{
|
{
|
||||||
$this->result = $result;
|
$this->result = $result;
|
||||||
$this->fetchmode = $fetchmode;
|
$this->fetchmode = $fetchmode;
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
// | Author: Lukas Smith <smith@pooteeweet.org> |
|
||||||
// +----------------------------------------------------------------------+
|
// +----------------------------------------------------------------------+
|
||||||
//
|
//
|
||||||
// $Id: LOB.php 222350 2006-10-25 11:52:21Z lsmith $
|
// $Id$
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @package MDB2
|
* @package MDB2
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
<?php
|
<?php /* vim: se et ts=4 sw=4 sts=4 fdm=marker tw=80: */
|
||||||
/**
|
/**
|
||||||
* PHP version 4, 5
|
* Copyright (c) 1998-2010 Manuel Lemos, Tomas V.V.Cox,
|
||||||
*
|
|
||||||
* Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox,
|
|
||||||
* Stig. S. Bakken, Lukas Smith, Igor Feghali
|
* Stig. S. Bakken, Lukas Smith, Igor Feghali
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
|
@ -39,15 +37,14 @@
|
||||||
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* Author: Lukas Smith <smith@pooteeweet.org>
|
* PHP version 5
|
||||||
* Author: Igor Feghali <ifeghali@php.net>
|
|
||||||
*
|
*
|
||||||
* @category Database
|
* @category Database
|
||||||
* @package MDB2_Schema
|
* @package MDB2_Schema
|
||||||
* @author Lukas Smith <smith@pooteeweet.org>
|
* @author Lukas Smith <smith@pooteeweet.org>
|
||||||
* @author Igor Feghali <ifeghali@php.net>
|
* @author Igor Feghali <ifeghali@php.net>
|
||||||
* @license BSD http://www.opensource.org/licenses/bsd-license.php
|
* @license BSD http://www.opensource.org/licenses/bsd-license.php
|
||||||
* @version CVS: $Id: Schema.php,v 1.132 2009/02/22 21:43:22 ifeghali Exp $
|
* @version SVN: $Id$
|
||||||
* @link http://pear.php.net/packages/MDB2_Schema
|
* @link http://pear.php.net/packages/MDB2_Schema
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -96,7 +93,7 @@ class MDB2_Schema extends PEAR
|
||||||
'parser' => 'MDB2_Schema_Parser',
|
'parser' => 'MDB2_Schema_Parser',
|
||||||
'writer' => 'MDB2_Schema_Writer',
|
'writer' => 'MDB2_Schema_Writer',
|
||||||
'validate' => 'MDB2_Schema_Validate',
|
'validate' => 'MDB2_Schema_Validate',
|
||||||
'drop_missing_tables' => false
|
'drop_obsolete_objects' => false
|
||||||
);
|
);
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
@ -237,9 +234,9 @@ class MDB2_Schema extends PEAR
|
||||||
* @access public
|
* @access public
|
||||||
* @see MDB2::parseDSN
|
* @see MDB2::parseDSN
|
||||||
*/
|
*/
|
||||||
function &factory(&$db, $options = array())
|
static function &factory(&$db, $options = array())
|
||||||
{
|
{
|
||||||
$obj =& new MDB2_Schema();
|
$obj = new MDB2_Schema();
|
||||||
|
|
||||||
$result = $obj->connect($db, $options);
|
$result = $obj->connect($db, $options);
|
||||||
if (PEAR::isError($result)) {
|
if (PEAR::isError($result)) {
|
||||||
|
@ -284,14 +281,14 @@ class MDB2_Schema extends PEAR
|
||||||
|
|
||||||
$this->disconnect();
|
$this->disconnect();
|
||||||
if (!MDB2::isConnection($db)) {
|
if (!MDB2::isConnection($db)) {
|
||||||
$db =& MDB2::factory($db, $db_options);
|
$db = MDB2::factory($db, $db_options);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PEAR::isError($db)) {
|
if (PEAR::isError($db)) {
|
||||||
return $db;
|
return $db;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->db =& $db;
|
$this->db = $db;
|
||||||
$this->db->loadModule('Datatype');
|
$this->db->loadModule('Datatype');
|
||||||
$this->db->loadModule('Manager');
|
$this->db->loadModule('Manager');
|
||||||
$this->db->loadModule('Reverse');
|
$this->db->loadModule('Reverse');
|
||||||
|
@ -380,7 +377,7 @@ class MDB2_Schema extends PEAR
|
||||||
$dtd_file = $this->options['dtd_file'];
|
$dtd_file = $this->options['dtd_file'];
|
||||||
if ($dtd_file) {
|
if ($dtd_file) {
|
||||||
include_once 'XML/DTD/XmlValidator.php';
|
include_once 'XML/DTD/XmlValidator.php';
|
||||||
$dtd =& new XML_DTD_XmlValidator;
|
$dtd = new XML_DTD_XmlValidator;
|
||||||
if (!$dtd->isValid($dtd_file, $input_file)) {
|
if (!$dtd->isValid($dtd_file, $input_file)) {
|
||||||
return $this->raiseError(MDB2_SCHEMA_ERROR_PARSE, null, null, $dtd->getMessage());
|
return $this->raiseError(MDB2_SCHEMA_ERROR_PARSE, null, null, $dtd->getMessage());
|
||||||
}
|
}
|
||||||
|
@ -393,7 +390,16 @@ class MDB2_Schema extends PEAR
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
$parser =& new $class_name($variables, $fail_on_invalid_names, $structure, $this->options['valid_types'], $this->options['force_defaults']);
|
$max_identifiers_length = null;
|
||||||
|
if (isset($this->db->options['max_identifiers_length'])) {
|
||||||
|
$max_identifiers_length = $this->db->options['max_identifiers_length'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$parser = new $class_name($variables, $fail_on_invalid_names, $structure,
|
||||||
|
$this->options['valid_types'], $this->options['force_defaults'],
|
||||||
|
$max_identifiers_length
|
||||||
|
);
|
||||||
|
|
||||||
$result = $parser->setInputFile($input_file);
|
$result = $parser->setInputFile($input_file);
|
||||||
if (PEAR::isError($result)) {
|
if (PEAR::isError($result)) {
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -436,7 +442,17 @@ class MDB2_Schema extends PEAR
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
$val =& new $class_name($this->options['fail_on_invalid_names'], $this->options['valid_types'], $this->options['force_defaults']);
|
$max_identifiers_length = null;
|
||||||
|
if (isset($this->db->options['max_identifiers_length'])) {
|
||||||
|
$max_identifiers_length = $this->db->options['max_identifiers_length'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$val = new $class_name(
|
||||||
|
$this->options['fail_on_invalid_names'],
|
||||||
|
$this->options['valid_types'],
|
||||||
|
$this->options['force_defaults'],
|
||||||
|
$max_identifiers_length
|
||||||
|
);
|
||||||
|
|
||||||
$database_definition = array(
|
$database_definition = array(
|
||||||
'name' => $database,
|
'name' => $database,
|
||||||
|
@ -470,7 +486,7 @@ class MDB2_Schema extends PEAR
|
||||||
'initialization' => array()
|
'initialization' => array()
|
||||||
);
|
);
|
||||||
|
|
||||||
$table_definition =& $database_definition['tables'][$table_name];
|
$table_definition = $database_definition['tables'][$table_name];
|
||||||
foreach ($fields as $field_name) {
|
foreach ($fields as $field_name) {
|
||||||
$definition = $this->db->reverse->getTableFieldDefinition($table_name, $field_name);
|
$definition = $this->db->reverse->getTableFieldDefinition($table_name, $field_name);
|
||||||
if (PEAR::isError($definition)) {
|
if (PEAR::isError($definition)) {
|
||||||
|
@ -628,6 +644,7 @@ class MDB2_Schema extends PEAR
|
||||||
if (PEAR::isError($result)) {
|
if (PEAR::isError($result)) {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
$database_definition['tables'][$table_name]=$table_definition;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1455,16 +1472,17 @@ class MDB2_Schema extends PEAR
|
||||||
$changes['tables'] = MDB2_Schema::arrayMergeClobber($changes['tables'], $change);
|
$changes['tables'] = MDB2_Schema::arrayMergeClobber($changes['tables'], $change);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!empty($previous_definition['tables'])
|
if (!empty($previous_definition['tables'])
|
||||||
&& is_array($previous_definition['tables'])) {
|
&& is_array($previous_definition['tables'])
|
||||||
foreach ($previous_definition['tables'] as $table_name => $table) {
|
) {
|
||||||
if (empty($defined_tables[$table_name])) {
|
foreach ($previous_definition['tables'] as $table_name => $table) {
|
||||||
$changes['tables']['remove'][$table_name] = true;
|
if (empty($defined_tables[$table_name])) {
|
||||||
}
|
$changes['tables']['remove'][$table_name] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($current_definition['sequences']) && is_array($current_definition['sequences'])) {
|
if (!empty($current_definition['sequences']) && is_array($current_definition['sequences'])) {
|
||||||
$changes['sequences'] = $defined_sequences = array();
|
$changes['sequences'] = $defined_sequences = array();
|
||||||
foreach ($current_definition['sequences'] as $sequence_name => $sequence) {
|
foreach ($current_definition['sequences'] as $sequence_name => $sequence) {
|
||||||
|
@ -1484,14 +1502,17 @@ class MDB2_Schema extends PEAR
|
||||||
$changes['sequences'] = MDB2_Schema::arrayMergeClobber($changes['sequences'], $change);
|
$changes['sequences'] = MDB2_Schema::arrayMergeClobber($changes['sequences'], $change);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!empty($previous_definition['sequences']) && is_array($previous_definition['sequences'])) {
|
}
|
||||||
foreach ($previous_definition['sequences'] as $sequence_name => $sequence) {
|
if (!empty($previous_definition['sequences'])
|
||||||
if (empty($defined_sequences[$sequence_name])) {
|
&& is_array($previous_definition['sequences'])
|
||||||
$changes['sequences']['remove'][$sequence_name] = true;
|
) {
|
||||||
}
|
foreach ($previous_definition['sequences'] as $sequence_name => $sequence) {
|
||||||
|
if (empty($defined_sequences[$sequence_name])) {
|
||||||
|
$changes['sequences']['remove'][$sequence_name] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $changes;
|
return $changes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2022,9 +2043,10 @@ class MDB2_Schema extends PEAR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->options['drop_missing_tables']
|
if ($this->options['drop_obsolete_objects']
|
||||||
&& !empty($changes['remove'])
|
&& !empty($changes['remove'])
|
||||||
&& is_array($changes['remove'])) {
|
&& is_array($changes['remove'])
|
||||||
|
) {
|
||||||
foreach ($changes['remove'] as $table_name => $table) {
|
foreach ($changes['remove'] as $table_name => $table) {
|
||||||
$result = $this->db->manager->dropTable($table_name);
|
$result = $this->db->manager->dropTable($table_name);
|
||||||
if (PEAR::isError($result)) {
|
if (PEAR::isError($result)) {
|
||||||
|
@ -2105,7 +2127,10 @@ class MDB2_Schema extends PEAR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($changes['remove']) && is_array($changes['remove'])) {
|
if ($this->options['drop_obsolete_objects']
|
||||||
|
&& !empty($changes['remove'])
|
||||||
|
&& is_array($changes['remove'])
|
||||||
|
) {
|
||||||
foreach ($changes['remove'] as $sequence_name => $sequence) {
|
foreach ($changes['remove'] as $sequence_name => $sequence) {
|
||||||
$result = $this->db->manager->dropSequence($sequence_name);
|
$result = $this->db->manager->dropSequence($sequence_name);
|
||||||
if (PEAR::isError($result)) {
|
if (PEAR::isError($result)) {
|
||||||
|
@ -2232,7 +2257,7 @@ class MDB2_Schema extends PEAR
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($changes['tables']['remove']) && is_array($changes['tables']['remove'])) {
|
if (!empty($changes['tables']['remove']) && is_array($changes['tables']['remove'])) {
|
||||||
if ($this->options['drop_missing_tables']) {
|
if ($this->options['drop_obsolete_objects']) {
|
||||||
foreach ($changes['tables']['remove'] as $table_name => $table) {
|
foreach ($changes['tables']['remove'] as $table_name => $table) {
|
||||||
$this->db->debug("$table_name:", __FUNCTION__);
|
$this->db->debug("$table_name:", __FUNCTION__);
|
||||||
$this->db->debug("\tRemoved table '$table_name'", __FUNCTION__);
|
$this->db->debug("\tRemoved table '$table_name'", __FUNCTION__);
|
||||||
|
@ -2338,9 +2363,15 @@ class MDB2_Schema extends PEAR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!empty($changes['sequences']['remove']) && is_array($changes['sequences']['remove'])) {
|
if (!empty($changes['sequences']['remove']) && is_array($changes['sequences']['remove'])) {
|
||||||
foreach ($changes['sequences']['remove'] as $sequence_name => $sequence) {
|
if ($this->options['drop_obsolete_objects']) {
|
||||||
$this->db->debug("$sequence_name:", __FUNCTION__);
|
foreach ($changes['sequences']['remove'] as $sequence_name => $sequence) {
|
||||||
$this->db->debug("\tAdded sequence '$sequence_name'", __FUNCTION__);
|
$this->db->debug("$sequence_name:", __FUNCTION__);
|
||||||
|
$this->db->debug("\tRemoved sequence '$sequence_name'", __FUNCTION__);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
foreach ($changes['sequences']['remove'] as $sequence_name => $sequence) {
|
||||||
|
$this->db->debug("\tObsolete sequence '$sequence_name' left as is", __FUNCTION__);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!empty($changes['sequences']['change']) && is_array($changes['sequences']['change'])) {
|
if (!empty($changes['sequences']['change']) && is_array($changes['sequences']['change'])) {
|
||||||
|
@ -2448,7 +2479,7 @@ class MDB2_Schema extends PEAR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$writer =& new $class_name($this->options['valid_types']);
|
$writer = new $class_name($this->options['valid_types']);
|
||||||
return $writer->dumpDatabase($database_definition, $arguments, $dump);
|
return $writer->dumpDatabase($database_definition, $arguments, $dump);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2696,9 +2727,9 @@ class MDB2_Schema extends PEAR
|
||||||
* @access public
|
* @access public
|
||||||
* @see PEAR_Error
|
* @see PEAR_Error
|
||||||
*/
|
*/
|
||||||
function &raiseError($code = null, $mode = null, $options = null, $userinfo = null)
|
static function &raiseError($code = null, $mode = null, $options = null, $userinfo = null, $dummy1 = null, $dummy2 = null, $dummy3 = false)
|
||||||
{
|
{
|
||||||
$err =& PEAR::raiseError(null, $code, $mode, $options,
|
$err = PEAR::raiseError(null, $code, $mode, $options,
|
||||||
$userinfo, 'MDB2_Schema_Error', true);
|
$userinfo, 'MDB2_Schema_Error', true);
|
||||||
return $err;
|
return $err;
|
||||||
}
|
}
|
||||||
|
@ -2717,7 +2748,7 @@ class MDB2_Schema extends PEAR
|
||||||
* @return bool true if parameter is an error
|
* @return bool true if parameter is an error
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
function isError($data, $code = null)
|
static function isError($data, $code = null)
|
||||||
{
|
{
|
||||||
if (is_a($data, 'MDB2_Schema_Error')) {
|
if (is_a($data, 'MDB2_Schema_Error')) {
|
||||||
if (is_null($code)) {
|
if (is_null($code)) {
|
||||||
|
@ -2764,4 +2795,3 @@ class MDB2_Schema_Error extends PEAR_Error
|
||||||
$mode, $level, $debuginfo);
|
$mode, $level, $debuginfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
<?php
|
<?php /* vim: se et ts=4 sw=4 sts=4 fdm=marker tw=80: */
|
||||||
/**
|
/**
|
||||||
* PHP versions 4 and 5
|
* Copyright (c) 1998-2010 Manuel Lemos, Tomas V.V.Cox,
|
||||||
*
|
|
||||||
* Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox,
|
|
||||||
* Stig. S. Bakken, Lukas Smith, Igor Feghali
|
* Stig. S. Bakken, Lukas Smith, Igor Feghali
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
|
@ -39,21 +37,17 @@
|
||||||
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* Author: Christian Dickmann <dickmann@php.net>
|
* PHP version 5
|
||||||
* Author: Igor Feghali <ifeghali@php.net>
|
|
||||||
*
|
|
||||||
* $Id: Parser.php,v 1.68 2008/11/30 03:34:00 clockwerx Exp $
|
|
||||||
*
|
*
|
||||||
* @category Database
|
* @category Database
|
||||||
* @package MDB2_Schema
|
* @package MDB2_Schema
|
||||||
* @author Christian Dickmann <dickmann@php.net>
|
* @author Christian Dickmann <dickmann@php.net>
|
||||||
* @author Igor Feghali <ifeghali@php.net>
|
* @author Igor Feghali <ifeghali@php.net>
|
||||||
* @license BSD http://www.opensource.org/licenses/bsd-license.php
|
* @license BSD http://www.opensource.org/licenses/bsd-license.php
|
||||||
* @version CVS: $Id: Parser.php,v 1.68 2008/11/30 03:34:00 clockwerx Exp $
|
* @version SVN: $Id$
|
||||||
* @link http://pear.php.net/packages/MDB2_Schema
|
* @link http://pear.php.net/packages/MDB2_Schema
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
require_once 'XML/Parser.php';
|
require_once 'XML/Parser.php';
|
||||||
require_once 'MDB2/Schema/Validate.php';
|
require_once 'MDB2/Schema/Validate.php';
|
||||||
|
|
||||||
|
@ -114,27 +108,83 @@ class MDB2_Schema_Parser extends XML_Parser
|
||||||
|
|
||||||
var $val;
|
var $val;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PHP 5 constructor
|
||||||
|
*
|
||||||
|
* @param array $variables mixed array with user defined schema
|
||||||
|
* variables
|
||||||
|
* @param bool $fail_on_invalid_names array with reserved words per RDBMS
|
||||||
|
* @param array $structure multi dimensional array with
|
||||||
|
* database schema and data
|
||||||
|
* @param array $valid_types information of all valid fields
|
||||||
|
* types
|
||||||
|
* @param bool $force_defaults if true sets a default value to
|
||||||
|
* field when not explicit
|
||||||
|
* @param int $max_identifiers_length maximum allowed size for entities
|
||||||
|
* name
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @static
|
||||||
|
*/
|
||||||
function __construct($variables, $fail_on_invalid_names = true,
|
function __construct($variables, $fail_on_invalid_names = true,
|
||||||
$structure = false, $valid_types = array(),
|
$structure = false, $valid_types = array(), $force_defaults = true,
|
||||||
$force_defaults = true)
|
$max_identifiers_length = null
|
||||||
{
|
) {
|
||||||
// force ISO-8859-1 due to different defaults for PHP4 and PHP5
|
// force ISO-8859-1 due to different defaults for PHP4 and PHP5
|
||||||
// todo: this probably needs to be investigated some more andcleaned up
|
// todo: this probably needs to be investigated some more andcleaned up
|
||||||
parent::XML_Parser('ISO-8859-1');
|
parent::__construct('ISO-8859-1');
|
||||||
|
|
||||||
$this->variables = $variables;
|
$this->variables = $variables;
|
||||||
$this->structure = $structure;
|
$this->structure = $structure;
|
||||||
$this->val =& new MDB2_Schema_Validate($fail_on_invalid_names, $valid_types, $force_defaults);
|
$this->val = new MDB2_Schema_Validate(
|
||||||
|
$fail_on_invalid_names,
|
||||||
|
$valid_types,
|
||||||
|
$force_defaults,
|
||||||
|
$max_identifiers_length
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PHP 4 compatible constructor
|
||||||
|
*
|
||||||
|
* @param array $variables mixed array with user defined schema
|
||||||
|
* variables
|
||||||
|
* @param bool $fail_on_invalid_names array with reserved words per RDBMS
|
||||||
|
* @param array $structure multi dimensional array with
|
||||||
|
* database schema and data
|
||||||
|
* @param array $valid_types information of all valid fields
|
||||||
|
* types
|
||||||
|
* @param bool $force_defaults if true sets a default value to
|
||||||
|
* field when not explicit
|
||||||
|
* @param int $max_identifiers_length maximum allowed size for entities
|
||||||
|
* name
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @static
|
||||||
|
*/
|
||||||
function MDB2_Schema_Parser($variables, $fail_on_invalid_names = true,
|
function MDB2_Schema_Parser($variables, $fail_on_invalid_names = true,
|
||||||
$structure = false, $valid_types = array(),
|
$structure = false, $valid_types = array(), $force_defaults = true,
|
||||||
$force_defaults = true)
|
$max_identifiers_length = null
|
||||||
{
|
) {
|
||||||
$this->__construct($variables, $fail_on_invalid_names, $structure, $valid_types, $force_defaults);
|
$this->__construct($variables, $fail_on_invalid_names, $structure, $valid_types, $force_defaults);
|
||||||
}
|
}
|
||||||
|
|
||||||
function startHandler($xp, $element, $attribs)
|
/**
|
||||||
|
* Triggered when reading a XML open tag <element>
|
||||||
|
*
|
||||||
|
* @param resource $xp xml parser resource
|
||||||
|
* @param string $element element name
|
||||||
|
* @param array $attribs attributes
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @access private
|
||||||
|
* @static
|
||||||
|
*/
|
||||||
|
function startHandler($xp, $element, &$attribs)
|
||||||
{
|
{
|
||||||
if (strtolower($element) == 'variable') {
|
if (strtolower($element) == 'variable') {
|
||||||
$this->var_mode = true;
|
$this->var_mode = true;
|
||||||
|
@ -335,12 +385,21 @@ class MDB2_Schema_Parser extends XML_Parser
|
||||||
'start' => '',
|
'start' => '',
|
||||||
'description' => '',
|
'description' => '',
|
||||||
'comments' => '',
|
'comments' => '',
|
||||||
'on' => array('table' => '', 'field' => '')
|
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Triggered when reading a XML close tag </element>
|
||||||
|
*
|
||||||
|
* @param resource $xp xml parser resource
|
||||||
|
* @param string $element element name
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @access private
|
||||||
|
* @static
|
||||||
|
*/
|
||||||
function endHandler($xp, $element)
|
function endHandler($xp, $element)
|
||||||
{
|
{
|
||||||
if (strtolower($element) == 'variable') {
|
if (strtolower($element) == 'variable') {
|
||||||
|
@ -503,7 +562,21 @@ class MDB2_Schema_Parser extends XML_Parser
|
||||||
$this->element = implode('-', $this->elements);
|
$this->element = implode('-', $this->elements);
|
||||||
}
|
}
|
||||||
|
|
||||||
function &raiseError($msg = null, $xmlecode = 0, $xp = null, $ecode = MDB2_SCHEMA_ERROR_PARSE)
|
/**
|
||||||
|
* Pushes a MDB2_Schema_Error into stack and returns it
|
||||||
|
*
|
||||||
|
* @param string $msg textual message
|
||||||
|
* @param int $xmlecode PHP's XML parser error code
|
||||||
|
* @param resource $xp xml parser resource
|
||||||
|
* @param int $ecode MDB2_Schema's error code
|
||||||
|
*
|
||||||
|
* @return object
|
||||||
|
* @access private
|
||||||
|
* @static
|
||||||
|
*/
|
||||||
|
static function &raiseError($msg = null, $xmlecode = 0, $xp = null, $ecode = MDB2_SCHEMA_ERROR_PARSE, $userinfo = null,
|
||||||
|
$error_class = null,
|
||||||
|
$skipmsg = false)
|
||||||
{
|
{
|
||||||
if (is_null($this->error)) {
|
if (is_null($this->error)) {
|
||||||
$error = '';
|
$error = '';
|
||||||
|
@ -530,11 +603,21 @@ class MDB2_Schema_Parser extends XML_Parser
|
||||||
|
|
||||||
$error .= "\n";
|
$error .= "\n";
|
||||||
|
|
||||||
$this->error =& MDB2_Schema::raiseError($ecode, null, null, $error);
|
$this->error = MDB2_Schema::raiseError($ecode, null, null, $error);
|
||||||
}
|
}
|
||||||
return $this->error;
|
return $this->error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Triggered when reading data in a XML element (text between tags)
|
||||||
|
*
|
||||||
|
* @param resource $xp xml parser resource
|
||||||
|
* @param string $data text
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @access private
|
||||||
|
* @static
|
||||||
|
*/
|
||||||
function cdataHandler($xp, $data)
|
function cdataHandler($xp, $data)
|
||||||
{
|
{
|
||||||
if ($this->var_mode == true) {
|
if ($this->var_mode == true) {
|
||||||
|
@ -806,6 +889,9 @@ class MDB2_Schema_Parser extends XML_Parser
|
||||||
case 'database-sequence-comments':
|
case 'database-sequence-comments':
|
||||||
$this->sequence['comments'] .= $data;
|
$this->sequence['comments'] .= $data;
|
||||||
break;
|
break;
|
||||||
|
case 'database-sequence-on':
|
||||||
|
$this->sequence['on'] = array('table' => '', 'field' => '');
|
||||||
|
break;
|
||||||
case 'database-sequence-on-table':
|
case 'database-sequence-on-table':
|
||||||
$this->sequence['on']['table'] .= $data;
|
$this->sequence['on']['table'] .= $data;
|
||||||
break;
|
break;
|
||||||
|
@ -815,5 +901,3 @@ class MDB2_Schema_Parser extends XML_Parser
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
<?php
|
<?php /* vim: se et ts=4 sw=4 sts=4 fdm=marker tw=80: */
|
||||||
/**
|
/**
|
||||||
* PHP versions 4 and 5
|
* Copyright (c) 1998-2010 Manuel Lemos, Tomas V.V.Cox,
|
||||||
*
|
|
||||||
* Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox,
|
|
||||||
* Stig. S. Bakken, Lukas Smith, Igor Feghali
|
* Stig. S. Bakken, Lukas Smith, Igor Feghali
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
|
@ -39,13 +37,13 @@
|
||||||
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* Author: Igor Feghali <ifeghali@php.net>
|
* PHP version 5
|
||||||
*
|
*
|
||||||
* @category Database
|
* @category Database
|
||||||
* @package MDB2_Schema
|
* @package MDB2_Schema
|
||||||
* @author Igor Feghali <ifeghali@php.net>
|
* @author Igor Feghali <ifeghali@php.net>
|
||||||
* @license BSD http://www.opensource.org/licenses/bsd-license.php
|
* @license BSD http://www.opensource.org/licenses/bsd-license.php
|
||||||
* @version CVS: $Id: Parser2.php,v 1.12 2008/11/30 03:34:00 clockwerx Exp $
|
* @version SVN: $Id$
|
||||||
* @link http://pear.php.net/packages/MDB2_Schema
|
* @link http://pear.php.net/packages/MDB2_Schema
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -100,8 +98,30 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
|
||||||
|
|
||||||
var $init = array();
|
var $init = array();
|
||||||
|
|
||||||
function __construct($variables, $fail_on_invalid_names = true, $structure = false, $valid_types = array(), $force_defaults = true)
|
/**
|
||||||
{
|
* PHP 5 constructor
|
||||||
|
*
|
||||||
|
* @param array $variables mixed array with user defined schema
|
||||||
|
* variables
|
||||||
|
* @param bool $fail_on_invalid_names array with reserved words per RDBMS
|
||||||
|
* @param array $structure multi dimensional array with
|
||||||
|
* database schema and data
|
||||||
|
* @param array $valid_types information of all valid fields
|
||||||
|
* types
|
||||||
|
* @param bool $force_defaults if true sets a default value to
|
||||||
|
* field when not explicit
|
||||||
|
* @param int $max_identifiers_length maximum allowed size for entities
|
||||||
|
* name
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @static
|
||||||
|
*/
|
||||||
|
function __construct($variables, $fail_on_invalid_names = true,
|
||||||
|
$structure = false, $valid_types = array(), $force_defaults = true,
|
||||||
|
$max_identifiers_length = null
|
||||||
|
) {
|
||||||
// force ISO-8859-1 due to different defaults for PHP4 and PHP5
|
// force ISO-8859-1 due to different defaults for PHP4 and PHP5
|
||||||
// todo: this probably needs to be investigated some more and cleaned up
|
// todo: this probably needs to be investigated some more and cleaned up
|
||||||
$this->options['encoding'] = 'ISO-8859-1';
|
$this->options['encoding'] = 'ISO-8859-1';
|
||||||
|
@ -119,15 +139,44 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
|
||||||
$this->variables = $variables;
|
$this->variables = $variables;
|
||||||
$this->structure = $structure;
|
$this->structure = $structure;
|
||||||
|
|
||||||
$this->val =& new MDB2_Schema_Validate($fail_on_invalid_names, $valid_types, $force_defaults);
|
$this->val = new MDB2_Schema_Validate($fail_on_invalid_names, $valid_types, $force_defaults);
|
||||||
parent::XML_Unserializer($this->options);
|
parent::XML_Unserializer($this->options);
|
||||||
}
|
}
|
||||||
|
|
||||||
function MDB2_Schema_Parser2($variables, $fail_on_invalid_names = true, $structure = false, $valid_types = array(), $force_defaults = true)
|
/**
|
||||||
{
|
* PHP 4 compatible constructor
|
||||||
|
*
|
||||||
|
* @param array $variables mixed array with user defined schema
|
||||||
|
* variables
|
||||||
|
* @param bool $fail_on_invalid_names array with reserved words per RDBMS
|
||||||
|
* @param array $structure multi dimensional array with
|
||||||
|
* database schema and data
|
||||||
|
* @param array $valid_types information of all valid fields
|
||||||
|
* types
|
||||||
|
* @param bool $force_defaults if true sets a default value to
|
||||||
|
* field when not explicit
|
||||||
|
* @param int $max_identifiers_length maximum allowed size for entities
|
||||||
|
* name
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @static
|
||||||
|
*/
|
||||||
|
function MDB2_Schema_Parser2($variables, $fail_on_invalid_names = true,
|
||||||
|
$structure = false, $valid_types = array(), $force_defaults = true,
|
||||||
|
$max_identifiers_length = null
|
||||||
|
) {
|
||||||
$this->__construct($variables, $fail_on_invalid_names, $structure, $valid_types, $force_defaults);
|
$this->__construct($variables, $fail_on_invalid_names, $structure, $valid_types, $force_defaults);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main method. Parses XML Schema File.
|
||||||
|
*
|
||||||
|
* @return bool|error object
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
function parse()
|
function parse()
|
||||||
{
|
{
|
||||||
$result = $this->unserialize($this->filename, true);
|
$result = $this->unserialize($this->filename, true);
|
||||||
|
@ -140,18 +189,33 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do the necessary stuff to set the input XML schema file
|
||||||
|
*
|
||||||
|
* @param string $filename full path to schema file
|
||||||
|
*
|
||||||
|
* @return boolean MDB2_OK on success
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
function setInputFile($filename)
|
function setInputFile($filename)
|
||||||
{
|
{
|
||||||
$this->filename = $filename;
|
$this->filename = $filename;
|
||||||
return MDB2_OK;
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
function renameKey(&$arr, $oKey, $nKey)
|
/**
|
||||||
{
|
* Enforce the default values for mandatory keys and ensure everything goes
|
||||||
$arr[$nKey] = &$arr[$oKey];
|
* always in the same order (simulates the behaviour of the original
|
||||||
unset($arr[$oKey]);
|
* parser). Works at database level.
|
||||||
}
|
*
|
||||||
|
* @param array $database multi dimensional array with database definition
|
||||||
|
* and data.
|
||||||
|
*
|
||||||
|
* @return bool|error MDB2_OK on success or error object
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
function fixDatabaseKeys($database)
|
function fixDatabaseKeys($database)
|
||||||
{
|
{
|
||||||
$this->database_definition = array(
|
$this->database_definition = array(
|
||||||
|
@ -204,6 +268,18 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
|
||||||
return MDB2_OK;
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enforce the default values for mandatory keys and ensure everything goes
|
||||||
|
* always in the same order (simulates the behaviour of the original
|
||||||
|
* parser). Works at table level.
|
||||||
|
*
|
||||||
|
* @param array $table multi dimensional array with table definition
|
||||||
|
* and data.
|
||||||
|
*
|
||||||
|
* @return bool|error MDB2_OK on success or error object
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
function fixTableKeys($table)
|
function fixTableKeys($table)
|
||||||
{
|
{
|
||||||
$this->table = array(
|
$this->table = array(
|
||||||
|
@ -279,6 +355,17 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
|
||||||
return MDB2_OK;
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enforce the default values for mandatory keys and ensure everything goes
|
||||||
|
* always in the same order (simulates the behaviour of the original
|
||||||
|
* parser). Works at table field level.
|
||||||
|
*
|
||||||
|
* @param array $field array with table field definition
|
||||||
|
*
|
||||||
|
* @return bool|error MDB2_OK on success or error object
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
function fixTableFieldKeys($field)
|
function fixTableFieldKeys($field)
|
||||||
{
|
{
|
||||||
$this->field = array();
|
$this->field = array();
|
||||||
|
@ -328,6 +415,17 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
|
||||||
return MDB2_OK;
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enforce the default values for mandatory keys and ensure everything goes
|
||||||
|
* always in the same order (simulates the behaviour of the original
|
||||||
|
* parser). Works at table index level.
|
||||||
|
*
|
||||||
|
* @param array $index array with table index definition
|
||||||
|
*
|
||||||
|
* @return bool|error MDB2_OK on success or error object
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
function fixTableIndexKeys($index)
|
function fixTableIndexKeys($index)
|
||||||
{
|
{
|
||||||
$this->index = array(
|
$this->index = array(
|
||||||
|
@ -389,6 +487,17 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
|
||||||
return MDB2_OK;
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enforce the default values for mandatory keys and ensure everything goes
|
||||||
|
* always in the same order (simulates the behaviour of the original
|
||||||
|
* parser). Works at table constraint level.
|
||||||
|
*
|
||||||
|
* @param array $constraint array with table index definition
|
||||||
|
*
|
||||||
|
* @return bool|error MDB2_OK on success or error object
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
function fixTableConstraintKeys($constraint)
|
function fixTableConstraintKeys($constraint)
|
||||||
{
|
{
|
||||||
$this->constraint = array(
|
$this->constraint = array(
|
||||||
|
@ -468,6 +577,18 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
|
||||||
return MDB2_OK;
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enforce the default values for mandatory keys and ensure everything goes
|
||||||
|
* always in the same order (simulates the behaviour of the original
|
||||||
|
* parser). Works at table data level.
|
||||||
|
*
|
||||||
|
* @param array $element multi dimensional array with query definition
|
||||||
|
* @param string $type whether its a insert|update|delete query
|
||||||
|
*
|
||||||
|
* @return bool|error MDB2_OK on success or error object
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
function fixTableInitializationKeys($element, $type = '')
|
function fixTableInitializationKeys($element, $type = '')
|
||||||
{
|
{
|
||||||
if (!empty($element['select']) && is_array($element['select'])) {
|
if (!empty($element['select']) && is_array($element['select'])) {
|
||||||
|
@ -480,6 +601,43 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
|
||||||
$this->table['initialization'][] = array( 'type' => $type, 'data' => $this->init );
|
$this->table['initialization'][] = array( 'type' => $type, 'data' => $this->init );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enforce the default values for mandatory keys and ensure everything goes
|
||||||
|
* always in the same order (simulates the behaviour of the original
|
||||||
|
* parser). Works deeper at the table initialization level (data). At this
|
||||||
|
* point we are look at one of the below:
|
||||||
|
*
|
||||||
|
* <insert>
|
||||||
|
* {field}+
|
||||||
|
* </insert>
|
||||||
|
*
|
||||||
|
* <select> (this is a select extracted off a insert-select query)
|
||||||
|
* <table/>
|
||||||
|
* {field}+
|
||||||
|
* <where>
|
||||||
|
* {expression}
|
||||||
|
* </where>?
|
||||||
|
* </select>
|
||||||
|
*
|
||||||
|
* <update>
|
||||||
|
* {field}+
|
||||||
|
* <where>
|
||||||
|
* {expression}
|
||||||
|
* </where>?
|
||||||
|
* </update>
|
||||||
|
*
|
||||||
|
* <delete>
|
||||||
|
* <where>
|
||||||
|
* {expression}
|
||||||
|
* </where>
|
||||||
|
* </delete>
|
||||||
|
*
|
||||||
|
* @param array $element multi dimensional array with query definition
|
||||||
|
*
|
||||||
|
* @return bool|error MDB2_OK on success or error object
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
function fixTableInitializationDataKeys($element)
|
function fixTableInitializationDataKeys($element)
|
||||||
{
|
{
|
||||||
$this->init = array();
|
$this->init = array();
|
||||||
|
@ -505,6 +663,22 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recursively diggs into an "expression" element. According to our
|
||||||
|
* documentation an "expression" element is of the kind:
|
||||||
|
*
|
||||||
|
* <expression>
|
||||||
|
* <null/> or <value/> or <column/> or {function} or {expression}
|
||||||
|
* <operator/>
|
||||||
|
* <null/> or <value/> or <column/> or {function} or {expression}
|
||||||
|
* </expression>
|
||||||
|
*
|
||||||
|
* @param array &$arr reference to current element definition
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
function setExpression(&$arr)
|
function setExpression(&$arr)
|
||||||
{
|
{
|
||||||
$element = each($arr);
|
$element = each($arr);
|
||||||
|
@ -555,6 +729,30 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enforce the default values for mandatory keys and ensure everything goes
|
||||||
|
* always in the same order (simulates the behaviour of the original
|
||||||
|
* parser). Works at database sequences level. A "sequence" element looks
|
||||||
|
* like:
|
||||||
|
*
|
||||||
|
* <sequence>
|
||||||
|
* <name/>
|
||||||
|
* <was/>?
|
||||||
|
* <start/>?
|
||||||
|
* <description/>?
|
||||||
|
* <comments/>?
|
||||||
|
* <on>
|
||||||
|
* <table/>
|
||||||
|
* <field/>
|
||||||
|
* </on>?
|
||||||
|
* </sequence>
|
||||||
|
*
|
||||||
|
* @param array $sequence multi dimensional array with sequence definition
|
||||||
|
*
|
||||||
|
* @return bool|error MDB2_OK on success or error object
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
function fixSequenceKeys($sequence)
|
function fixSequenceKeys($sequence)
|
||||||
{
|
{
|
||||||
$this->sequence = array(
|
$this->sequence = array(
|
||||||
|
@ -562,7 +760,6 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
|
||||||
'start' => '',
|
'start' => '',
|
||||||
'description' => '',
|
'description' => '',
|
||||||
'comments' => '',
|
'comments' => '',
|
||||||
'on' => array('table' => '', 'field' => '')
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!empty($sequence['name'])) {
|
if (!empty($sequence['name'])) {
|
||||||
|
@ -610,15 +807,23 @@ class MDB2_Schema_Parser2 extends XML_Unserializer
|
||||||
return MDB2_OK;
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pushes a MDB2_Schema_Error into stack and returns it
|
||||||
|
*
|
||||||
|
* @param string $msg textual message
|
||||||
|
* @param int $ecode MDB2_Schema's error code
|
||||||
|
*
|
||||||
|
* @return object
|
||||||
|
* @access private
|
||||||
|
* @static
|
||||||
|
*/
|
||||||
function &raiseError($msg = null, $ecode = MDB2_SCHEMA_ERROR_PARSE)
|
function &raiseError($msg = null, $ecode = MDB2_SCHEMA_ERROR_PARSE)
|
||||||
{
|
{
|
||||||
if (is_null($this->error)) {
|
if (is_null($this->error)) {
|
||||||
$error = 'Parser error: '.$msg."\n";
|
$error = 'Parser error: '.$msg."\n";
|
||||||
|
|
||||||
$this->error =& MDB2_Schema::raiseError($ecode, null, null, $error);
|
$this->error = MDB2_Schema::raiseError($ecode, null, null, $error);
|
||||||
}
|
}
|
||||||
return $this->error;
|
return $this->error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
|
@ -1,49 +1,51 @@
|
||||||
<?php
|
<?php /* vim: se et ts=4 sw=4 sts=4 fdm=marker tw=80: */
|
||||||
// {{{ Disclaimer, Licence, copyrights
|
/**
|
||||||
// +----------------------------------------------------------------------+
|
* Copyright (c) 1998-2010 Manuel Lemos, Tomas V.V.Cox,
|
||||||
// | PHP versions 4 and 5 |
|
* Stig. S. Bakken, Lukas Smith, Igor Feghali
|
||||||
// +----------------------------------------------------------------------+
|
* All rights reserved.
|
||||||
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
|
*
|
||||||
// | Stig. S. Bakken, Lukas Smith |
|
* MDB2_Schema enables users to maintain RDBMS independant schema files
|
||||||
// | All rights reserved. |
|
* in XML that can be used to manipulate both data and database schemas
|
||||||
// +----------------------------------------------------------------------+
|
* This LICENSE is in the BSD license style.
|
||||||
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
|
*
|
||||||
// | API as well as database abstraction for PHP applications. |
|
* Redistribution and use in source and binary forms, with or without
|
||||||
// | This LICENSE is in the BSD license style. |
|
* modification, are permitted provided that the following conditions
|
||||||
// | |
|
* are met:
|
||||||
// | Redistribution and use in source and binary forms, with or without |
|
*
|
||||||
// | modification, are permitted provided that the following conditions |
|
* Redistributions of source code must retain the above copyright
|
||||||
// | are met: |
|
* notice, this list of conditions and the following disclaimer.
|
||||||
// | |
|
*
|
||||||
// | Redistributions of source code must retain the above copyright |
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
// | notice, this list of conditions and the following disclaimer. |
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
// | |
|
* documentation and/or other materials provided with the distribution.
|
||||||
// | Redistributions in binary form must reproduce the above copyright |
|
*
|
||||||
// | notice, this list of conditions and the following disclaimer in the |
|
* Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,
|
||||||
// | documentation and/or other materials provided with the distribution. |
|
* Lukas Smith, Igor Feghali nor the names of his contributors may be
|
||||||
// | |
|
* used to endorse or promote products derived from this software
|
||||||
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
|
* without specific prior written permission.
|
||||||
// | Lukas Smith nor the names of his contributors may be used to endorse |
|
*
|
||||||
// | or promote products derived from this software without specific prior|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
// | written permission. |
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
// | |
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
* REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
|
||||||
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
|
*
|
||||||
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
* PHP version 5
|
||||||
// | POSSIBILITY OF SUCH DAMAGE. |
|
*
|
||||||
// +----------------------------------------------------------------------+
|
* @category Database
|
||||||
// | Author: Lorenzo Alberton <l.alberton@quipo.it> |
|
* @package MDB2_Schema
|
||||||
// +----------------------------------------------------------------------+
|
* @author Lorenzo Alberton <l.alberton@quipo.it>
|
||||||
//
|
* @license BSD http://www.opensource.org/licenses/bsd-license.php
|
||||||
// }}}
|
* @version SVN: $Id$
|
||||||
|
* @link http://pear.php.net/packages/MDB2_Schema
|
||||||
|
*/
|
||||||
// {{{ $GLOBALS['_MDB2_Schema_Reserved']['ibase']
|
// {{{ $GLOBALS['_MDB2_Schema_Reserved']['ibase']
|
||||||
/**
|
/**
|
||||||
* Has a list of reserved words of Interbase/Firebird
|
* Has a list of reserved words of Interbase/Firebird
|
||||||
|
@ -433,4 +435,3 @@ $GLOBALS['_MDB2_Schema_Reserved']['ibase'] = array(
|
||||||
'ZONE',
|
'ZONE',
|
||||||
);
|
);
|
||||||
// }}}
|
// }}}
|
||||||
?>
|
|
|
@ -1,48 +1,52 @@
|
||||||
<?php
|
<?php /* vim: se et ts=4 sw=4 sts=4 fdm=marker tw=80: */
|
||||||
// {{{ Disclaimer, Licence, copyrights
|
/**
|
||||||
// +----------------------------------------------------------------------+
|
* Copyright (c) 1998-2010 Manuel Lemos, Tomas V.V.Cox,
|
||||||
// | PHP versions 4 and 5 |
|
* Stig. S. Bakken, Lukas Smith, Igor Feghali
|
||||||
// +----------------------------------------------------------------------+
|
* All rights reserved.
|
||||||
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
|
*
|
||||||
// | Stig. S. Bakken, Lukas Smith |
|
* MDB2_Schema enables users to maintain RDBMS independant schema files
|
||||||
// | All rights reserved. |
|
* in XML that can be used to manipulate both data and database schemas
|
||||||
// +----------------------------------------------------------------------+
|
* This LICENSE is in the BSD license style.
|
||||||
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
|
*
|
||||||
// | API as well as database abstraction for PHP applications. |
|
* Redistribution and use in source and binary forms, with or without
|
||||||
// | This LICENSE is in the BSD license style. |
|
* modification, are permitted provided that the following conditions
|
||||||
// | |
|
* are met:
|
||||||
// | Redistribution and use in source and binary forms, with or without |
|
*
|
||||||
// | modification, are permitted provided that the following conditions |
|
* Redistributions of source code must retain the above copyright
|
||||||
// | are met: |
|
* notice, this list of conditions and the following disclaimer.
|
||||||
// | |
|
*
|
||||||
// | Redistributions of source code must retain the above copyright |
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
// | notice, this list of conditions and the following disclaimer. |
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
// | |
|
* documentation and/or other materials provided with the distribution.
|
||||||
// | Redistributions in binary form must reproduce the above copyright |
|
*
|
||||||
// | notice, this list of conditions and the following disclaimer in the |
|
* Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,
|
||||||
// | documentation and/or other materials provided with the distribution. |
|
* Lukas Smith, Igor Feghali nor the names of his contributors may be
|
||||||
// | |
|
* used to endorse or promote products derived from this software
|
||||||
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
|
* without specific prior written permission.
|
||||||
// | Lukas Smith nor the names of his contributors may be used to endorse |
|
*
|
||||||
// | or promote products derived from this software without specific prior|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
// | written permission. |
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
// | |
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
* REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
|
||||||
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
|
*
|
||||||
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
* PHP version 5
|
||||||
// | POSSIBILITY OF SUCH DAMAGE. |
|
*
|
||||||
// +----------------------------------------------------------------------+
|
* @category Database
|
||||||
// | Author: David Coallier <davidc@php.net> |
|
* @package MDB2_Schema
|
||||||
// +----------------------------------------------------------------------+
|
* @author David Coallier <davidc@php.net>
|
||||||
// }}}
|
* @license BSD http://www.opensource.org/licenses/bsd-license.php
|
||||||
|
* @version SVN: $Id$
|
||||||
|
* @link http://pear.php.net/packages/MDB2_Schema
|
||||||
|
*/
|
||||||
|
|
||||||
// {{{ $GLOBALS['_MDB2_Schema_Reserved']['mssql']
|
// {{{ $GLOBALS['_MDB2_Schema_Reserved']['mssql']
|
||||||
/**
|
/**
|
||||||
* Has a list of all the reserved words for mssql.
|
* Has a list of all the reserved words for mssql.
|
||||||
|
@ -254,5 +258,3 @@ $GLOBALS['_MDB2_Schema_Reserved']['mssql'] = array(
|
||||||
'SELECT',
|
'SELECT',
|
||||||
);
|
);
|
||||||
//}}}
|
//}}}
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
|
@ -1,50 +1,52 @@
|
||||||
<?php
|
<?php /* vim: se et ts=4 sw=4 sts=4 fdm=marker tw=80: */
|
||||||
// {{{ Disclaimer, Licence, copyrights
|
/**
|
||||||
// +----------------------------------------------------------------------+
|
* Copyright (c) 1998-2010 Manuel Lemos, Tomas V.V.Cox,
|
||||||
// | PHP versions 4 and 5 |
|
* Stig. S. Bakken, Lukas Smith, Igor Feghali
|
||||||
// +----------------------------------------------------------------------+
|
* All rights reserved.
|
||||||
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
|
*
|
||||||
// | Stig. S. Bakken, Lukas Smith |
|
* MDB2_Schema enables users to maintain RDBMS independant schema files
|
||||||
// | All rights reserved. |
|
* in XML that can be used to manipulate both data and database schemas
|
||||||
// +----------------------------------------------------------------------+
|
* This LICENSE is in the BSD license style.
|
||||||
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
|
*
|
||||||
// | API as well as database abstraction for PHP applications. |
|
* Redistribution and use in source and binary forms, with or without
|
||||||
// | This LICENSE is in the BSD license style. |
|
* modification, are permitted provided that the following conditions
|
||||||
// | |
|
* are met:
|
||||||
// | Redistribution and use in source and binary forms, with or without |
|
*
|
||||||
// | modification, are permitted provided that the following conditions |
|
* Redistributions of source code must retain the above copyright
|
||||||
// | are met: |
|
* notice, this list of conditions and the following disclaimer.
|
||||||
// | |
|
*
|
||||||
// | Redistributions of source code must retain the above copyright |
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
// | notice, this list of conditions and the following disclaimer. |
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
// | |
|
* documentation and/or other materials provided with the distribution.
|
||||||
// | Redistributions in binary form must reproduce the above copyright |
|
*
|
||||||
// | notice, this list of conditions and the following disclaimer in the |
|
* Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,
|
||||||
// | documentation and/or other materials provided with the distribution. |
|
* Lukas Smith, Igor Feghali nor the names of his contributors may be
|
||||||
// | |
|
* used to endorse or promote products derived from this software
|
||||||
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
|
* without specific prior written permission.
|
||||||
// | Lukas Smith nor the names of his contributors may be used to endorse |
|
*
|
||||||
// | or promote products derived from this software without specific prior|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
// | written permission. |
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
// | |
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
* REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
|
||||||
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
|
*
|
||||||
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
* PHP version 5
|
||||||
// | POSSIBILITY OF SUCH DAMAGE. |
|
*
|
||||||
// +----------------------------------------------------------------------+
|
* @category Database
|
||||||
// | Author: David Coallier <davidc@php.net> |
|
* @package MDB2_Schema
|
||||||
// +----------------------------------------------------------------------+
|
* @author David Coallier <davidc@php.net>
|
||||||
//
|
* @license BSD http://www.opensource.org/licenses/bsd-license.php
|
||||||
// $Id: mysql.php,v 1.3 2006/03/01 12:16:40 lsmith Exp $
|
* @version SVN: $Id$
|
||||||
// }}}
|
* @link http://pear.php.net/packages/MDB2_Schema
|
||||||
|
*/
|
||||||
|
|
||||||
// {{{ $GLOBALS['_MDB2_Schema_Reserved']['mysql']
|
// {{{ $GLOBALS['_MDB2_Schema_Reserved']['mysql']
|
||||||
/**
|
/**
|
||||||
* Has a list of reserved words of mysql
|
* Has a list of reserved words of mysql
|
||||||
|
@ -281,4 +283,3 @@ $GLOBALS['_MDB2_Schema_Reserved']['mysql'] = array(
|
||||||
'ZEROFILL',
|
'ZEROFILL',
|
||||||
);
|
);
|
||||||
// }}}
|
// }}}
|
||||||
?>
|
|
||||||
|
|
|
@ -1,48 +1,52 @@
|
||||||
<?php
|
<?php /* vim: se et ts=4 sw=4 sts=4 fdm=marker tw=80: */
|
||||||
// {{{ Disclaimer, Licence, copyrights
|
/**
|
||||||
// +----------------------------------------------------------------------+
|
* Copyright (c) 1998-2010 Manuel Lemos, Tomas V.V.Cox,
|
||||||
// | PHP versions 4 and 5 |
|
* Stig. S. Bakken, Lukas Smith, Igor Feghali
|
||||||
// +----------------------------------------------------------------------+
|
* All rights reserved.
|
||||||
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
|
*
|
||||||
// | Stig. S. Bakken, Lukas Smith |
|
* MDB2_Schema enables users to maintain RDBMS independant schema files
|
||||||
// | All rights reserved. |
|
* in XML that can be used to manipulate both data and database schemas
|
||||||
// +----------------------------------------------------------------------+
|
* This LICENSE is in the BSD license style.
|
||||||
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
|
*
|
||||||
// | API as well as database abstraction for PHP applications. |
|
* Redistribution and use in source and binary forms, with or without
|
||||||
// | This LICENSE is in the BSD license style. |
|
* modification, are permitted provided that the following conditions
|
||||||
// | |
|
* are met:
|
||||||
// | Redistribution and use in source and binary forms, with or without |
|
*
|
||||||
// | modification, are permitted provided that the following conditions |
|
* Redistributions of source code must retain the above copyright
|
||||||
// | are met: |
|
* notice, this list of conditions and the following disclaimer.
|
||||||
// | |
|
*
|
||||||
// | Redistributions of source code must retain the above copyright |
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
// | notice, this list of conditions and the following disclaimer. |
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
// | |
|
* documentation and/or other materials provided with the distribution.
|
||||||
// | Redistributions in binary form must reproduce the above copyright |
|
*
|
||||||
// | notice, this list of conditions and the following disclaimer in the |
|
* Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,
|
||||||
// | documentation and/or other materials provided with the distribution. |
|
* Lukas Smith, Igor Feghali nor the names of his contributors may be
|
||||||
// | |
|
* used to endorse or promote products derived from this software
|
||||||
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
|
* without specific prior written permission.
|
||||||
// | Lukas Smith nor the names of his contributors may be used to endorse |
|
*
|
||||||
// | or promote products derived from this software without specific prior|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
// | written permission. |
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
// | |
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
* REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
|
||||||
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
|
*
|
||||||
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
* PHP version 5
|
||||||
// | POSSIBILITY OF SUCH DAMAGE. |
|
*
|
||||||
// +----------------------------------------------------------------------+
|
* @category Database
|
||||||
// | Author: David Coallier <davidc@php.net> |
|
* @package MDB2_Schema
|
||||||
// +----------------------------------------------------------------------+
|
* @author David Coallier <davidc@php.net>
|
||||||
// }}}
|
* @license BSD http://www.opensource.org/licenses/bsd-license.php
|
||||||
|
* @version SVN: $Id$
|
||||||
|
* @link http://pear.php.net/packages/MDB2_Schema
|
||||||
|
*/
|
||||||
|
|
||||||
// {{{ $GLOBALS['_MDB2_Schema_Reserved']['oci8']
|
// {{{ $GLOBALS['_MDB2_Schema_Reserved']['oci8']
|
||||||
/**
|
/**
|
||||||
* Has a list of all the reserved words for oracle.
|
* Has a list of all the reserved words for oracle.
|
||||||
|
@ -167,5 +171,3 @@ $GLOBALS['_MDB2_Schema_Reserved']['oci8'] = array(
|
||||||
'WITH',
|
'WITH',
|
||||||
);
|
);
|
||||||
// }}}
|
// }}}
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
|
@ -1,49 +1,52 @@
|
||||||
<?php
|
<?php /* vim: se et ts=4 sw=4 sts=4 fdm=marker tw=80: */
|
||||||
// {{{ Disclaimer, Licence, copyrights
|
/**
|
||||||
// +----------------------------------------------------------------------+
|
* Copyright (c) 1998-2010 Manuel Lemos, Tomas V.V.Cox,
|
||||||
// | PHP versions 4 and 5 |
|
* Stig. S. Bakken, Lukas Smith, Igor Feghali
|
||||||
// +----------------------------------------------------------------------+
|
* All rights reserved.
|
||||||
// | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
|
*
|
||||||
// | Stig. S. Bakken, Lukas Smith |
|
* MDB2_Schema enables users to maintain RDBMS independant schema files
|
||||||
// | All rights reserved. |
|
* in XML that can be used to manipulate both data and database schemas
|
||||||
// +----------------------------------------------------------------------+
|
* This LICENSE is in the BSD license style.
|
||||||
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
|
*
|
||||||
// | API as well as database abstraction for PHP applications. |
|
* Redistribution and use in source and binary forms, with or without
|
||||||
// | This LICENSE is in the BSD license style. |
|
* modification, are permitted provided that the following conditions
|
||||||
// | |
|
* are met:
|
||||||
// | Redistribution and use in source and binary forms, with or without |
|
*
|
||||||
// | modification, are permitted provided that the following conditions |
|
* Redistributions of source code must retain the above copyright
|
||||||
// | are met: |
|
* notice, this list of conditions and the following disclaimer.
|
||||||
// | |
|
*
|
||||||
// | Redistributions of source code must retain the above copyright |
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
// | notice, this list of conditions and the following disclaimer. |
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
// | |
|
* documentation and/or other materials provided with the distribution.
|
||||||
// | Redistributions in binary form must reproduce the above copyright |
|
*
|
||||||
// | notice, this list of conditions and the following disclaimer in the |
|
* Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,
|
||||||
// | documentation and/or other materials provided with the distribution. |
|
* Lukas Smith, Igor Feghali nor the names of his contributors may be
|
||||||
// | |
|
* used to endorse or promote products derived from this software
|
||||||
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
|
* without specific prior written permission.
|
||||||
// | Lukas Smith nor the names of his contributors may be used to endorse |
|
*
|
||||||
// | or promote products derived from this software without specific prior|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
// | written permission. |
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
// | |
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
* REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
|
||||||
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
|
*
|
||||||
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
* PHP version 5
|
||||||
// | POSSIBILITY OF SUCH DAMAGE. |
|
*
|
||||||
// +----------------------------------------------------------------------+
|
* @category Database
|
||||||
// | Author: Marcelo Santos Araujo <msaraujo@php.net> |
|
* @package MDB2_Schema
|
||||||
// +----------------------------------------------------------------------+
|
* @author Marcelo Santos Araujo <msaraujo@php.net>
|
||||||
//
|
* @license BSD http://www.opensource.org/licenses/bsd-license.php
|
||||||
// }}}
|
* @version SVN: $Id$
|
||||||
|
* @link http://pear.php.net/packages/MDB2_Schema
|
||||||
|
*/
|
||||||
|
|
||||||
// {{{ $GLOBALS['_MDB2_Schema_Reserved']['pgsql']
|
// {{{ $GLOBALS['_MDB2_Schema_Reserved']['pgsql']
|
||||||
/**
|
/**
|
||||||
* Has a list of reserved words of pgsql
|
* Has a list of reserved words of pgsql
|
||||||
|
@ -143,5 +146,3 @@ $GLOBALS['_MDB2_Schema_Reserved']['pgsql'] = array(
|
||||||
'WHERE'
|
'WHERE'
|
||||||
);
|
);
|
||||||
// }}}
|
// }}}
|
||||||
?>
|
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
<?php
|
<?php /* vim: se et ts=4 sw=4 sts=4 fdm=marker tw=80: */
|
||||||
/**
|
/**
|
||||||
* PHP versions 4 and 5
|
* Copyright (c) 1998-2010 Manuel Lemos, Tomas V.V.Cox,
|
||||||
*
|
|
||||||
* Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox,
|
|
||||||
* Stig. S. Bakken, Lukas Smith, Igor Feghali
|
* Stig. S. Bakken, Lukas Smith, Igor Feghali
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
|
@ -39,14 +37,13 @@
|
||||||
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* Author: Christian Weiske <cweiske@php.net>
|
* PHP version 5
|
||||||
* $Id: Tool.php,v 1.6 2008/12/13 00:26:07 clockwerx Exp $
|
|
||||||
*
|
*
|
||||||
* @category Database
|
* @category Database
|
||||||
* @package MDB2_Schema
|
* @package MDB2_Schema
|
||||||
* @author Christian Weiske <cweiske@php.net>
|
* @author Christian Weiske <cweiske@php.net>
|
||||||
* @license BSD http://www.opensource.org/licenses/bsd-license.php
|
* @license BSD http://www.opensource.org/licenses/bsd-license.php
|
||||||
* @version CVS: $Id: Tool.php,v 1.6 2008/12/13 00:26:07 clockwerx Exp $
|
* @version SVN: $Id$
|
||||||
* @link http://pear.php.net/packages/MDB2_Schema
|
* @link http://pear.php.net/packages/MDB2_Schema
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -152,7 +149,9 @@ class MDB2_Schema_Tool
|
||||||
case '--init':
|
case '--init':
|
||||||
return 'init';
|
return 'init';
|
||||||
default:
|
default:
|
||||||
throw new MDB2_Schema_Tool_ParameterException("Unknown mode \"$arg\"");
|
throw new MDB2_Schema_Tool_ParameterException(
|
||||||
|
"Unknown mode \"$arg\""
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}//protected function getAction(&$args)
|
}//protected function getAction(&$args)
|
||||||
|
|
||||||
|
@ -179,7 +178,8 @@ class MDB2_Schema_Tool
|
||||||
*/
|
*/
|
||||||
protected function doHelp()
|
protected function doHelp()
|
||||||
{
|
{
|
||||||
self::toStdErr(<<<EOH
|
self::toStdErr(
|
||||||
|
<<<EOH
|
||||||
Usage: mdb2_schematool mode parameters
|
Usage: mdb2_schematool mode parameters
|
||||||
|
|
||||||
Works with database schemas
|
Works with database schemas
|
||||||
|
@ -205,7 +205,8 @@ EOH
|
||||||
*/
|
*/
|
||||||
protected function doHelpDump()
|
protected function doHelpDump()
|
||||||
{
|
{
|
||||||
self::toStdErr( <<<EOH
|
self::toStdErr(
|
||||||
|
<<<EOH
|
||||||
Usage: mdb2_schematool dump [all|data|schema] [-p] DSN
|
Usage: mdb2_schematool dump [all|data|schema] [-p] DSN
|
||||||
|
|
||||||
Dumps a database schema to stdout
|
Dumps a database schema to stdout
|
||||||
|
@ -216,7 +217,8 @@ DSN: Data source name in the form of
|
||||||
driver://user:password@host/database
|
driver://user:password@host/database
|
||||||
|
|
||||||
User and password may be omitted.
|
User and password may be omitted.
|
||||||
Using -p reads password from stdin which is more secure than passing it in the parameter.
|
Using -p reads password from stdin which is more secure than passing it in the
|
||||||
|
parameter.
|
||||||
|
|
||||||
EOH
|
EOH
|
||||||
);
|
);
|
||||||
|
@ -231,7 +233,8 @@ EOH
|
||||||
*/
|
*/
|
||||||
protected function doHelpInit()
|
protected function doHelpInit()
|
||||||
{
|
{
|
||||||
self::toStdErr( <<<EOH
|
self::toStdErr(
|
||||||
|
<<<EOH
|
||||||
Usage: mdb2_schematool init source [-p] destination
|
Usage: mdb2_schematool init source [-p] destination
|
||||||
|
|
||||||
Initializes a database with data
|
Initializes a database with data
|
||||||
|
@ -244,7 +247,8 @@ DSN: Data source name in the form of
|
||||||
driver://user:password@host/database
|
driver://user:password@host/database
|
||||||
|
|
||||||
User and password may be omitted.
|
User and password may be omitted.
|
||||||
Using -p reads password from stdin which is more secure than passing it in the parameter.
|
Using -p reads password from stdin which is more secure than passing it in the
|
||||||
|
parameter.
|
||||||
|
|
||||||
EOH
|
EOH
|
||||||
);
|
);
|
||||||
|
@ -259,7 +263,8 @@ EOH
|
||||||
*/
|
*/
|
||||||
protected function doHelpLoad()
|
protected function doHelpLoad()
|
||||||
{
|
{
|
||||||
self::toStdErr( <<<EOH
|
self::toStdErr(
|
||||||
|
<<<EOH
|
||||||
Usage: mdb2_schematool load [-p] source [-p] destination
|
Usage: mdb2_schematool load [-p] source [-p] destination
|
||||||
|
|
||||||
Loads a database schema from source to destination
|
Loads a database schema from source to destination
|
||||||
|
@ -272,7 +277,8 @@ DSN: Data source name in the form of
|
||||||
driver://user:password@host/database
|
driver://user:password@host/database
|
||||||
|
|
||||||
User and password may be omitted.
|
User and password may be omitted.
|
||||||
Using -p reads password from stdin which is more secure than passing it in the parameter.
|
Using -p reads password from stdin which is more secure than passing it in the
|
||||||
|
parameter.
|
||||||
|
|
||||||
EOH
|
EOH
|
||||||
);
|
);
|
||||||
|
@ -334,7 +340,9 @@ EOH
|
||||||
protected function getFileOrDsn(&$args)
|
protected function getFileOrDsn(&$args)
|
||||||
{
|
{
|
||||||
if (count($args) == 0) {
|
if (count($args) == 0) {
|
||||||
throw new MDB2_Schema_Tool_ParameterException('File or DSN expected');
|
throw new MDB2_Schema_Tool_ParameterException(
|
||||||
|
'File or DSN expected'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$arg = array_shift($args);
|
$arg = array_shift($args);
|
||||||
|
@ -450,7 +458,8 @@ EOH
|
||||||
list($type, $dsn) = $this->getFileOrDsn($args);
|
list($type, $dsn) = $this->getFileOrDsn($args);
|
||||||
if ($type == 'file') {
|
if ($type == 'file') {
|
||||||
throw new MDB2_Schema_Tool_ParameterException(
|
throw new MDB2_Schema_Tool_ParameterException(
|
||||||
'Dumping a schema file as a schema file does not make much sense'
|
'Dumping a schema file as a schema file does not make much ' .
|
||||||
|
'sense'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -503,8 +512,14 @@ EOH
|
||||||
$definition = $schemaDest->parseDatabaseDefinitionFile($dsnSource);
|
$definition = $schemaDest->parseDatabaseDefinitionFile($dsnSource);
|
||||||
$where = 'loading schema file';
|
$where = 'loading schema file';
|
||||||
} else {
|
} else {
|
||||||
$schemaSource = MDB2_Schema::factory($dsnSource, $this->getSchemaOptions());
|
$schemaSource = MDB2_Schema::factory(
|
||||||
$this->throwExceptionOnError($schemaSource, 'connecting to source database');
|
$dsnSource,
|
||||||
|
$this->getSchemaOptions()
|
||||||
|
);
|
||||||
|
$this->throwExceptionOnError(
|
||||||
|
$schemaSource,
|
||||||
|
'connecting to source database'
|
||||||
|
);
|
||||||
|
|
||||||
$definition = $schemaSource->getDefinitionFromDatabase();
|
$definition = $schemaSource->getDefinitionFromDatabase();
|
||||||
$where = 'loading definition from database';
|
$where = 'loading definition from database';
|
||||||
|
@ -514,7 +529,11 @@ EOH
|
||||||
|
|
||||||
//create destination database from definition
|
//create destination database from definition
|
||||||
$simulate = false;
|
$simulate = false;
|
||||||
$op = $schemaDest->createDatabase($definition, array(), $simulate);
|
$op = $schemaDest->createDatabase(
|
||||||
|
$definition,
|
||||||
|
array(),
|
||||||
|
$simulate
|
||||||
|
);
|
||||||
$this->throwExceptionOnError($op, 'creating the database');
|
$this->throwExceptionOnError($op, 'creating the database');
|
||||||
}//protected function doLoad($args)
|
}//protected function doLoad($args)
|
||||||
|
|
||||||
|
@ -545,10 +564,16 @@ EOH
|
||||||
}
|
}
|
||||||
|
|
||||||
$schemaDest = MDB2_Schema::factory($dsnDest, $this->getSchemaOptions());
|
$schemaDest = MDB2_Schema::factory($dsnDest, $this->getSchemaOptions());
|
||||||
$this->throwExceptionOnError($schemaDest, 'connecting to destination database');
|
$this->throwExceptionOnError(
|
||||||
|
$schemaDest,
|
||||||
|
'connecting to destination database'
|
||||||
|
);
|
||||||
|
|
||||||
$definition = $schemaDest->getDefinitionFromDatabase();
|
$definition = $schemaDest->getDefinitionFromDatabase();
|
||||||
$this->throwExceptionOnError($definition, 'loading definition from database');
|
$this->throwExceptionOnError(
|
||||||
|
$definition,
|
||||||
|
'loading definition from database'
|
||||||
|
);
|
||||||
|
|
||||||
$op = $schemaDest->writeInitialization($dsnSource, $definition);
|
$op = $schemaDest->writeInitialization($dsnSource, $definition);
|
||||||
$this->throwExceptionOnError($op, 'initializing database');
|
$this->throwExceptionOnError($op, 'initializing database');
|
||||||
|
@ -556,5 +581,3 @@ EOH
|
||||||
|
|
||||||
|
|
||||||
}//class MDB2_Schema_Tool
|
}//class MDB2_Schema_Tool
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
|
@ -1,6 +1,61 @@
|
||||||
<?php
|
<?php /* vim: se et ts=4 sw=4 sts=4 fdm=marker tw=80: */
|
||||||
|
/**
|
||||||
|
* Copyright (c) 1998-2010 Manuel Lemos, Tomas V.V.Cox,
|
||||||
|
* Stig. S. Bakken, Lukas Smith, Igor Feghali
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* MDB2_Schema enables users to maintain RDBMS independant schema files
|
||||||
|
* in XML that can be used to manipulate both data and database schemas
|
||||||
|
* This LICENSE is in the BSD license style.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,
|
||||||
|
* Lukas Smith, Igor Feghali nor the names of his contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
|
||||||
|
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* PHP version 5
|
||||||
|
*
|
||||||
|
* @category Database
|
||||||
|
* @package MDB2_Schema
|
||||||
|
* @author Christian Weiske <cweiske@php.net>
|
||||||
|
* @license BSD http://www.opensource.org/licenses/bsd-license.php
|
||||||
|
* @version SVN: $Id$
|
||||||
|
* @link http://pear.php.net/packages/MDB2_Schema
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To be implemented yet
|
||||||
|
*
|
||||||
|
* @category Database
|
||||||
|
* @package MDB2_Schema
|
||||||
|
* @author Christian Weiske <cweiske@php.net>
|
||||||
|
* @license BSD http://www.opensource.org/licenses/bsd-license.php
|
||||||
|
* @link http://pear.php.net/packages/MDB2_Schema
|
||||||
|
*/
|
||||||
class MDB2_Schema_Tool_ParameterException extends Exception
|
class MDB2_Schema_Tool_ParameterException extends Exception
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
?>
|
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
<?php
|
<?php /* vim: se et ts=4 sw=4 sts=4 fdm=marker tw=80: */
|
||||||
/**
|
/**
|
||||||
* PHP versions 4 and 5
|
* Copyright (c) 1998-2010 Manuel Lemos, Tomas V.V.Cox,
|
||||||
*
|
|
||||||
* Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox,
|
|
||||||
* Stig. S. Bakken, Lukas Smith, Igor Feghali
|
* Stig. S. Bakken, Lukas Smith, Igor Feghali
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
|
@ -39,15 +37,14 @@
|
||||||
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* Author: Christian Dickmann <dickmann@php.net>
|
* PHP version 5
|
||||||
* Author: Igor Feghali <ifeghali@php.net>
|
|
||||||
*
|
*
|
||||||
* @category Database
|
* @category Database
|
||||||
* @package MDB2_Schema
|
* @package MDB2_Schema
|
||||||
* @author Christian Dickmann <dickmann@php.net>
|
* @author Christian Dickmann <dickmann@php.net>
|
||||||
* @author Igor Feghali <ifeghali@php.net>
|
* @author Igor Feghali <ifeghali@php.net>
|
||||||
* @license BSD http://www.opensource.org/licenses/bsd-license.php
|
* @license BSD http://www.opensource.org/licenses/bsd-license.php
|
||||||
* @version CVS: $Id: Validate.php,v 1.42 2008/11/30 03:34:00 clockwerx Exp $
|
* @version SVN: $Id$
|
||||||
* @link http://pear.php.net/packages/MDB2_Schema
|
* @link http://pear.php.net/packages/MDB2_Schema
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -70,11 +67,30 @@ class MDB2_Schema_Validate
|
||||||
|
|
||||||
var $force_defaults = true;
|
var $force_defaults = true;
|
||||||
|
|
||||||
|
var $max_identifiers_length = null;
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ constructor
|
// {{{ constructor
|
||||||
|
|
||||||
function __construct($fail_on_invalid_names = true, $valid_types = array(), $force_defaults = true)
|
/**
|
||||||
{
|
* PHP 5 constructor
|
||||||
|
*
|
||||||
|
* @param bool $fail_on_invalid_names array with reserved words per RDBMS
|
||||||
|
* @param array $valid_types information of all valid fields
|
||||||
|
* types
|
||||||
|
* @param bool $force_defaults if true sets a default value to
|
||||||
|
* field when not explicit
|
||||||
|
* @param int $max_identifiers_length maximum allowed size for entities
|
||||||
|
* name
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @static
|
||||||
|
*/
|
||||||
|
function __construct($fail_on_invalid_names = true, $valid_types = array(),
|
||||||
|
$force_defaults = true, $max_identifiers_length = null
|
||||||
|
) {
|
||||||
if (empty($GLOBALS['_MDB2_Schema_Reserved'])) {
|
if (empty($GLOBALS['_MDB2_Schema_Reserved'])) {
|
||||||
$GLOBALS['_MDB2_Schema_Reserved'] = array();
|
$GLOBALS['_MDB2_Schema_Reserved'] = array();
|
||||||
}
|
}
|
||||||
|
@ -87,21 +103,49 @@ class MDB2_Schema_Validate
|
||||||
} else {
|
} else {
|
||||||
$this->fail_on_invalid_names = array();
|
$this->fail_on_invalid_names = array();
|
||||||
}
|
}
|
||||||
$this->valid_types = $valid_types;
|
$this->valid_types = $valid_types;
|
||||||
$this->force_defaults = $force_defaults;
|
$this->force_defaults = $force_defaults;
|
||||||
|
$this->max_identifiers_length = $max_identifiers_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
function MDB2_Schema_Validate($fail_on_invalid_names = true, $valid_types = array(), $force_defaults = true)
|
/**
|
||||||
{
|
* PHP 4 compatible constructor
|
||||||
|
*
|
||||||
|
* @param bool $fail_on_invalid_names array with reserved words per RDBMS
|
||||||
|
* @param array $valid_types information of all valid fields
|
||||||
|
* types
|
||||||
|
* @param bool $force_defaults if true sets a default value to
|
||||||
|
* field when not explicit
|
||||||
|
* @param int $max_identifiers_length maximum allowed size for entities
|
||||||
|
* name
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @static
|
||||||
|
*/
|
||||||
|
function MDB2_Schema_Validate($fail_on_invalid_names = true, $valid_types = array(),
|
||||||
|
$force_defaults = true, $max_identifiers_length = null
|
||||||
|
) {
|
||||||
$this->__construct($fail_on_invalid_names, $valid_types, $force_defaults);
|
$this->__construct($fail_on_invalid_names, $valid_types, $force_defaults);
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ raiseError()
|
// {{{ raiseError()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pushes a MDB2_Schema_Error into stack and returns it
|
||||||
|
*
|
||||||
|
* @param int $ecode MDB2_Schema's error code
|
||||||
|
* @param string $msg textual message
|
||||||
|
*
|
||||||
|
* @return object
|
||||||
|
* @access private
|
||||||
|
* @static
|
||||||
|
*/
|
||||||
function &raiseError($ecode, $msg = null)
|
function &raiseError($ecode, $msg = null)
|
||||||
{
|
{
|
||||||
$error =& MDB2_Schema::raiseError($ecode, null, null, $msg);
|
$error = MDB2_Schema::raiseError($ecode, null, null, $msg);
|
||||||
return $error;
|
return $error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,27 +220,18 @@ class MDB2_Schema_Validate
|
||||||
*/
|
*/
|
||||||
function validateTable($tables, &$table, $table_name)
|
function validateTable($tables, &$table, $table_name)
|
||||||
{
|
{
|
||||||
/* Have we got a name? */
|
|
||||||
if (!$table_name) {
|
|
||||||
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
|
|
||||||
'a table has to have a name');
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Table name duplicated? */
|
/* Table name duplicated? */
|
||||||
if (is_array($tables) && isset($tables[$table_name])) {
|
if (is_array($tables) && isset($tables[$table_name])) {
|
||||||
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
|
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
|
||||||
'table "'.$table_name.'" already exists');
|
'table "'.$table_name.'" already exists');
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Table name reserved? */
|
/**
|
||||||
if (is_array($this->fail_on_invalid_names)) {
|
* Valid name ?
|
||||||
$name = strtoupper($table_name);
|
*/
|
||||||
foreach ($this->fail_on_invalid_names as $rdbms) {
|
$result = $this->validateIdentifier($table_name, 'table');
|
||||||
if (in_array($name, $GLOBALS['_MDB2_Schema_Reserved'][$rdbms])) {
|
if (PEAR::isError($result)) {
|
||||||
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
|
return $result;
|
||||||
'table name "'.$table_name.'" is a reserved word in: '.$rdbms);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Was */
|
/* Was */
|
||||||
|
@ -289,10 +324,12 @@ class MDB2_Schema_Validate
|
||||||
*/
|
*/
|
||||||
function validateField($fields, &$field, $field_name)
|
function validateField($fields, &$field, $field_name)
|
||||||
{
|
{
|
||||||
/* Have we got a name? */
|
/**
|
||||||
if (!$field_name) {
|
* Valid name ?
|
||||||
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
|
*/
|
||||||
'field name missing');
|
$result = $this->validateIdentifier($field_name, 'field');
|
||||||
|
if (PEAR::isError($result)) {
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Field name duplicated? */
|
/* Field name duplicated? */
|
||||||
|
@ -301,17 +338,6 @@ class MDB2_Schema_Validate
|
||||||
'field "'.$field_name.'" already exists');
|
'field "'.$field_name.'" already exists');
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Field name reserverd? */
|
|
||||||
if (is_array($this->fail_on_invalid_names)) {
|
|
||||||
$name = strtoupper($field_name);
|
|
||||||
foreach ($this->fail_on_invalid_names as $rdbms) {
|
|
||||||
if (in_array($name, $GLOBALS['_MDB2_Schema_Reserved'][$rdbms])) {
|
|
||||||
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
|
|
||||||
'field name "'.$field_name.'" is a reserved word in: '.$rdbms);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Type check */
|
/* Type check */
|
||||||
if (empty($field['type'])) {
|
if (empty($field['type'])) {
|
||||||
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
|
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
|
||||||
|
@ -422,10 +448,14 @@ class MDB2_Schema_Validate
|
||||||
*/
|
*/
|
||||||
function validateIndex($table_indexes, &$index, $index_name)
|
function validateIndex($table_indexes, &$index, $index_name)
|
||||||
{
|
{
|
||||||
if (!$index_name) {
|
/**
|
||||||
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
|
* Valid name ?
|
||||||
'an index has to have a name');
|
*/
|
||||||
|
$result = $this->validateIdentifier($index_name, 'index');
|
||||||
|
if (PEAR::isError($result)) {
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($table_indexes) && isset($table_indexes[$index_name])) {
|
if (is_array($table_indexes) && isset($table_indexes[$index_name])) {
|
||||||
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
|
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
|
||||||
'index "'.$index_name.'" already exists');
|
'index "'.$index_name.'" already exists');
|
||||||
|
@ -470,14 +500,18 @@ class MDB2_Schema_Validate
|
||||||
*/
|
*/
|
||||||
function validateIndexField($index_fields, &$field, $field_name)
|
function validateIndexField($index_fields, &$field, $field_name)
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Valid name ?
|
||||||
|
*/
|
||||||
|
$result = $this->validateIdentifier($field_name, 'index field');
|
||||||
|
if (PEAR::isError($result)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
if (is_array($index_fields) && isset($index_fields[$field_name])) {
|
if (is_array($index_fields) && isset($index_fields[$field_name])) {
|
||||||
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
|
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
|
||||||
'index field "'.$field_name.'" already exists');
|
'index field "'.$field_name.'" already exists');
|
||||||
}
|
}
|
||||||
if (!$field_name) {
|
|
||||||
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
|
|
||||||
'the index-field-name is required');
|
|
||||||
}
|
|
||||||
if (empty($field['sorting'])) {
|
if (empty($field['sorting'])) {
|
||||||
$field['sorting'] = 'ascending';
|
$field['sorting'] = 'ascending';
|
||||||
} elseif ($field['sorting'] !== 'ascending' && $field['sorting'] !== 'descending') {
|
} elseif ($field['sorting'] !== 'ascending' && $field['sorting'] !== 'descending') {
|
||||||
|
@ -506,10 +540,14 @@ class MDB2_Schema_Validate
|
||||||
*/
|
*/
|
||||||
function validateConstraint($table_constraints, &$constraint, $constraint_name)
|
function validateConstraint($table_constraints, &$constraint, $constraint_name)
|
||||||
{
|
{
|
||||||
if (!$constraint_name) {
|
/**
|
||||||
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
|
* Valid name ?
|
||||||
'a foreign key has to have a name');
|
*/
|
||||||
|
$result = $this->validateIdentifier($constraint_name, 'foreign key');
|
||||||
|
if (PEAR::isError($result)) {
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($table_constraints) && isset($table_constraints[$constraint_name])) {
|
if (is_array($table_constraints) && isset($table_constraints[$constraint_name])) {
|
||||||
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
|
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
|
||||||
'foreign key "'.$constraint_name.'" already exists');
|
'foreign key "'.$constraint_name.'" already exists');
|
||||||
|
@ -555,10 +593,14 @@ class MDB2_Schema_Validate
|
||||||
*/
|
*/
|
||||||
function validateConstraintField($constraint_fields, $field_name)
|
function validateConstraintField($constraint_fields, $field_name)
|
||||||
{
|
{
|
||||||
if (!$field_name) {
|
/**
|
||||||
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
|
* Valid name ?
|
||||||
'empty value for foreign-field');
|
*/
|
||||||
|
$result = $this->validateIdentifier($field_name, 'foreign key field');
|
||||||
|
if (PEAR::isError($result)) {
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($constraint_fields) && isset($constraint_fields[$field_name])) {
|
if (is_array($constraint_fields) && isset($constraint_fields[$field_name])) {
|
||||||
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
|
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
|
||||||
'foreign field "'.$field_name.'" already exists');
|
'foreign field "'.$field_name.'" already exists');
|
||||||
|
@ -582,10 +624,14 @@ class MDB2_Schema_Validate
|
||||||
*/
|
*/
|
||||||
function validateConstraintReferencedField($referenced_fields, $field_name)
|
function validateConstraintReferencedField($referenced_fields, $field_name)
|
||||||
{
|
{
|
||||||
if (!$field_name) {
|
/**
|
||||||
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
|
* Valid name ?
|
||||||
'empty value for referenced foreign-field');
|
*/
|
||||||
|
$result = $this->validateIdentifier($field_name, 'referenced foreign field');
|
||||||
|
if (PEAR::isError($result)) {
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($referenced_fields) && isset($referenced_fields[$field_name])) {
|
if (is_array($referenced_fields) && isset($referenced_fields[$field_name])) {
|
||||||
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
|
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
|
||||||
'foreign field "'.$field_name.'" already referenced');
|
'foreign field "'.$field_name.'" already referenced');
|
||||||
|
@ -612,9 +658,12 @@ class MDB2_Schema_Validate
|
||||||
*/
|
*/
|
||||||
function validateSequence($sequences, &$sequence, $sequence_name)
|
function validateSequence($sequences, &$sequence, $sequence_name)
|
||||||
{
|
{
|
||||||
if (!$sequence_name) {
|
/**
|
||||||
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
|
* Valid name ?
|
||||||
'a sequence has to have a name');
|
*/
|
||||||
|
$result = $this->validateIdentifier($sequence_name, 'sequence');
|
||||||
|
if (PEAR::isError($result)) {
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($sequences) && isset($sequences[$sequence_name])) {
|
if (is_array($sequences) && isset($sequences[$sequence_name])) {
|
||||||
|
@ -661,21 +710,17 @@ class MDB2_Schema_Validate
|
||||||
*/
|
*/
|
||||||
function validateDatabase(&$database)
|
function validateDatabase(&$database)
|
||||||
{
|
{
|
||||||
/* Have we got a name? */
|
if (!is_array($database)) {
|
||||||
if (!is_array($database) || !isset($database['name']) || !$database['name']) {
|
|
||||||
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
|
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
|
||||||
'a database has to have a name');
|
'something wrong went with database definition');
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Database name reserved? */
|
/**
|
||||||
if (is_array($this->fail_on_invalid_names)) {
|
* Valid name ?
|
||||||
$name = strtoupper($database['name']);
|
*/
|
||||||
foreach ($this->fail_on_invalid_names as $rdbms) {
|
$result = $this->validateIdentifier($database['name'], 'database');
|
||||||
if (in_array($name, $GLOBALS['_MDB2_Schema_Reserved'][$rdbms])) {
|
if (PEAR::isError($result)) {
|
||||||
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
|
return $result;
|
||||||
'database name "'.$database['name'].'" is a reserved word in: '.$rdbms);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create */
|
/* Create */
|
||||||
|
@ -798,9 +843,12 @@ class MDB2_Schema_Validate
|
||||||
*/
|
*/
|
||||||
function validateDataField($table_fields, $instruction_fields, &$field)
|
function validateDataField($table_fields, $instruction_fields, &$field)
|
||||||
{
|
{
|
||||||
if (!$field['name']) {
|
/**
|
||||||
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
|
* Valid name ?
|
||||||
'field-name has to be specified');
|
*/
|
||||||
|
$result = $this->validateIdentifier($field['name'], 'field');
|
||||||
|
if (PEAR::isError($result)) {
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($instruction_fields) && isset($instruction_fields[$field['name']])) {
|
if (is_array($instruction_fields) && isset($instruction_fields[$field['name']])) {
|
||||||
|
@ -917,6 +965,62 @@ class MDB2_Schema_Validate
|
||||||
}
|
}
|
||||||
return MDB2_OK;
|
return MDB2_OK;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
// }}}
|
||||||
|
// {{{ validateIdentifier()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether a given identifier is valid for current driver.
|
||||||
|
*
|
||||||
|
* @param string $id identifier to check
|
||||||
|
* @param string $type whether identifier represents a table name, index, etc.
|
||||||
|
*
|
||||||
|
* @return bool|error object
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function validateIdentifier($id, $type)
|
||||||
|
{
|
||||||
|
$max_length = $this->max_identifiers_length;
|
||||||
|
$cur_length = strlen($id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Have we got a name?
|
||||||
|
*/
|
||||||
|
if (!$id) {
|
||||||
|
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
|
||||||
|
"a $type has to have a name");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Supported length ?
|
||||||
|
*/
|
||||||
|
if ($max_length !== null
|
||||||
|
&& $cur_length > $max_length
|
||||||
|
) {
|
||||||
|
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
|
||||||
|
"$type name '$id' is too long for current driver");
|
||||||
|
} elseif ($cur_length > 30) {
|
||||||
|
// FIXME: find a way to issue a warning in MDB2_Schema object
|
||||||
|
/* $this->warnings[] = "$type name '$id' might not be
|
||||||
|
portable to other drivers"; */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reserved ?
|
||||||
|
*/
|
||||||
|
if (is_array($this->fail_on_invalid_names)) {
|
||||||
|
$name = strtoupper($id);
|
||||||
|
foreach ($this->fail_on_invalid_names as $rdbms) {
|
||||||
|
if (in_array($name, $GLOBALS['_MDB2_Schema_Reserved'][$rdbms])) {
|
||||||
|
return $this->raiseError(MDB2_SCHEMA_ERROR_VALIDATE,
|
||||||
|
"$type name '$id' is a reserved word in: $rdbms");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return MDB2_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
<?php
|
<?php /* vim: se et ts=4 sw=4 sts=4 fdm=marker tw=80: */
|
||||||
/**
|
/**
|
||||||
* PHP versions 4 and 5
|
* Copyright (c) 1998-2010 Manuel Lemos, Tomas V.V.Cox,
|
||||||
*
|
|
||||||
* Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox,
|
|
||||||
* Stig. S. Bakken, Lukas Smith, Igor Feghali
|
* Stig. S. Bakken, Lukas Smith, Igor Feghali
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
|
@ -39,15 +37,14 @@
|
||||||
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* Author: Lukas Smith <smith@pooteeweet.org>
|
* PHP version 5
|
||||||
* Author: Igor Feghali <ifeghali@php.net>
|
|
||||||
*
|
*
|
||||||
* @category Database
|
* @category Database
|
||||||
* @package MDB2_Schema
|
* @package MDB2_Schema
|
||||||
* @author Lukas Smith <smith@pooteeweet.org>
|
* @author Lukas Smith <smith@pooteeweet.org>
|
||||||
* @author Igor Feghali <ifeghali@php.net>
|
* @author Igor Feghali <ifeghali@php.net>
|
||||||
* @license BSD http://www.opensource.org/licenses/bsd-license.php
|
* @license BSD http://www.opensource.org/licenses/bsd-license.php
|
||||||
* @version CVS: $Id: Writer.php,v 1.40 2008/11/30 03:34:00 clockwerx Exp $
|
* @version SVN: $Id$
|
||||||
* @link http://pear.php.net/packages/MDB2_Schema
|
* @link http://pear.php.net/packages/MDB2_Schema
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -69,11 +66,33 @@ class MDB2_Schema_Writer
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ constructor
|
// {{{ constructor
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PHP 5 constructor
|
||||||
|
*
|
||||||
|
* @param array $valid_types information of all valid fields
|
||||||
|
* types
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @static
|
||||||
|
*/
|
||||||
function __construct($valid_types = array())
|
function __construct($valid_types = array())
|
||||||
{
|
{
|
||||||
$this->valid_types = $valid_types;
|
$this->valid_types = $valid_types;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PHP 4 compatible constructor
|
||||||
|
*
|
||||||
|
* @param array $valid_types information of all valid fields
|
||||||
|
* types
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @static
|
||||||
|
*/
|
||||||
function MDB2_Schema_Writer($valid_types = array())
|
function MDB2_Schema_Writer($valid_types = array())
|
||||||
{
|
{
|
||||||
$this->__construct($valid_types);
|
$this->__construct($valid_types);
|
||||||
|
@ -87,15 +106,18 @@ class MDB2_Schema_Writer
|
||||||
* callbacks etc. Basically a wrapper for PEAR::raiseError
|
* callbacks etc. Basically a wrapper for PEAR::raiseError
|
||||||
* without the message string.
|
* without the message string.
|
||||||
*
|
*
|
||||||
* @param int|PEAR_Error $code integer error code or and PEAR_Error instance
|
* @param int|PEAR_Error $code integer error code or and PEAR_Error
|
||||||
* @param int $mode error mode, see PEAR_Error docs
|
* instance
|
||||||
* error level (E_USER_NOTICE etc). If error mode is
|
* @param int $mode error mode, see PEAR_Error docs error
|
||||||
* PEAR_ERROR_CALLBACK, this is the callback function,
|
* level (E_USER_NOTICE etc). If error mode
|
||||||
* either as a function name, or as an array of an
|
* is PEAR_ERROR_CALLBACK, this is the
|
||||||
* object and method name. For other error modes this
|
* callback function, either as a function
|
||||||
* parameter is ignored.
|
* name, or as an array of an object and
|
||||||
* @param string $options Extra debug information. Defaults to the last
|
* method name. For other error modes this
|
||||||
* query and native error code.
|
* parameter is ignored.
|
||||||
|
* @param string $options Extra debug information. Defaults to the
|
||||||
|
* last query and native error code.
|
||||||
|
* @param string $userinfo User-friendly error message
|
||||||
*
|
*
|
||||||
* @return object a PEAR error object
|
* @return object a PEAR error object
|
||||||
* @access public
|
* @access public
|
||||||
|
@ -103,7 +125,7 @@ class MDB2_Schema_Writer
|
||||||
*/
|
*/
|
||||||
function &raiseError($code = null, $mode = null, $options = null, $userinfo = null)
|
function &raiseError($code = null, $mode = null, $options = null, $userinfo = null)
|
||||||
{
|
{
|
||||||
$error =& MDB2_Schema::raiseError($code, $mode, $options, $userinfo);
|
$error = MDB2_Schema::raiseError($code, $mode, $options, $userinfo);
|
||||||
return $error;
|
return $error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -578,4 +600,3 @@ class MDB2_Schema_Writer
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
}
|
}
|
||||||
?>
|
|
||||||
|
|
|
@ -247,7 +247,7 @@ class PEAR
|
||||||
* @access public
|
* @access public
|
||||||
* @return bool true if parameter is an error
|
* @return bool true if parameter is an error
|
||||||
*/
|
*/
|
||||||
function isError($data, $code = null)
|
static function isError($data, $code = null)
|
||||||
{
|
{
|
||||||
if (!is_a($data, 'PEAR_Error')) {
|
if (!is_a($data, 'PEAR_Error')) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -469,7 +469,7 @@ class PEAR
|
||||||
* @see PEAR::setErrorHandling
|
* @see PEAR::setErrorHandling
|
||||||
* @since PHP 4.0.5
|
* @since PHP 4.0.5
|
||||||
*/
|
*/
|
||||||
function &raiseError($message = null,
|
static function &raiseError($message = null,
|
||||||
$code = null,
|
$code = null,
|
||||||
$mode = null,
|
$mode = null,
|
||||||
$options = null,
|
$options = null,
|
||||||
|
@ -555,11 +555,11 @@ class PEAR
|
||||||
function &throwError($message = null, $code = null, $userinfo = null)
|
function &throwError($message = null, $code = null, $userinfo = null)
|
||||||
{
|
{
|
||||||
if (isset($this) && is_a($this, 'PEAR')) {
|
if (isset($this) && is_a($this, 'PEAR')) {
|
||||||
$a = &$this->raiseError($message, $code, null, null, $userinfo);
|
$a = $this->raiseError($message, $code, null, null, $userinfo);
|
||||||
return $a;
|
return $a;
|
||||||
}
|
}
|
||||||
|
|
||||||
$a = &PEAR::raiseError($message, $code, null, null, $userinfo);
|
$a = PEAR::raiseError($message, $code, null, null, $userinfo);
|
||||||
return $a;
|
return $a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -695,7 +695,7 @@ class PEAR
|
||||||
* @param string $ext The extension name
|
* @param string $ext The extension name
|
||||||
* @return bool Success or not on the dl() call
|
* @return bool Success or not on the dl() call
|
||||||
*/
|
*/
|
||||||
function loadExtension($ext)
|
static function loadExtension($ext)
|
||||||
{
|
{
|
||||||
if (extension_loaded($ext)) {
|
if (extension_loaded($ext)) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -144,7 +144,7 @@ class PEAR_Autoloader extends PEAR
|
||||||
$include_file = preg_replace('/[^a-z0-9]/i', '_', $classname);
|
$include_file = preg_replace('/[^a-z0-9]/i', '_', $classname);
|
||||||
include_once $include_file;
|
include_once $include_file;
|
||||||
}
|
}
|
||||||
$obj =& new $classname;
|
$obj = new $classname;
|
||||||
$methods = get_class_methods($classname);
|
$methods = get_class_methods($classname);
|
||||||
foreach ($methods as $method) {
|
foreach ($methods as $method) {
|
||||||
// don't import priviate methods and constructors
|
// don't import priviate methods and constructors
|
||||||
|
|
|
@ -133,8 +133,8 @@ class PEAR_Command
|
||||||
$a = PEAR::raiseError("unknown command `$command'");
|
$a = PEAR::raiseError("unknown command `$command'");
|
||||||
return $a;
|
return $a;
|
||||||
}
|
}
|
||||||
$ui =& PEAR_Command::getFrontendObject();
|
$ui = PEAR_Command::getFrontendObject();
|
||||||
$obj = &new $class($ui, $config);
|
$obj = new $class($ui, $config);
|
||||||
return $obj;
|
return $obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ class PEAR_Command
|
||||||
if (!class_exists($class)) {
|
if (!class_exists($class)) {
|
||||||
return PEAR::raiseError("unknown command `$command'");
|
return PEAR::raiseError("unknown command `$command'");
|
||||||
}
|
}
|
||||||
$ui =& PEAR_Command::getFrontendObject();
|
$ui = PEAR_Command::getFrontendObject();
|
||||||
$config = &PEAR_Config::singleton();
|
$config = &PEAR_Config::singleton();
|
||||||
$obj = &new $class($ui, $config);
|
$obj = &new $class($ui, $config);
|
||||||
return $obj;
|
return $obj;
|
||||||
|
|
|
@ -168,7 +168,7 @@ class PEAR_Common extends PEAR
|
||||||
function PEAR_Common()
|
function PEAR_Common()
|
||||||
{
|
{
|
||||||
parent::PEAR();
|
parent::PEAR();
|
||||||
$this->config = &PEAR_Config::singleton();
|
$this->config = PEAR_Config::singleton();
|
||||||
$this->debug = $this->config->get('verbose');
|
$this->debug = $this->config->get('verbose');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -109,7 +109,7 @@ class PEAR_PackageFile_Generator_v1
|
||||||
// }}}
|
// }}}
|
||||||
$packagexml = $this->toPackageFile($where, PEAR_VALIDATE_PACKAGING, 'package.xml', true);
|
$packagexml = $this->toPackageFile($where, PEAR_VALIDATE_PACKAGING, 'package.xml', true);
|
||||||
if ($packagexml) {
|
if ($packagexml) {
|
||||||
$tar =& new Archive_Tar($dest_package, $compress);
|
$tar = new Archive_Tar($dest_package, $compress);
|
||||||
$tar->setErrorHandling(PEAR_ERROR_RETURN); // XXX Don't print errors
|
$tar->setErrorHandling(PEAR_ERROR_RETURN); // XXX Don't print errors
|
||||||
// ----- Creates with the package.xml file
|
// ----- Creates with the package.xml file
|
||||||
$ok = $tar->createModify(array($packagexml), '', $where);
|
$ok = $tar->createModify(array($packagexml), '', $where);
|
||||||
|
|
|
@ -269,7 +269,7 @@ http://pear.php.net/dtd/package-2.0.xsd',
|
||||||
$name = $pf1 !== null ? 'package2.xml' : 'package.xml';
|
$name = $pf1 !== null ? 'package2.xml' : 'package.xml';
|
||||||
$packagexml = $this->toPackageFile($where, PEAR_VALIDATE_PACKAGING, $name);
|
$packagexml = $this->toPackageFile($where, PEAR_VALIDATE_PACKAGING, $name);
|
||||||
if ($packagexml) {
|
if ($packagexml) {
|
||||||
$tar =& new Archive_Tar($dest_package, $compress);
|
$tar = new Archive_Tar($dest_package, $compress);
|
||||||
$tar->setErrorHandling(PEAR_ERROR_RETURN); // XXX Don't print errors
|
$tar->setErrorHandling(PEAR_ERROR_RETURN); // XXX Don't print errors
|
||||||
// ----- Creates with the package.xml file
|
// ----- Creates with the package.xml file
|
||||||
$ok = $tar->createModify(array($packagexml), '', $where);
|
$ok = $tar->createModify(array($packagexml), '', $where);
|
||||||
|
|
|
@ -191,26 +191,6 @@ class XML_Parser extends PEAR
|
||||||
*/
|
*/
|
||||||
var $_validEncodings = array('ISO-8859-1', 'UTF-8', 'US-ASCII');
|
var $_validEncodings = array('ISO-8859-1', 'UTF-8', 'US-ASCII');
|
||||||
|
|
||||||
// }}}
|
|
||||||
// {{{ php4 constructor
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an XML parser.
|
|
||||||
*
|
|
||||||
* This is needed for PHP4 compatibility, it will
|
|
||||||
* call the constructor, when a new instance is created.
|
|
||||||
*
|
|
||||||
* @param string $srcenc source charset encoding, use NULL (default) to use
|
|
||||||
* whatever the document specifies
|
|
||||||
* @param string $mode how this parser object should work, "event" for
|
|
||||||
* startelement/endelement-type events, "func"
|
|
||||||
* to have it call functions named after elements
|
|
||||||
* @param string $tgtenc a valid target encoding
|
|
||||||
*/
|
|
||||||
function XML_Parser($srcenc = null, $mode = 'event', $tgtenc = null)
|
|
||||||
{
|
|
||||||
XML_Parser::__construct($srcenc, $mode, $tgtenc);
|
|
||||||
}
|
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ php5 constructor
|
// {{{ php5 constructor
|
||||||
|
|
||||||
|
@ -364,7 +344,7 @@ class XML_Parser extends PEAR
|
||||||
}
|
}
|
||||||
$this->parser = $xp;
|
$this->parser = $xp;
|
||||||
$result = $this->_initHandlers($this->mode);
|
$result = $this->_initHandlers($this->mode);
|
||||||
if ($this->isError($result)) {
|
if (PEAR::isError($result)) {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
xml_parser_set_option($xp, XML_OPTION_CASE_FOLDING, $this->folding);
|
xml_parser_set_option($xp, XML_OPTION_CASE_FOLDING, $this->folding);
|
||||||
|
@ -393,7 +373,7 @@ class XML_Parser extends PEAR
|
||||||
function reset()
|
function reset()
|
||||||
{
|
{
|
||||||
$result = $this->_create();
|
$result = $this->_create();
|
||||||
if ($this->isError($result)) {
|
if (PEAR::isError($result)) {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -505,7 +485,7 @@ class XML_Parser extends PEAR
|
||||||
* reset the parser
|
* reset the parser
|
||||||
*/
|
*/
|
||||||
$result = $this->reset();
|
$result = $this->reset();
|
||||||
if ($this->isError($result)) {
|
if (PEAR::isError($result)) {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
// if $this->fp was fopened previously
|
// if $this->fp was fopened previously
|
||||||
|
@ -610,10 +590,16 @@ class XML_Parser extends PEAR
|
||||||
*
|
*
|
||||||
* @return XML_Parser_Error reference to the error object
|
* @return XML_Parser_Error reference to the error object
|
||||||
**/
|
**/
|
||||||
function &raiseError($msg = null, $ecode = 0)
|
static function &raiseError($message = null,
|
||||||
|
$code = 0,
|
||||||
|
$mode = null,
|
||||||
|
$options = null,
|
||||||
|
$userinfo = null,
|
||||||
|
$error_class = null,
|
||||||
|
$skipmsg = false)
|
||||||
{
|
{
|
||||||
$msg = !is_null($msg) ? $msg : $this->parser;
|
$msg = !is_null($msg) ? $msg : $this->parser;
|
||||||
$err = &new XML_Parser_Error($msg, $ecode);
|
$err = new XML_Parser_Error($msg, $ecode);
|
||||||
return parent::raiseError($err);
|
return parent::raiseError($err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,50 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: adapter_test.php 1748 2008-04-14 01:50:41Z lastcraft $
|
|
||||||
require_once(dirname(__FILE__) . '/../autorun.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../extensions/pear_test_case.php');
|
|
||||||
|
|
||||||
class SameTestClass {
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfPearAdapter extends PHPUnit_TestCase {
|
|
||||||
|
|
||||||
function testBoolean() {
|
|
||||||
$this->assertTrue(true, "PEAR true");
|
|
||||||
$this->assertFalse(false, "PEAR false");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testName() {
|
|
||||||
$this->assertTrue($this->getName() == get_class($this));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testPass() {
|
|
||||||
$this->pass("PEAR pass");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testNulls() {
|
|
||||||
$value = null;
|
|
||||||
$this->assertNull($value, "PEAR null");
|
|
||||||
$value = 0;
|
|
||||||
$this->assertNotNull($value, "PEAR not null");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testType() {
|
|
||||||
$this->assertType("Hello", "string", "PEAR type");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testEquals() {
|
|
||||||
$this->assertEquals(12, 12, "PEAR identity");
|
|
||||||
$this->setLooselyTyped(true);
|
|
||||||
$this->assertEquals("12", 12, "PEAR equality");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSame() {
|
|
||||||
$same = new SameTestClass();
|
|
||||||
$this->assertSame($same, $same, "PEAR same");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testRegExp() {
|
|
||||||
$this->assertRegExp('/hello/', "A big hello from me", "PEAR regex");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,13 +0,0 @@
|
||||||
<?php
|
|
||||||
require_once(dirname(__FILE__) . '/../autorun.php');
|
|
||||||
|
|
||||||
class AllTests extends TestSuite {
|
|
||||||
function AllTests() {
|
|
||||||
$this->TestSuite('All tests for SimpleTest ' . SimpleTest::getVersion());
|
|
||||||
$this->addFile(dirname(__FILE__) . '/unit_tests.php');
|
|
||||||
$this->addFile(dirname(__FILE__) . '/shell_test.php');
|
|
||||||
$this->addFile(dirname(__FILE__) . '/live_test.php');
|
|
||||||
$this->addFile(dirname(__FILE__) . '/acceptance_test.php');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,82 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: cookies_test.php 1506 2007-05-07 00:58:03Z lastcraft $
|
|
||||||
require_once(dirname(__FILE__) . '/../autorun.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../arguments.php');
|
|
||||||
|
|
||||||
class TestOfCommandLineArgumentParsing extends UnitTestCase {
|
|
||||||
function testArgumentListWithJustProgramNameGivesFalseToEveryName() {
|
|
||||||
$arguments = new SimpleArguments(array('me'));
|
|
||||||
$this->assertIdentical($arguments->a, false);
|
|
||||||
$this->assertIdentical($arguments->all(), array());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSingleArgumentNameRecordedAsTrue() {
|
|
||||||
$arguments = new SimpleArguments(array('me', '-a'));
|
|
||||||
$this->assertIdentical($arguments->a, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSingleArgumentCanBeGivenAValue() {
|
|
||||||
$arguments = new SimpleArguments(array('me', '-a=AAA'));
|
|
||||||
$this->assertIdentical($arguments->a, 'AAA');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSingleArgumentCanBeGivenSpaceSeparatedValue() {
|
|
||||||
$arguments = new SimpleArguments(array('me', '-a', 'AAA'));
|
|
||||||
$this->assertIdentical($arguments->a, 'AAA');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testWillBuildArrayFromRepeatedValue() {
|
|
||||||
$arguments = new SimpleArguments(array('me', '-a', 'A', '-a', 'AA'));
|
|
||||||
$this->assertIdentical($arguments->a, array('A', 'AA'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testWillBuildArrayFromMultiplyRepeatedValues() {
|
|
||||||
$arguments = new SimpleArguments(array('me', '-a', 'A', '-a', 'AA', '-a', 'AAA'));
|
|
||||||
$this->assertIdentical($arguments->a, array('A', 'AA', 'AAA'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanParseLongFormArguments() {
|
|
||||||
$arguments = new SimpleArguments(array('me', '--aa=AA', '--bb', 'BB'));
|
|
||||||
$this->assertIdentical($arguments->aa, 'AA');
|
|
||||||
$this->assertIdentical($arguments->bb, 'BB');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testGetsFullSetOfResultsAsHash() {
|
|
||||||
$arguments = new SimpleArguments(array('me', '-a', '-b=1', '-b', '2', '--aa=AA', '--bb', 'BB', '-c'));
|
|
||||||
$this->assertEqual($arguments->all(),
|
|
||||||
array('a' => true, 'b' => array('1', '2'), 'aa' => 'AA', 'bb' => 'BB', 'c' => true));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfHelpOutput extends UnitTestCase {
|
|
||||||
function testDisplaysGeneralHelpBanner() {
|
|
||||||
$help = new SimpleHelp('Cool program');
|
|
||||||
$this->assertEqual($help->render(), "Cool program\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testDisplaysOnlySingleLineEndings() {
|
|
||||||
$help = new SimpleHelp("Cool program\n");
|
|
||||||
$this->assertEqual($help->render(), "Cool program\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testDisplaysHelpOnShortFlag() {
|
|
||||||
$help = new SimpleHelp('Cool program');
|
|
||||||
$help->explainFlag('a', 'Enables A');
|
|
||||||
$this->assertEqual($help->render(), "Cool program\n-a Enables A\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testHasAtleastFourSpacesAfterLongestFlag() {
|
|
||||||
$help = new SimpleHelp('Cool program');
|
|
||||||
$help->explainFlag('a', 'Enables A');
|
|
||||||
$help->explainFlag('long', 'Enables Long');
|
|
||||||
$this->assertEqual($help->render(),
|
|
||||||
"Cool program\n-a Enables A\n--long Enables Long\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanDisplaysMultipleFlagsForEachOption() {
|
|
||||||
$help = new SimpleHelp('Cool program');
|
|
||||||
$help->explainFlag(array('a', 'aa'), 'Enables A');
|
|
||||||
$this->assertEqual($help->render(), "Cool program\n-a Enables A\n --aa\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,145 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: authentication_test.php 1748 2008-04-14 01:50:41Z lastcraft $
|
|
||||||
require_once(dirname(__FILE__) . '/../autorun.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../authentication.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../http.php');
|
|
||||||
Mock::generate('SimpleHttpRequest');
|
|
||||||
|
|
||||||
class TestOfRealm extends UnitTestCase {
|
|
||||||
|
|
||||||
function testWithinSameUrl() {
|
|
||||||
$realm = new SimpleRealm(
|
|
||||||
'Basic',
|
|
||||||
new SimpleUrl('http://www.here.com/path/hello.html'));
|
|
||||||
$this->assertTrue($realm->isWithin(
|
|
||||||
new SimpleUrl('http://www.here.com/path/hello.html')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testInsideWithLongerUrl() {
|
|
||||||
$realm = new SimpleRealm(
|
|
||||||
'Basic',
|
|
||||||
new SimpleUrl('http://www.here.com/path/'));
|
|
||||||
$this->assertTrue($realm->isWithin(
|
|
||||||
new SimpleUrl('http://www.here.com/path/hello.html')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testBelowRootIsOutside() {
|
|
||||||
$realm = new SimpleRealm(
|
|
||||||
'Basic',
|
|
||||||
new SimpleUrl('http://www.here.com/path/'));
|
|
||||||
$this->assertTrue($realm->isWithin(
|
|
||||||
new SimpleUrl('http://www.here.com/path/more/hello.html')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testOldNetscapeDefinitionIsOutside() {
|
|
||||||
$realm = new SimpleRealm(
|
|
||||||
'Basic',
|
|
||||||
new SimpleUrl('http://www.here.com/path/'));
|
|
||||||
$this->assertFalse($realm->isWithin(
|
|
||||||
new SimpleUrl('http://www.here.com/pathmore/hello.html')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testInsideWithMissingTrailingSlash() {
|
|
||||||
$realm = new SimpleRealm(
|
|
||||||
'Basic',
|
|
||||||
new SimpleUrl('http://www.here.com/path/'));
|
|
||||||
$this->assertTrue($realm->isWithin(
|
|
||||||
new SimpleUrl('http://www.here.com/path')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testDifferentPageNameStillInside() {
|
|
||||||
$realm = new SimpleRealm(
|
|
||||||
'Basic',
|
|
||||||
new SimpleUrl('http://www.here.com/path/hello.html'));
|
|
||||||
$this->assertTrue($realm->isWithin(
|
|
||||||
new SimpleUrl('http://www.here.com/path/goodbye.html')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testNewUrlInSameDirectoryDoesNotChangeRealm() {
|
|
||||||
$realm = new SimpleRealm(
|
|
||||||
'Basic',
|
|
||||||
new SimpleUrl('http://www.here.com/path/hello.html'));
|
|
||||||
$realm->stretch(new SimpleUrl('http://www.here.com/path/goodbye.html'));
|
|
||||||
$this->assertTrue($realm->isWithin(
|
|
||||||
new SimpleUrl('http://www.here.com/path/index.html')));
|
|
||||||
$this->assertFalse($realm->isWithin(
|
|
||||||
new SimpleUrl('http://www.here.com/index.html')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testNewUrlMakesRealmTheCommonPath() {
|
|
||||||
$realm = new SimpleRealm(
|
|
||||||
'Basic',
|
|
||||||
new SimpleUrl('http://www.here.com/path/here/hello.html'));
|
|
||||||
$realm->stretch(new SimpleUrl('http://www.here.com/path/there/goodbye.html'));
|
|
||||||
$this->assertTrue($realm->isWithin(
|
|
||||||
new SimpleUrl('http://www.here.com/path/here/index.html')));
|
|
||||||
$this->assertTrue($realm->isWithin(
|
|
||||||
new SimpleUrl('http://www.here.com/path/there/index.html')));
|
|
||||||
$this->assertTrue($realm->isWithin(
|
|
||||||
new SimpleUrl('http://www.here.com/path/index.html')));
|
|
||||||
$this->assertFalse($realm->isWithin(
|
|
||||||
new SimpleUrl('http://www.here.com/index.html')));
|
|
||||||
$this->assertFalse($realm->isWithin(
|
|
||||||
new SimpleUrl('http://www.here.com/paths/index.html')));
|
|
||||||
$this->assertFalse($realm->isWithin(
|
|
||||||
new SimpleUrl('http://www.here.com/pathindex.html')));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfAuthenticator extends UnitTestCase {
|
|
||||||
|
|
||||||
function testNoRealms() {
|
|
||||||
$request = new MockSimpleHttpRequest();
|
|
||||||
$request->expectNever('addHeaderLine');
|
|
||||||
$authenticator = new SimpleAuthenticator();
|
|
||||||
$authenticator->addHeaders($request, new SimpleUrl('http://here.com/'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function &createSingleRealm() {
|
|
||||||
$authenticator = new SimpleAuthenticator();
|
|
||||||
$authenticator->addRealm(
|
|
||||||
new SimpleUrl('http://www.here.com/path/hello.html'),
|
|
||||||
'Basic',
|
|
||||||
'Sanctuary');
|
|
||||||
$authenticator->setIdentityForRealm('www.here.com', 'Sanctuary', 'test', 'secret');
|
|
||||||
return $authenticator;
|
|
||||||
}
|
|
||||||
|
|
||||||
function testOutsideRealm() {
|
|
||||||
$request = new MockSimpleHttpRequest();
|
|
||||||
$request->expectNever('addHeaderLine');
|
|
||||||
$authenticator = &$this->createSingleRealm();
|
|
||||||
$authenticator->addHeaders(
|
|
||||||
$request,
|
|
||||||
new SimpleUrl('http://www.here.com/hello.html'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testWithinRealm() {
|
|
||||||
$request = new MockSimpleHttpRequest();
|
|
||||||
$request->expectOnce('addHeaderLine');
|
|
||||||
$authenticator = &$this->createSingleRealm();
|
|
||||||
$authenticator->addHeaders(
|
|
||||||
$request,
|
|
||||||
new SimpleUrl('http://www.here.com/path/more/hello.html'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testRestartingClearsRealm() {
|
|
||||||
$request = new MockSimpleHttpRequest();
|
|
||||||
$request->expectNever('addHeaderLine');
|
|
||||||
$authenticator = &$this->createSingleRealm();
|
|
||||||
$authenticator->restartSession();
|
|
||||||
$authenticator->addHeaders(
|
|
||||||
$request,
|
|
||||||
new SimpleUrl('http://www.here.com/hello.html'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testDifferentHostIsOutsideRealm() {
|
|
||||||
$request = new MockSimpleHttpRequest();
|
|
||||||
$request->expectNever('addHeaderLine');
|
|
||||||
$authenticator = &$this->createSingleRealm();
|
|
||||||
$authenticator->addHeaders(
|
|
||||||
$request,
|
|
||||||
new SimpleUrl('http://here.com/path/hello.html'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,23 +0,0 @@
|
||||||
<?php
|
|
||||||
require_once(dirname(__FILE__) . '/../autorun.php');
|
|
||||||
require_once(dirname(__FILE__) . '/support/test1.php');
|
|
||||||
|
|
||||||
class TestOfAutorun extends UnitTestCase {
|
|
||||||
function testLoadIfIncluded() {
|
|
||||||
$tests = new TestSuite();
|
|
||||||
$tests->addFile(dirname(__FILE__) . '/support/test1.php');
|
|
||||||
$this->assertEqual($tests->getSize(), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testExitStatusOneIfTestsFail() {
|
|
||||||
exec('php ' . dirname(__FILE__) . '/support/failing_test.php', $output, $exit_status);
|
|
||||||
$this->assertEqual($exit_status, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testExitStatusZeroIfTestsPass() {
|
|
||||||
exec('php ' . dirname(__FILE__) . '/support/passing_test.php', $output, $exit_status);
|
|
||||||
$this->assertEqual($exit_status, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
|
@ -1,10 +0,0 @@
|
||||||
<?php
|
|
||||||
require_once(dirname(__FILE__) . '/../autorun.php');
|
|
||||||
|
|
||||||
class BadTestCases extends TestSuite {
|
|
||||||
function BadTestCases() {
|
|
||||||
$this->TestSuite('Two bad test cases');
|
|
||||||
$this->addFile(dirname(__FILE__) . '/support/empty_test_file.php');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,802 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: browser_test.php 1964 2009-10-13 15:27:31Z maetl_ $
|
|
||||||
require_once(dirname(__FILE__) . '/../autorun.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../browser.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../user_agent.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../http.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../page.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../encoding.php');
|
|
||||||
|
|
||||||
Mock::generate('SimpleHttpResponse');
|
|
||||||
Mock::generate('SimplePage');
|
|
||||||
Mock::generate('SimpleForm');
|
|
||||||
Mock::generate('SimpleUserAgent');
|
|
||||||
Mock::generatePartial(
|
|
||||||
'SimpleBrowser',
|
|
||||||
'MockParseSimpleBrowser',
|
|
||||||
array('createUserAgent', 'parse'));
|
|
||||||
Mock::generatePartial(
|
|
||||||
'SimpleBrowser',
|
|
||||||
'MockUserAgentSimpleBrowser',
|
|
||||||
array('createUserAgent'));
|
|
||||||
|
|
||||||
class TestOfHistory extends UnitTestCase {
|
|
||||||
|
|
||||||
function testEmptyHistoryHasFalseContents() {
|
|
||||||
$history = new SimpleBrowserHistory();
|
|
||||||
$this->assertIdentical($history->getUrl(), false);
|
|
||||||
$this->assertIdentical($history->getParameters(), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCannotMoveInEmptyHistory() {
|
|
||||||
$history = new SimpleBrowserHistory();
|
|
||||||
$this->assertFalse($history->back());
|
|
||||||
$this->assertFalse($history->forward());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCurrentTargetAccessors() {
|
|
||||||
$history = new SimpleBrowserHistory();
|
|
||||||
$history->recordEntry(
|
|
||||||
new SimpleUrl('http://www.here.com/'),
|
|
||||||
new SimpleGetEncoding());
|
|
||||||
$this->assertIdentical($history->getUrl(), new SimpleUrl('http://www.here.com/'));
|
|
||||||
$this->assertIdentical($history->getParameters(), new SimpleGetEncoding());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSecondEntryAccessors() {
|
|
||||||
$history = new SimpleBrowserHistory();
|
|
||||||
$history->recordEntry(
|
|
||||||
new SimpleUrl('http://www.first.com/'),
|
|
||||||
new SimpleGetEncoding());
|
|
||||||
$history->recordEntry(
|
|
||||||
new SimpleUrl('http://www.second.com/'),
|
|
||||||
new SimplePostEncoding(array('a' => 1)));
|
|
||||||
$this->assertIdentical($history->getUrl(), new SimpleUrl('http://www.second.com/'));
|
|
||||||
$this->assertIdentical(
|
|
||||||
$history->getParameters(),
|
|
||||||
new SimplePostEncoding(array('a' => 1)));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testGoingBackwards() {
|
|
||||||
$history = new SimpleBrowserHistory();
|
|
||||||
$history->recordEntry(
|
|
||||||
new SimpleUrl('http://www.first.com/'),
|
|
||||||
new SimpleGetEncoding());
|
|
||||||
$history->recordEntry(
|
|
||||||
new SimpleUrl('http://www.second.com/'),
|
|
||||||
new SimplePostEncoding(array('a' => 1)));
|
|
||||||
$this->assertTrue($history->back());
|
|
||||||
$this->assertIdentical($history->getUrl(), new SimpleUrl('http://www.first.com/'));
|
|
||||||
$this->assertIdentical($history->getParameters(), new SimpleGetEncoding());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testGoingBackwardsOffBeginning() {
|
|
||||||
$history = new SimpleBrowserHistory();
|
|
||||||
$history->recordEntry(
|
|
||||||
new SimpleUrl('http://www.first.com/'),
|
|
||||||
new SimpleGetEncoding());
|
|
||||||
$this->assertFalse($history->back());
|
|
||||||
$this->assertIdentical($history->getUrl(), new SimpleUrl('http://www.first.com/'));
|
|
||||||
$this->assertIdentical($history->getParameters(), new SimpleGetEncoding());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testGoingForwardsOffEnd() {
|
|
||||||
$history = new SimpleBrowserHistory();
|
|
||||||
$history->recordEntry(
|
|
||||||
new SimpleUrl('http://www.first.com/'),
|
|
||||||
new SimpleGetEncoding());
|
|
||||||
$this->assertFalse($history->forward());
|
|
||||||
$this->assertIdentical($history->getUrl(), new SimpleUrl('http://www.first.com/'));
|
|
||||||
$this->assertIdentical($history->getParameters(), new SimpleGetEncoding());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testGoingBackwardsAndForwards() {
|
|
||||||
$history = new SimpleBrowserHistory();
|
|
||||||
$history->recordEntry(
|
|
||||||
new SimpleUrl('http://www.first.com/'),
|
|
||||||
new SimpleGetEncoding());
|
|
||||||
$history->recordEntry(
|
|
||||||
new SimpleUrl('http://www.second.com/'),
|
|
||||||
new SimplePostEncoding(array('a' => 1)));
|
|
||||||
$this->assertTrue($history->back());
|
|
||||||
$this->assertTrue($history->forward());
|
|
||||||
$this->assertIdentical($history->getUrl(), new SimpleUrl('http://www.second.com/'));
|
|
||||||
$this->assertIdentical(
|
|
||||||
$history->getParameters(),
|
|
||||||
new SimplePostEncoding(array('a' => 1)));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testNewEntryReplacesNextOne() {
|
|
||||||
$history = new SimpleBrowserHistory();
|
|
||||||
$history->recordEntry(
|
|
||||||
new SimpleUrl('http://www.first.com/'),
|
|
||||||
new SimpleGetEncoding());
|
|
||||||
$history->recordEntry(
|
|
||||||
new SimpleUrl('http://www.second.com/'),
|
|
||||||
new SimplePostEncoding(array('a' => 1)));
|
|
||||||
$history->back();
|
|
||||||
$history->recordEntry(
|
|
||||||
new SimpleUrl('http://www.third.com/'),
|
|
||||||
new SimpleGetEncoding());
|
|
||||||
$this->assertIdentical($history->getUrl(), new SimpleUrl('http://www.third.com/'));
|
|
||||||
$this->assertIdentical($history->getParameters(), new SimpleGetEncoding());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testNewEntryDropsFutureEntries() {
|
|
||||||
$history = new SimpleBrowserHistory();
|
|
||||||
$history->recordEntry(
|
|
||||||
new SimpleUrl('http://www.first.com/'),
|
|
||||||
new SimpleGetEncoding());
|
|
||||||
$history->recordEntry(
|
|
||||||
new SimpleUrl('http://www.second.com/'),
|
|
||||||
new SimpleGetEncoding());
|
|
||||||
$history->recordEntry(
|
|
||||||
new SimpleUrl('http://www.third.com/'),
|
|
||||||
new SimpleGetEncoding());
|
|
||||||
$history->back();
|
|
||||||
$history->back();
|
|
||||||
$history->recordEntry(
|
|
||||||
new SimpleUrl('http://www.fourth.com/'),
|
|
||||||
new SimpleGetEncoding());
|
|
||||||
$this->assertIdentical($history->getUrl(), new SimpleUrl('http://www.fourth.com/'));
|
|
||||||
$this->assertFalse($history->forward());
|
|
||||||
$history->back();
|
|
||||||
$this->assertIdentical($history->getUrl(), new SimpleUrl('http://www.first.com/'));
|
|
||||||
$this->assertFalse($history->back());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfParsedPageAccess extends UnitTestCase {
|
|
||||||
|
|
||||||
function loadPage(&$page) {
|
|
||||||
$response = new MockSimpleHttpResponse($this);
|
|
||||||
$agent = new MockSimpleUserAgent($this);
|
|
||||||
$agent->returns('fetchResponse', $response);
|
|
||||||
|
|
||||||
$browser = new MockParseSimpleBrowser($this);
|
|
||||||
$browser->returns('createUserAgent', $agent);
|
|
||||||
$browser->returns('parse', $page);
|
|
||||||
$browser->__construct();
|
|
||||||
|
|
||||||
$browser->get('http://this.com/page.html');
|
|
||||||
return $browser;
|
|
||||||
}
|
|
||||||
|
|
||||||
function testAccessorsWhenNoPage() {
|
|
||||||
$agent = new MockSimpleUserAgent($this);
|
|
||||||
$browser = new MockParseSimpleBrowser($this);
|
|
||||||
$browser->returns('createUserAgent', $agent);
|
|
||||||
$browser->__construct();
|
|
||||||
$this->assertEqual($browser->getContent(), '');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testParse() {
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$page->setReturnValue('getRequest', "GET here.html\r\n\r\n");
|
|
||||||
$page->setReturnValue('getRaw', 'Raw HTML');
|
|
||||||
$page->setReturnValue('getTitle', 'Here');
|
|
||||||
$page->setReturnValue('getFrameFocus', 'Frame');
|
|
||||||
$page->setReturnValue('getMimeType', 'text/html');
|
|
||||||
$page->setReturnValue('getResponseCode', 200);
|
|
||||||
$page->setReturnValue('getAuthentication', 'Basic');
|
|
||||||
$page->setReturnValue('getRealm', 'Somewhere');
|
|
||||||
$page->setReturnValue('getTransportError', 'Ouch!');
|
|
||||||
|
|
||||||
$browser = $this->loadPage($page);
|
|
||||||
$this->assertEqual($browser->getRequest(), "GET here.html\r\n\r\n");
|
|
||||||
$this->assertEqual($browser->getContent(), 'Raw HTML');
|
|
||||||
$this->assertEqual($browser->getTitle(), 'Here');
|
|
||||||
$this->assertEqual($browser->getFrameFocus(), 'Frame');
|
|
||||||
$this->assertIdentical($browser->getResponseCode(), 200);
|
|
||||||
$this->assertEqual($browser->getMimeType(), 'text/html');
|
|
||||||
$this->assertEqual($browser->getAuthentication(), 'Basic');
|
|
||||||
$this->assertEqual($browser->getRealm(), 'Somewhere');
|
|
||||||
$this->assertEqual($browser->getTransportError(), 'Ouch!');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testLinkAffirmationWhenPresent() {
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$page->setReturnValue('getUrlsByLabel', array('http://www.nowhere.com'));
|
|
||||||
$page->expectOnce('getUrlsByLabel', array('a link label'));
|
|
||||||
$browser = $this->loadPage($page);
|
|
||||||
$this->assertIdentical($browser->getLink('a link label'), 'http://www.nowhere.com');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testLinkAffirmationByIdWhenPresent() {
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$page->setReturnValue('getUrlById', 'a_page.com', array(99));
|
|
||||||
$page->setReturnValue('getUrlById', false, array('*'));
|
|
||||||
$browser = $this->loadPage($page);
|
|
||||||
$this->assertIdentical($browser->getLinkById(99), 'a_page.com');
|
|
||||||
$this->assertFalse($browser->getLinkById(98));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSettingFieldIsPassedToPage() {
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$page->expectOnce('setField', array(new SimpleByLabelOrName('key'), 'Value', false));
|
|
||||||
$page->setReturnValue('getField', 'Value');
|
|
||||||
$browser = $this->loadPage($page);
|
|
||||||
$this->assertEqual($browser->getField('key'), 'Value');
|
|
||||||
$browser->setField('key', 'Value');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfBrowserNavigation extends UnitTestCase {
|
|
||||||
function createBrowser($agent, $page) {
|
|
||||||
$browser = new MockParseSimpleBrowser();
|
|
||||||
$browser->returns('createUserAgent', $agent);
|
|
||||||
$browser->returns('parse', $page);
|
|
||||||
$browser->__construct();
|
|
||||||
return $browser;
|
|
||||||
}
|
|
||||||
|
|
||||||
function testBrowserRequestMethods() {
|
|
||||||
$agent = new MockSimpleUserAgent();
|
|
||||||
$agent->returns('fetchResponse', new MockSimpleHttpResponse());
|
|
||||||
$agent->expectAt(
|
|
||||||
0,
|
|
||||||
'fetchResponse',
|
|
||||||
array(new SimpleUrl('http://this.com/get.req'), new SimpleGetEncoding()));
|
|
||||||
$agent->expectAt(
|
|
||||||
1,
|
|
||||||
'fetchResponse',
|
|
||||||
array(new SimpleUrl('http://this.com/post.req'), new SimplePostEncoding()));
|
|
||||||
$agent->expectAt(
|
|
||||||
2,
|
|
||||||
'fetchResponse',
|
|
||||||
array(new SimpleUrl('http://this.com/put.req'), new SimplePutEncoding()));
|
|
||||||
$agent->expectAt(
|
|
||||||
3,
|
|
||||||
'fetchResponse',
|
|
||||||
array(new SimpleUrl('http://this.com/delete.req'), new SimpleDeleteEncoding()));
|
|
||||||
$agent->expectAt(
|
|
||||||
4,
|
|
||||||
'fetchResponse',
|
|
||||||
array(new SimpleUrl('http://this.com/head.req'), new SimpleHeadEncoding()));
|
|
||||||
$agent->expectCallCount('fetchResponse', 5);
|
|
||||||
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
|
|
||||||
$browser = $this->createBrowser($agent, $page);
|
|
||||||
$browser->get('http://this.com/get.req');
|
|
||||||
$browser->post('http://this.com/post.req');
|
|
||||||
$browser->put('http://this.com/put.req');
|
|
||||||
$browser->delete('http://this.com/delete.req');
|
|
||||||
$browser->head('http://this.com/head.req');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testClickLinkRequestsPage() {
|
|
||||||
$agent = new MockSimpleUserAgent();
|
|
||||||
$agent->returns('fetchResponse', new MockSimpleHttpResponse());
|
|
||||||
$agent->expectAt(
|
|
||||||
0,
|
|
||||||
'fetchResponse',
|
|
||||||
array(new SimpleUrl('http://this.com/page.html'), new SimpleGetEncoding()));
|
|
||||||
$agent->expectAt(
|
|
||||||
1,
|
|
||||||
'fetchResponse',
|
|
||||||
array(new SimpleUrl('http://this.com/new.html'), new SimpleGetEncoding()));
|
|
||||||
$agent->expectCallCount('fetchResponse', 2);
|
|
||||||
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$page->setReturnValue('getUrlsByLabel', array(new SimpleUrl('http://this.com/new.html')));
|
|
||||||
$page->expectOnce('getUrlsByLabel', array('New'));
|
|
||||||
$page->setReturnValue('getRaw', 'A page');
|
|
||||||
|
|
||||||
$browser = $this->createBrowser($agent, $page);
|
|
||||||
$browser->get('http://this.com/page.html');
|
|
||||||
$this->assertTrue($browser->clickLink('New'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testClickLinkWithUnknownFrameStillRequestsWholePage() {
|
|
||||||
$agent = new MockSimpleUserAgent();
|
|
||||||
$agent->returns('fetchResponse', new MockSimpleHttpResponse());
|
|
||||||
$agent->expectAt(
|
|
||||||
0,
|
|
||||||
'fetchResponse',
|
|
||||||
array(new SimpleUrl('http://this.com/page.html'), new SimpleGetEncoding()));
|
|
||||||
$target = new SimpleUrl('http://this.com/new.html');
|
|
||||||
$target->setTarget('missing');
|
|
||||||
$agent->expectAt(
|
|
||||||
1,
|
|
||||||
'fetchResponse',
|
|
||||||
array($target, new SimpleGetEncoding()));
|
|
||||||
$agent->expectCallCount('fetchResponse', 2);
|
|
||||||
|
|
||||||
$parsed_url = new SimpleUrl('http://this.com/new.html');
|
|
||||||
$parsed_url->setTarget('missing');
|
|
||||||
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$page->setReturnValue('getUrlsByLabel', array($parsed_url));
|
|
||||||
$page->setReturnValue('hasFrames', false);
|
|
||||||
$page->expectOnce('getUrlsByLabel', array('New'));
|
|
||||||
$page->setReturnValue('getRaw', 'A page');
|
|
||||||
|
|
||||||
$browser = $this->createBrowser($agent, $page);
|
|
||||||
$browser->get('http://this.com/page.html');
|
|
||||||
$this->assertTrue($browser->clickLink('New'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testClickingMissingLinkFails() {
|
|
||||||
$agent = new MockSimpleUserAgent($this);
|
|
||||||
$agent->returns('fetchResponse', new MockSimpleHttpResponse());
|
|
||||||
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$page->setReturnValue('getUrlsByLabel', array());
|
|
||||||
$page->setReturnValue('getRaw', 'stuff');
|
|
||||||
|
|
||||||
$browser = $this->createBrowser($agent, $page);
|
|
||||||
$this->assertTrue($browser->get('http://this.com/page.html'));
|
|
||||||
$this->assertFalse($browser->clickLink('New'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testClickIndexedLink() {
|
|
||||||
$agent = new MockSimpleUserAgent();
|
|
||||||
$agent->returns('fetchResponse', new MockSimpleHttpResponse());
|
|
||||||
$agent->expectAt(
|
|
||||||
1,
|
|
||||||
'fetchResponse',
|
|
||||||
array(new SimpleUrl('1.html'), new SimpleGetEncoding()));
|
|
||||||
$agent->expectCallCount('fetchResponse', 2);
|
|
||||||
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$page->setReturnValue(
|
|
||||||
'getUrlsByLabel',
|
|
||||||
array(new SimpleUrl('0.html'), new SimpleUrl('1.html')));
|
|
||||||
$page->setReturnValue('getRaw', 'A page');
|
|
||||||
|
|
||||||
$browser = $this->createBrowser($agent, $page);
|
|
||||||
$browser->get('http://this.com/page.html');
|
|
||||||
$this->assertTrue($browser->clickLink('New', 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testClinkLinkById() {
|
|
||||||
$agent = new MockSimpleUserAgent();
|
|
||||||
$agent->returns('fetchResponse', new MockSimpleHttpResponse());
|
|
||||||
$agent->expectAt(1, 'fetchResponse', array(
|
|
||||||
new SimpleUrl('http://this.com/link.html'),
|
|
||||||
new SimpleGetEncoding()));
|
|
||||||
$agent->expectCallCount('fetchResponse', 2);
|
|
||||||
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$page->setReturnValue('getUrlById', new SimpleUrl('http://this.com/link.html'));
|
|
||||||
$page->expectOnce('getUrlById', array(2));
|
|
||||||
$page->setReturnValue('getRaw', 'A page');
|
|
||||||
|
|
||||||
$browser = $this->createBrowser($agent, $page);
|
|
||||||
$browser->get('http://this.com/page.html');
|
|
||||||
$this->assertTrue($browser->clickLinkById(2));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testClickingMissingLinkIdFails() {
|
|
||||||
$agent = new MockSimpleUserAgent();
|
|
||||||
$agent->returns('fetchResponse', new MockSimpleHttpResponse());
|
|
||||||
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$page->setReturnValue('getUrlById', false);
|
|
||||||
|
|
||||||
$browser = $this->createBrowser($agent, $page);
|
|
||||||
$browser->get('http://this.com/page.html');
|
|
||||||
$this->assertFalse($browser->clickLink(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSubmitFormByLabel() {
|
|
||||||
$agent = new MockSimpleUserAgent();
|
|
||||||
$agent->returns('fetchResponse', new MockSimpleHttpResponse());
|
|
||||||
$agent->expectAt(1, 'fetchResponse', array(
|
|
||||||
new SimpleUrl('http://this.com/handler.html'),
|
|
||||||
new SimplePostEncoding(array('a' => 'A'))));
|
|
||||||
$agent->expectCallCount('fetchResponse', 2);
|
|
||||||
|
|
||||||
$form = new MockSimpleForm();
|
|
||||||
$form->setReturnValue('getAction', new SimpleUrl('http://this.com/handler.html'));
|
|
||||||
$form->setReturnValue('getMethod', 'post');
|
|
||||||
$form->setReturnValue('submitButton', new SimplePostEncoding(array('a' => 'A')));
|
|
||||||
$form->expectOnce('submitButton', array(new SimpleByLabel('Go'), false));
|
|
||||||
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$page->returns('getFormBySubmit', $form);
|
|
||||||
$page->expectOnce('getFormBySubmit', array(new SimpleByLabel('Go')));
|
|
||||||
$page->setReturnValue('getRaw', 'stuff');
|
|
||||||
|
|
||||||
$browser = $this->createBrowser($agent, $page);
|
|
||||||
$browser->get('http://this.com/page.html');
|
|
||||||
$this->assertTrue($browser->clickSubmit('Go'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testDefaultSubmitFormByLabel() {
|
|
||||||
$agent = new MockSimpleUserAgent();
|
|
||||||
$agent->returns('fetchResponse', new MockSimpleHttpResponse());
|
|
||||||
$agent->expectAt(1, 'fetchResponse', array(
|
|
||||||
new SimpleUrl('http://this.com/page.html'),
|
|
||||||
new SimpleGetEncoding(array('a' => 'A'))));
|
|
||||||
$agent->expectCallCount('fetchResponse', 2);
|
|
||||||
|
|
||||||
$form = new MockSimpleForm();
|
|
||||||
$form->setReturnValue('getAction', new SimpleUrl('http://this.com/page.html'));
|
|
||||||
$form->setReturnValue('getMethod', 'get');
|
|
||||||
$form->setReturnValue('submitButton', new SimpleGetEncoding(array('a' => 'A')));
|
|
||||||
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$page->returns('getFormBySubmit', $form);
|
|
||||||
$page->expectOnce('getFormBySubmit', array(new SimpleByLabel('Submit')));
|
|
||||||
$page->setReturnValue('getRaw', 'stuff');
|
|
||||||
$page->setReturnValue('getUrl', new SimpleUrl('http://this.com/page.html'));
|
|
||||||
|
|
||||||
$browser = $this->createBrowser($agent, $page);
|
|
||||||
$browser->get('http://this.com/page.html');
|
|
||||||
$this->assertTrue($browser->clickSubmit());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSubmitFormByName() {
|
|
||||||
$agent = new MockSimpleUserAgent();
|
|
||||||
$agent->returns('fetchResponse', new MockSimpleHttpResponse());
|
|
||||||
|
|
||||||
$form = new MockSimpleForm();
|
|
||||||
$form->setReturnValue('getAction', new SimpleUrl('http://this.com/handler.html'));
|
|
||||||
$form->setReturnValue('getMethod', 'post');
|
|
||||||
$form->setReturnValue('submitButton', new SimplePostEncoding(array('a' => 'A')));
|
|
||||||
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$page->returns('getFormBySubmit', $form);
|
|
||||||
$page->expectOnce('getFormBySubmit', array(new SimpleByName('me')));
|
|
||||||
$page->setReturnValue('getRaw', 'stuff');
|
|
||||||
|
|
||||||
$browser = $this->createBrowser($agent, $page);
|
|
||||||
$browser->get('http://this.com/page.html');
|
|
||||||
$this->assertTrue($browser->clickSubmitByName('me'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSubmitFormById() {
|
|
||||||
$agent = new MockSimpleUserAgent();
|
|
||||||
$agent->returns('fetchResponse', new MockSimpleHttpResponse());
|
|
||||||
|
|
||||||
$form = new MockSimpleForm();
|
|
||||||
$form->setReturnValue('getAction', new SimpleUrl('http://this.com/handler.html'));
|
|
||||||
$form->setReturnValue('getMethod', 'post');
|
|
||||||
$form->setReturnValue('submitButton', new SimplePostEncoding(array('a' => 'A')));
|
|
||||||
$form->expectOnce('submitButton', array(new SimpleById(99), false));
|
|
||||||
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$page->returns('getFormBySubmit', $form);
|
|
||||||
$page->expectOnce('getFormBySubmit', array(new SimpleById(99)));
|
|
||||||
$page->setReturnValue('getRaw', 'stuff');
|
|
||||||
|
|
||||||
$browser = $this->createBrowser($agent, $page);
|
|
||||||
$browser->get('http://this.com/page.html');
|
|
||||||
$this->assertTrue($browser->clickSubmitById(99));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSubmitFormByImageLabel() {
|
|
||||||
$agent = new MockSimpleUserAgent();
|
|
||||||
$agent->returns('fetchResponse', new MockSimpleHttpResponse());
|
|
||||||
|
|
||||||
$form = new MockSimpleForm();
|
|
||||||
$form->setReturnValue('getAction', new SimpleUrl('http://this.com/handler.html'));
|
|
||||||
$form->setReturnValue('getMethod', 'post');
|
|
||||||
$form->setReturnValue('submitImage', new SimplePostEncoding(array('a' => 'A')));
|
|
||||||
$form->expectOnce('submitImage', array(new SimpleByLabel('Go!'), 10, 11, false));
|
|
||||||
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$page->returns('getFormByImage', $form);
|
|
||||||
$page->expectOnce('getFormByImage', array(new SimpleByLabel('Go!')));
|
|
||||||
$page->setReturnValue('getRaw', 'stuff');
|
|
||||||
|
|
||||||
$browser = $this->createBrowser($agent, $page);
|
|
||||||
$browser->get('http://this.com/page.html');
|
|
||||||
$this->assertTrue($browser->clickImage('Go!', 10, 11));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSubmitFormByImageName() {
|
|
||||||
$agent = new MockSimpleUserAgent();
|
|
||||||
$agent->returns('fetchResponse', new MockSimpleHttpResponse());
|
|
||||||
|
|
||||||
$form = new MockSimpleForm();
|
|
||||||
$form->setReturnValue('getAction', new SimpleUrl('http://this.com/handler.html'));
|
|
||||||
$form->setReturnValue('getMethod', 'post');
|
|
||||||
$form->setReturnValue('submitImage', new SimplePostEncoding(array('a' => 'A')));
|
|
||||||
$form->expectOnce('submitImage', array(new SimpleByName('a'), 10, 11, false));
|
|
||||||
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$page->returns('getFormByImage', $form);
|
|
||||||
$page->expectOnce('getFormByImage', array(new SimpleByName('a')));
|
|
||||||
$page->setReturnValue('getRaw', 'stuff');
|
|
||||||
|
|
||||||
$browser = $this->createBrowser($agent, $page);
|
|
||||||
$browser->get('http://this.com/page.html');
|
|
||||||
$this->assertTrue($browser->clickImageByName('a', 10, 11));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSubmitFormByImageId() {
|
|
||||||
$agent = new MockSimpleUserAgent();
|
|
||||||
$agent->returns('fetchResponse', new MockSimpleHttpResponse());
|
|
||||||
|
|
||||||
$form = new MockSimpleForm();
|
|
||||||
$form->setReturnValue('getAction', new SimpleUrl('http://this.com/handler.html'));
|
|
||||||
$form->setReturnValue('getMethod', 'post');
|
|
||||||
$form->setReturnValue('submitImage', new SimplePostEncoding(array('a' => 'A')));
|
|
||||||
$form->expectOnce('submitImage', array(new SimpleById(99), 10, 11, false));
|
|
||||||
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$page->returns('getFormByImage', $form);
|
|
||||||
$page->expectOnce('getFormByImage', array(new SimpleById(99)));
|
|
||||||
$page->setReturnValue('getRaw', 'stuff');
|
|
||||||
|
|
||||||
$browser = $this->createBrowser($agent, $page);
|
|
||||||
$browser->get('http://this.com/page.html');
|
|
||||||
$this->assertTrue($browser->clickImageById(99, 10, 11));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSubmitFormByFormId() {
|
|
||||||
$agent = new MockSimpleUserAgent();
|
|
||||||
$agent->returns('fetchResponse', new MockSimpleHttpResponse());
|
|
||||||
$agent->expectAt(1, 'fetchResponse', array(
|
|
||||||
new SimpleUrl('http://this.com/handler.html'),
|
|
||||||
new SimplePostEncoding(array('a' => 'A'))));
|
|
||||||
$agent->expectCallCount('fetchResponse', 2);
|
|
||||||
|
|
||||||
$form = new MockSimpleForm();
|
|
||||||
$form->setReturnValue('getAction', new SimpleUrl('http://this.com/handler.html'));
|
|
||||||
$form->setReturnValue('getMethod', 'post');
|
|
||||||
$form->setReturnValue('submit', new SimplePostEncoding(array('a' => 'A')));
|
|
||||||
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$page->returns('getFormById', $form);
|
|
||||||
$page->expectOnce('getFormById', array(33));
|
|
||||||
$page->setReturnValue('getRaw', 'stuff');
|
|
||||||
|
|
||||||
$browser = $this->createBrowser($agent, $page);
|
|
||||||
$browser->get('http://this.com/page.html');
|
|
||||||
$this->assertTrue($browser->submitFormById(33));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfBrowserFrames extends UnitTestCase {
|
|
||||||
|
|
||||||
function createBrowser($agent) {
|
|
||||||
$browser = new MockUserAgentSimpleBrowser();
|
|
||||||
$browser->returns('createUserAgent', $agent);
|
|
||||||
$browser->__construct();
|
|
||||||
return $browser;
|
|
||||||
}
|
|
||||||
|
|
||||||
function createUserAgent($pages) {
|
|
||||||
$agent = new MockSimpleUserAgent();
|
|
||||||
foreach ($pages as $url => $raw) {
|
|
||||||
$url = new SimpleUrl($url);
|
|
||||||
$response = new MockSimpleHttpResponse();
|
|
||||||
$response->setReturnValue('getUrl', $url);
|
|
||||||
$response->setReturnValue('getContent', $raw);
|
|
||||||
$agent->returns('fetchResponse', $response, array($url, '*'));
|
|
||||||
}
|
|
||||||
return $agent;
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSimplePageHasNoFrames() {
|
|
||||||
$browser = $this->createBrowser($this->createUserAgent(
|
|
||||||
array('http://site.with.no.frames/' => 'A non-framed page')));
|
|
||||||
$this->assertEqual(
|
|
||||||
$browser->get('http://site.with.no.frames/'),
|
|
||||||
'A non-framed page');
|
|
||||||
$this->assertIdentical($browser->getFrames(), 'http://site.with.no.frames/');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFramesetWithSingleFrame() {
|
|
||||||
$frameset = '<frameset><frame name="a" src="frame.html"></frameset>';
|
|
||||||
$browser = $this->createBrowser($this->createUserAgent(array(
|
|
||||||
'http://site.with.one.frame/' => $frameset,
|
|
||||||
'http://site.with.one.frame/frame.html' => 'A frame')));
|
|
||||||
$this->assertEqual($browser->get('http://site.with.one.frame/'), 'A frame');
|
|
||||||
$this->assertIdentical(
|
|
||||||
$browser->getFrames(),
|
|
||||||
array('a' => 'http://site.with.one.frame/frame.html'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testTitleTakenFromFramesetPage() {
|
|
||||||
$frameset = '<title>Frameset title</title>' .
|
|
||||||
'<frameset><frame name="a" src="frame.html"></frameset>';
|
|
||||||
$browser = $this->createBrowser($this->createUserAgent(array(
|
|
||||||
'http://site.with.one.frame/' => $frameset,
|
|
||||||
'http://site.with.one.frame/frame.html' => '<title>Page title</title>')));
|
|
||||||
$browser->get('http://site.with.one.frame/');
|
|
||||||
$this->assertEqual($browser->getTitle(), 'Frameset title');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFramesetWithSingleUnnamedFrame() {
|
|
||||||
$frameset = '<frameset><frame src="frame.html"></frameset>';
|
|
||||||
$browser = $this->createBrowser($this->createUserAgent(array(
|
|
||||||
'http://site.with.one.frame/' => $frameset,
|
|
||||||
'http://site.with.one.frame/frame.html' => 'One frame')));
|
|
||||||
$this->assertEqual(
|
|
||||||
$browser->get('http://site.with.one.frame/'),
|
|
||||||
'One frame');
|
|
||||||
$this->assertIdentical(
|
|
||||||
$browser->getFrames(),
|
|
||||||
array(1 => 'http://site.with.one.frame/frame.html'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFramesetWithMultipleFrames() {
|
|
||||||
$frameset = '<frameset>' .
|
|
||||||
'<frame name="a" src="frame_a.html">' .
|
|
||||||
'<frame name="b" src="frame_b.html">' .
|
|
||||||
'<frame name="c" src="frame_c.html">' .
|
|
||||||
'</frameset>';
|
|
||||||
$browser = $this->createBrowser($this->createUserAgent(array(
|
|
||||||
'http://site.with.frames/' => $frameset,
|
|
||||||
'http://site.with.frames/frame_a.html' => 'A frame',
|
|
||||||
'http://site.with.frames/frame_b.html' => 'B frame',
|
|
||||||
'http://site.with.frames/frame_c.html' => 'C frame')));
|
|
||||||
$this->assertEqual(
|
|
||||||
$browser->get('http://site.with.frames/'),
|
|
||||||
'A frameB frameC frame');
|
|
||||||
$this->assertIdentical($browser->getFrames(), array(
|
|
||||||
'a' => 'http://site.with.frames/frame_a.html',
|
|
||||||
'b' => 'http://site.with.frames/frame_b.html',
|
|
||||||
'c' => 'http://site.with.frames/frame_c.html'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFrameFocusByName() {
|
|
||||||
$frameset = '<frameset>' .
|
|
||||||
'<frame name="a" src="frame_a.html">' .
|
|
||||||
'<frame name="b" src="frame_b.html">' .
|
|
||||||
'<frame name="c" src="frame_c.html">' .
|
|
||||||
'</frameset>';
|
|
||||||
$browser = $this->createBrowser($this->createUserAgent(array(
|
|
||||||
'http://site.with.frames/' => $frameset,
|
|
||||||
'http://site.with.frames/frame_a.html' => 'A frame',
|
|
||||||
'http://site.with.frames/frame_b.html' => 'B frame',
|
|
||||||
'http://site.with.frames/frame_c.html' => 'C frame')));
|
|
||||||
$browser->get('http://site.with.frames/');
|
|
||||||
$browser->setFrameFocus('a');
|
|
||||||
$this->assertEqual($browser->getContent(), 'A frame');
|
|
||||||
$browser->setFrameFocus('b');
|
|
||||||
$this->assertEqual($browser->getContent(), 'B frame');
|
|
||||||
$browser->setFrameFocus('c');
|
|
||||||
$this->assertEqual($browser->getContent(), 'C frame');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFramesetWithSomeNamedFrames() {
|
|
||||||
$frameset = '<frameset>' .
|
|
||||||
'<frame name="a" src="frame_a.html">' .
|
|
||||||
'<frame src="frame_b.html">' .
|
|
||||||
'<frame name="c" src="frame_c.html">' .
|
|
||||||
'<frame src="frame_d.html">' .
|
|
||||||
'</frameset>';
|
|
||||||
$browser = $this->createBrowser($this->createUserAgent(array(
|
|
||||||
'http://site.with.frames/' => $frameset,
|
|
||||||
'http://site.with.frames/frame_a.html' => 'A frame',
|
|
||||||
'http://site.with.frames/frame_b.html' => 'B frame',
|
|
||||||
'http://site.with.frames/frame_c.html' => 'C frame',
|
|
||||||
'http://site.with.frames/frame_d.html' => 'D frame')));
|
|
||||||
$this->assertEqual(
|
|
||||||
$browser->get('http://site.with.frames/'),
|
|
||||||
'A frameB frameC frameD frame');
|
|
||||||
$this->assertIdentical($browser->getFrames(), array(
|
|
||||||
'a' => 'http://site.with.frames/frame_a.html',
|
|
||||||
2 => 'http://site.with.frames/frame_b.html',
|
|
||||||
'c' => 'http://site.with.frames/frame_c.html',
|
|
||||||
4 => 'http://site.with.frames/frame_d.html'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFrameFocusWithMixedNamesAndIndexes() {
|
|
||||||
$frameset = '<frameset>' .
|
|
||||||
'<frame name="a" src="frame_a.html">' .
|
|
||||||
'<frame src="frame_b.html">' .
|
|
||||||
'<frame name="c" src="frame_c.html">' .
|
|
||||||
'<frame src="frame_d.html">' .
|
|
||||||
'</frameset>';
|
|
||||||
$browser = $this->createBrowser($this->createUserAgent(array(
|
|
||||||
'http://site.with.frames/' => $frameset,
|
|
||||||
'http://site.with.frames/frame_a.html' => 'A frame',
|
|
||||||
'http://site.with.frames/frame_b.html' => 'B frame',
|
|
||||||
'http://site.with.frames/frame_c.html' => 'C frame',
|
|
||||||
'http://site.with.frames/frame_d.html' => 'D frame')));
|
|
||||||
$browser->get('http://site.with.frames/');
|
|
||||||
$browser->setFrameFocus('a');
|
|
||||||
$this->assertEqual($browser->getContent(), 'A frame');
|
|
||||||
$browser->setFrameFocus(2);
|
|
||||||
$this->assertEqual($browser->getContent(), 'B frame');
|
|
||||||
$browser->setFrameFocus('c');
|
|
||||||
$this->assertEqual($browser->getContent(), 'C frame');
|
|
||||||
$browser->setFrameFocus(4);
|
|
||||||
$this->assertEqual($browser->getContent(), 'D frame');
|
|
||||||
$browser->clearFrameFocus();
|
|
||||||
$this->assertEqual($browser->getContent(), 'A frameB frameC frameD frame');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testNestedFrameset() {
|
|
||||||
$inner = '<frameset>' .
|
|
||||||
'<frame name="page" src="page.html">' .
|
|
||||||
'</frameset>';
|
|
||||||
$outer = '<frameset>' .
|
|
||||||
'<frame name="inner" src="inner.html">' .
|
|
||||||
'</frameset>';
|
|
||||||
$browser = $this->createBrowser($this->createUserAgent(array(
|
|
||||||
'http://site.with.nested.frame/' => $outer,
|
|
||||||
'http://site.with.nested.frame/inner.html' => $inner,
|
|
||||||
'http://site.with.nested.frame/page.html' => 'The page')));
|
|
||||||
$this->assertEqual(
|
|
||||||
$browser->get('http://site.with.nested.frame/'),
|
|
||||||
'The page');
|
|
||||||
$this->assertIdentical($browser->getFrames(), array(
|
|
||||||
'inner' => array(
|
|
||||||
'page' => 'http://site.with.nested.frame/page.html')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanNavigateToNestedFrame() {
|
|
||||||
$inner = '<frameset>' .
|
|
||||||
'<frame name="one" src="one.html">' .
|
|
||||||
'<frame name="two" src="two.html">' .
|
|
||||||
'</frameset>';
|
|
||||||
$outer = '<frameset>' .
|
|
||||||
'<frame name="inner" src="inner.html">' .
|
|
||||||
'<frame name="three" src="three.html">' .
|
|
||||||
'</frameset>';
|
|
||||||
$browser = $this->createBrowser($this->createUserAgent(array(
|
|
||||||
'http://site.with.nested.frames/' => $outer,
|
|
||||||
'http://site.with.nested.frames/inner.html' => $inner,
|
|
||||||
'http://site.with.nested.frames/one.html' => 'Page one',
|
|
||||||
'http://site.with.nested.frames/two.html' => 'Page two',
|
|
||||||
'http://site.with.nested.frames/three.html' => 'Page three')));
|
|
||||||
|
|
||||||
$browser->get('http://site.with.nested.frames/');
|
|
||||||
$this->assertEqual($browser->getContent(), 'Page onePage twoPage three');
|
|
||||||
|
|
||||||
$this->assertTrue($browser->setFrameFocus('inner'));
|
|
||||||
$this->assertEqual($browser->getFrameFocus(), array('inner'));
|
|
||||||
$this->assertTrue($browser->setFrameFocus('one'));
|
|
||||||
$this->assertEqual($browser->getFrameFocus(), array('inner', 'one'));
|
|
||||||
$this->assertEqual($browser->getContent(), 'Page one');
|
|
||||||
|
|
||||||
$this->assertTrue($browser->setFrameFocus('two'));
|
|
||||||
$this->assertEqual($browser->getFrameFocus(), array('inner', 'two'));
|
|
||||||
$this->assertEqual($browser->getContent(), 'Page two');
|
|
||||||
|
|
||||||
$browser->clearFrameFocus();
|
|
||||||
$this->assertTrue($browser->setFrameFocus('three'));
|
|
||||||
$this->assertEqual($browser->getFrameFocus(), array('three'));
|
|
||||||
$this->assertEqual($browser->getContent(), 'Page three');
|
|
||||||
|
|
||||||
$this->assertTrue($browser->setFrameFocus('inner'));
|
|
||||||
$this->assertEqual($browser->getContent(), 'Page onePage two');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanNavigateToNestedFrameByIndex() {
|
|
||||||
$inner = '<frameset>' .
|
|
||||||
'<frame src="one.html">' .
|
|
||||||
'<frame src="two.html">' .
|
|
||||||
'</frameset>';
|
|
||||||
$outer = '<frameset>' .
|
|
||||||
'<frame src="inner.html">' .
|
|
||||||
'<frame src="three.html">' .
|
|
||||||
'</frameset>';
|
|
||||||
$browser = $this->createBrowser($this->createUserAgent(array(
|
|
||||||
'http://site.with.nested.frames/' => $outer,
|
|
||||||
'http://site.with.nested.frames/inner.html' => $inner,
|
|
||||||
'http://site.with.nested.frames/one.html' => 'Page one',
|
|
||||||
'http://site.with.nested.frames/two.html' => 'Page two',
|
|
||||||
'http://site.with.nested.frames/three.html' => 'Page three')));
|
|
||||||
|
|
||||||
$browser->get('http://site.with.nested.frames/');
|
|
||||||
$this->assertEqual($browser->getContent(), 'Page onePage twoPage three');
|
|
||||||
|
|
||||||
$this->assertTrue($browser->setFrameFocusByIndex(1));
|
|
||||||
$this->assertEqual($browser->getFrameFocus(), array(1));
|
|
||||||
$this->assertTrue($browser->setFrameFocusByIndex(1));
|
|
||||||
$this->assertEqual($browser->getFrameFocus(), array(1, 1));
|
|
||||||
$this->assertEqual($browser->getContent(), 'Page one');
|
|
||||||
|
|
||||||
$this->assertTrue($browser->setFrameFocusByIndex(2));
|
|
||||||
$this->assertEqual($browser->getFrameFocus(), array(1, 2));
|
|
||||||
$this->assertEqual($browser->getContent(), 'Page two');
|
|
||||||
|
|
||||||
$browser->clearFrameFocus();
|
|
||||||
$this->assertTrue($browser->setFrameFocusByIndex(2));
|
|
||||||
$this->assertEqual($browser->getFrameFocus(), array(2));
|
|
||||||
$this->assertEqual($browser->getContent(), 'Page three');
|
|
||||||
|
|
||||||
$this->assertTrue($browser->setFrameFocusByIndex(1));
|
|
||||||
$this->assertEqual($browser->getContent(), 'Page onePage two');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,50 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: collector_test.php 1769 2008-04-19 14:39:00Z pp11 $
|
|
||||||
require_once(dirname(__FILE__) . '/../autorun.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../collector.php');
|
|
||||||
SimpleTest::ignore('MockTestSuite');
|
|
||||||
Mock::generate('TestSuite');
|
|
||||||
|
|
||||||
class PathEqualExpectation extends EqualExpectation {
|
|
||||||
function __construct($value, $message = '%s') {
|
|
||||||
parent::__construct(str_replace("\\", '/', $value), $message);
|
|
||||||
}
|
|
||||||
|
|
||||||
function test($compare) {
|
|
||||||
return parent::test(str_replace("\\", '/', $compare));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfCollector extends UnitTestCase {
|
|
||||||
function testCollectionIsAddedToGroup() {
|
|
||||||
$suite = new MockTestSuite();
|
|
||||||
$suite->expectMinimumCallCount('addFile', 2);
|
|
||||||
$suite->expect(
|
|
||||||
'addFile',
|
|
||||||
array(new PatternExpectation('/collectable\\.(1|2)$/')));
|
|
||||||
$collector = new SimpleCollector();
|
|
||||||
$collector->collect($suite, dirname(__FILE__) . '/support/collector/');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfPatternCollector extends UnitTestCase {
|
|
||||||
|
|
||||||
function testAddingEverythingToGroup() {
|
|
||||||
$suite = new MockTestSuite();
|
|
||||||
$suite->expectCallCount('addFile', 2);
|
|
||||||
$suite->expect(
|
|
||||||
'addFile',
|
|
||||||
array(new PatternExpectation('/collectable\\.(1|2)$/')));
|
|
||||||
$collector = new SimplePatternCollector('/.*/');
|
|
||||||
$collector->collect($suite, dirname(__FILE__) . '/support/collector/');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testOnlyMatchedFilesAreAddedToGroup() {
|
|
||||||
$suite = new MockTestSuite();
|
|
||||||
$suite->expectOnce('addFile', array(new PathEqualExpectation(
|
|
||||||
dirname(__FILE__) . '/support/collector/collectable.1')));
|
|
||||||
$collector = new SimplePatternCollector('/1$/');
|
|
||||||
$collector->collect($suite, dirname(__FILE__) . '/support/collector/');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,40 +0,0 @@
|
||||||
<?php
|
|
||||||
require_once(dirname(__FILE__) . '/../autorun.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../default_reporter.php');
|
|
||||||
|
|
||||||
class TestOfCommandLineParsing extends UnitTestCase {
|
|
||||||
|
|
||||||
function testDefaultsToEmptyStringToMeanNullToTheSelectiveReporter() {
|
|
||||||
$parser = new SimpleCommandLineParser(array());
|
|
||||||
$this->assertIdentical($parser->getTest(), '');
|
|
||||||
$this->assertIdentical($parser->getTestCase(), '');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testNotXmlByDefault() {
|
|
||||||
$parser = new SimpleCommandLineParser(array());
|
|
||||||
$this->assertFalse($parser->isXml());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanDetectRequestForXml() {
|
|
||||||
$parser = new SimpleCommandLineParser(array('--xml'));
|
|
||||||
$this->assertTrue($parser->isXml());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanReadAssignmentSyntax() {
|
|
||||||
$parser = new SimpleCommandLineParser(array('--test=myTest'));
|
|
||||||
$this->assertEqual($parser->getTest(), 'myTest');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanReadFollowOnSyntax() {
|
|
||||||
$parser = new SimpleCommandLineParser(array('--test', 'myTest'));
|
|
||||||
$this->assertEqual($parser->getTest(), 'myTest');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanReadShortForms() {
|
|
||||||
$parser = new SimpleCommandLineParser(array('-t', 'myTest', '-c', 'MyClass', '-x'));
|
|
||||||
$this->assertEqual($parser->getTest(), 'myTest');
|
|
||||||
$this->assertEqual($parser->getTestCase(), 'MyClass');
|
|
||||||
$this->assertTrue($parser->isXml());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,87 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: compatibility_test.php 1748 2008-04-14 01:50:41Z lastcraft $
|
|
||||||
require_once(dirname(__FILE__) . '/../autorun.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../compatibility.php');
|
|
||||||
|
|
||||||
class ComparisonClass { }
|
|
||||||
class ComparisonSubclass extends ComparisonClass { }
|
|
||||||
interface ComparisonInterface { }
|
|
||||||
class ComparisonClassWithInterface implements ComparisonInterface { }
|
|
||||||
|
|
||||||
class TestOfCompatibility extends UnitTestCase {
|
|
||||||
|
|
||||||
function testIsA() {
|
|
||||||
$this->assertTrue(SimpleTestCompatibility::isA(
|
|
||||||
new ComparisonClass(),
|
|
||||||
'ComparisonClass'));
|
|
||||||
$this->assertFalse(SimpleTestCompatibility::isA(
|
|
||||||
new ComparisonClass(),
|
|
||||||
'ComparisonSubclass'));
|
|
||||||
$this->assertTrue(SimpleTestCompatibility::isA(
|
|
||||||
new ComparisonSubclass(),
|
|
||||||
'ComparisonClass'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testIdentityOfNumericStrings() {
|
|
||||||
$numericString1 = "123";
|
|
||||||
$numericString2 = "00123";
|
|
||||||
$this->assertNotIdentical($numericString1, $numericString2);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testIdentityOfObjects() {
|
|
||||||
$object1 = new ComparisonClass();
|
|
||||||
$object2 = new ComparisonClass();
|
|
||||||
$this->assertIdentical($object1, $object2);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testReferences () {
|
|
||||||
$thing = "Hello";
|
|
||||||
$thing_reference = &$thing;
|
|
||||||
$thing_copy = $thing;
|
|
||||||
$this->assertTrue(SimpleTestCompatibility::isReference(
|
|
||||||
$thing,
|
|
||||||
$thing));
|
|
||||||
$this->assertTrue(SimpleTestCompatibility::isReference(
|
|
||||||
$thing,
|
|
||||||
$thing_reference));
|
|
||||||
$this->assertFalse(SimpleTestCompatibility::isReference(
|
|
||||||
$thing,
|
|
||||||
$thing_copy));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testObjectReferences () {
|
|
||||||
$object = new ComparisonClass();
|
|
||||||
$object_reference = $object;
|
|
||||||
$object_copy = new ComparisonClass();
|
|
||||||
$object_assignment = $object;
|
|
||||||
$this->assertTrue(SimpleTestCompatibility::isReference(
|
|
||||||
$object,
|
|
||||||
$object));
|
|
||||||
$this->assertTrue(SimpleTestCompatibility::isReference(
|
|
||||||
$object,
|
|
||||||
$object_reference));
|
|
||||||
$this->assertFalse(SimpleTestCompatibility::isReference(
|
|
||||||
$object,
|
|
||||||
$object_copy));
|
|
||||||
if (version_compare(phpversion(), '5', '>=')) {
|
|
||||||
$this->assertTrue(SimpleTestCompatibility::isReference(
|
|
||||||
$object,
|
|
||||||
$object_assignment));
|
|
||||||
} else {
|
|
||||||
$this->assertFalse(SimpleTestCompatibility::isReference(
|
|
||||||
$object,
|
|
||||||
$object_assignment));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function testInteraceComparison() {
|
|
||||||
$object = new ComparisonClassWithInterface();
|
|
||||||
$this->assertFalse(SimpleTestCompatibility::isA(
|
|
||||||
new ComparisonClass(),
|
|
||||||
'ComparisonInterface'));
|
|
||||||
$this->assertTrue(SimpleTestCompatibility::isA(
|
|
||||||
new ComparisonClassWithInterface(),
|
|
||||||
'ComparisonInterface'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,227 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: cookies_test.php 1506 2007-05-07 00:58:03Z lastcraft $
|
|
||||||
require_once(dirname(__FILE__) . '/../autorun.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../cookies.php');
|
|
||||||
|
|
||||||
class TestOfCookie extends UnitTestCase {
|
|
||||||
|
|
||||||
function testCookieDefaults() {
|
|
||||||
$cookie = new SimpleCookie("name");
|
|
||||||
$this->assertFalse($cookie->getValue());
|
|
||||||
$this->assertEqual($cookie->getPath(), "/");
|
|
||||||
$this->assertIdentical($cookie->getHost(), false);
|
|
||||||
$this->assertFalse($cookie->getExpiry());
|
|
||||||
$this->assertFalse($cookie->isSecure());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCookieAccessors() {
|
|
||||||
$cookie = new SimpleCookie(
|
|
||||||
"name",
|
|
||||||
"value",
|
|
||||||
"/path",
|
|
||||||
"Mon, 18 Nov 2002 15:50:29 GMT",
|
|
||||||
true);
|
|
||||||
$this->assertEqual($cookie->getName(), "name");
|
|
||||||
$this->assertEqual($cookie->getValue(), "value");
|
|
||||||
$this->assertEqual($cookie->getPath(), "/path/");
|
|
||||||
$this->assertEqual($cookie->getExpiry(), "Mon, 18 Nov 2002 15:50:29 GMT");
|
|
||||||
$this->assertTrue($cookie->isSecure());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFullHostname() {
|
|
||||||
$cookie = new SimpleCookie("name");
|
|
||||||
$this->assertTrue($cookie->setHost("host.name.here"));
|
|
||||||
$this->assertEqual($cookie->getHost(), "host.name.here");
|
|
||||||
$this->assertTrue($cookie->setHost("host.com"));
|
|
||||||
$this->assertEqual($cookie->getHost(), "host.com");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testHostTruncation() {
|
|
||||||
$cookie = new SimpleCookie("name");
|
|
||||||
$cookie->setHost("this.host.name.here");
|
|
||||||
$this->assertEqual($cookie->getHost(), "host.name.here");
|
|
||||||
$cookie->setHost("this.host.com");
|
|
||||||
$this->assertEqual($cookie->getHost(), "host.com");
|
|
||||||
$this->assertTrue($cookie->setHost("dashes.in-host.com"));
|
|
||||||
$this->assertEqual($cookie->getHost(), "in-host.com");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testBadHosts() {
|
|
||||||
$cookie = new SimpleCookie("name");
|
|
||||||
$this->assertFalse($cookie->setHost("gibberish"));
|
|
||||||
$this->assertFalse($cookie->setHost("host.here"));
|
|
||||||
$this->assertFalse($cookie->setHost("host..com"));
|
|
||||||
$this->assertFalse($cookie->setHost("..."));
|
|
||||||
$this->assertFalse($cookie->setHost("host.com."));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testHostValidity() {
|
|
||||||
$cookie = new SimpleCookie("name");
|
|
||||||
$cookie->setHost("this.host.name.here");
|
|
||||||
$this->assertTrue($cookie->isValidHost("host.name.here"));
|
|
||||||
$this->assertTrue($cookie->isValidHost("that.host.name.here"));
|
|
||||||
$this->assertFalse($cookie->isValidHost("bad.host"));
|
|
||||||
$this->assertFalse($cookie->isValidHost("nearly.name.here"));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testPathValidity() {
|
|
||||||
$cookie = new SimpleCookie("name", "value", "/path");
|
|
||||||
$this->assertFalse($cookie->isValidPath("/"));
|
|
||||||
$this->assertTrue($cookie->isValidPath("/path/"));
|
|
||||||
$this->assertTrue($cookie->isValidPath("/path/more"));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSessionExpiring() {
|
|
||||||
$cookie = new SimpleCookie("name", "value", "/path");
|
|
||||||
$this->assertTrue($cookie->isExpired(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testTimestampExpiry() {
|
|
||||||
$cookie = new SimpleCookie("name", "value", "/path", 456);
|
|
||||||
$this->assertFalse($cookie->isExpired(0));
|
|
||||||
$this->assertTrue($cookie->isExpired(457));
|
|
||||||
$this->assertFalse($cookie->isExpired(455));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testDateExpiry() {
|
|
||||||
$cookie = new SimpleCookie(
|
|
||||||
"name",
|
|
||||||
"value",
|
|
||||||
"/path",
|
|
||||||
"Mon, 18 Nov 2002 15:50:29 GMT");
|
|
||||||
$this->assertTrue($cookie->isExpired("Mon, 18 Nov 2002 15:50:30 GMT"));
|
|
||||||
$this->assertFalse($cookie->isExpired("Mon, 18 Nov 2002 15:50:28 GMT"));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testAging() {
|
|
||||||
$cookie = new SimpleCookie("name", "value", "/path", 200);
|
|
||||||
$cookie->agePrematurely(199);
|
|
||||||
$this->assertFalse($cookie->isExpired(0));
|
|
||||||
$cookie->agePrematurely(2);
|
|
||||||
$this->assertTrue($cookie->isExpired(0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfCookieJar extends UnitTestCase {
|
|
||||||
|
|
||||||
function testAddCookie() {
|
|
||||||
$jar = new SimpleCookieJar();
|
|
||||||
$jar->setCookie("a", "A");
|
|
||||||
$this->assertEqual($jar->selectAsPairs(new SimpleUrl('/')), array('a=A'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testHostFilter() {
|
|
||||||
$jar = new SimpleCookieJar();
|
|
||||||
$jar->setCookie('a', 'A', 'my-host.com');
|
|
||||||
$jar->setCookie('b', 'B', 'another-host.com');
|
|
||||||
$jar->setCookie('c', 'C');
|
|
||||||
$this->assertEqual(
|
|
||||||
$jar->selectAsPairs(new SimpleUrl('my-host.com')),
|
|
||||||
array('a=A', 'c=C'));
|
|
||||||
$this->assertEqual(
|
|
||||||
$jar->selectAsPairs(new SimpleUrl('another-host.com')),
|
|
||||||
array('b=B', 'c=C'));
|
|
||||||
$this->assertEqual(
|
|
||||||
$jar->selectAsPairs(new SimpleUrl('www.another-host.com')),
|
|
||||||
array('b=B', 'c=C'));
|
|
||||||
$this->assertEqual(
|
|
||||||
$jar->selectAsPairs(new SimpleUrl('new-host.org')),
|
|
||||||
array('c=C'));
|
|
||||||
$this->assertEqual(
|
|
||||||
$jar->selectAsPairs(new SimpleUrl('/')),
|
|
||||||
array('a=A', 'b=B', 'c=C'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testPathFilter() {
|
|
||||||
$jar = new SimpleCookieJar();
|
|
||||||
$jar->setCookie('a', 'A', false, '/path/');
|
|
||||||
$this->assertEqual($jar->selectAsPairs(new SimpleUrl('/')), array());
|
|
||||||
$this->assertEqual($jar->selectAsPairs(new SimpleUrl('/elsewhere')), array());
|
|
||||||
$this->assertEqual($jar->selectAsPairs(new SimpleUrl('/path/')), array('a=A'));
|
|
||||||
$this->assertEqual($jar->selectAsPairs(new SimpleUrl('/path')), array('a=A'));
|
|
||||||
$this->assertEqual($jar->selectAsPairs(new SimpleUrl('/pa')), array());
|
|
||||||
$this->assertEqual($jar->selectAsPairs(new SimpleUrl('/path/here')), array('a=A'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testPathFilterDeeply() {
|
|
||||||
$jar = new SimpleCookieJar();
|
|
||||||
$jar->setCookie('a', 'A', false, '/path/more_path/');
|
|
||||||
$this->assertEqual($jar->selectAsPairs(new SimpleUrl('/path/')), array());
|
|
||||||
$this->assertEqual($jar->selectAsPairs(new SimpleUrl('/path')), array());
|
|
||||||
$this->assertEqual($jar->selectAsPairs(new SimpleUrl('/pa')), array());
|
|
||||||
$this->assertEqual($jar->selectAsPairs(new SimpleUrl('/path/more_path/')), array('a=A'));
|
|
||||||
$this->assertEqual($jar->selectAsPairs(new SimpleUrl('/path/more_path/and_more')), array('a=A'));
|
|
||||||
$this->assertEqual($jar->selectAsPairs(new SimpleUrl('/path/not_here/')), array());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMultipleCookieWithDifferentPathsButSameName() {
|
|
||||||
$jar = new SimpleCookieJar();
|
|
||||||
$jar->setCookie('a', 'abc', false, '/');
|
|
||||||
$jar->setCookie('a', '123', false, '/path/here/');
|
|
||||||
$this->assertEqual(
|
|
||||||
$jar->selectAsPairs(new SimpleUrl('/')),
|
|
||||||
array('a=abc'));
|
|
||||||
$this->assertEqual(
|
|
||||||
$jar->selectAsPairs(new SimpleUrl('my-host.com/')),
|
|
||||||
array('a=abc'));
|
|
||||||
$this->assertEqual(
|
|
||||||
$jar->selectAsPairs(new SimpleUrl('my-host.com/path/')),
|
|
||||||
array('a=abc'));
|
|
||||||
$this->assertEqual(
|
|
||||||
$jar->selectAsPairs(new SimpleUrl('my-host.com/path/here')),
|
|
||||||
array('a=abc', 'a=123'));
|
|
||||||
$this->assertEqual(
|
|
||||||
$jar->selectAsPairs(new SimpleUrl('my-host.com/path/here/there')),
|
|
||||||
array('a=abc', 'a=123'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testOverwrite() {
|
|
||||||
$jar = new SimpleCookieJar();
|
|
||||||
$jar->setCookie('a', 'abc', false, '/');
|
|
||||||
$jar->setCookie('a', 'cde', false, '/');
|
|
||||||
$this->assertEqual($jar->selectAsPairs(new SimpleUrl('/')), array('a=cde'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testClearSessionCookies() {
|
|
||||||
$jar = new SimpleCookieJar();
|
|
||||||
$jar->setCookie('a', 'A', false, '/');
|
|
||||||
$jar->restartSession();
|
|
||||||
$this->assertEqual($jar->selectAsPairs(new SimpleUrl('/')), array());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testExpiryFilterByDate() {
|
|
||||||
$jar = new SimpleCookieJar();
|
|
||||||
$jar->setCookie('a', 'A', false, '/', 'Wed, 25-Dec-02 04:24:20 GMT');
|
|
||||||
$jar->restartSession("Wed, 25-Dec-02 04:24:19 GMT");
|
|
||||||
$this->assertEqual($jar->selectAsPairs(new SimpleUrl('/')), array('a=A'));
|
|
||||||
$jar->restartSession("Wed, 25-Dec-02 04:24:21 GMT");
|
|
||||||
$this->assertEqual($jar->selectAsPairs(new SimpleUrl('/')), array());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testExpiryFilterByAgeing() {
|
|
||||||
$jar = new SimpleCookieJar();
|
|
||||||
$jar->setCookie('a', 'A', false, '/', 'Wed, 25-Dec-02 04:24:20 GMT');
|
|
||||||
$jar->restartSession("Wed, 25-Dec-02 04:24:19 GMT");
|
|
||||||
$this->assertEqual($jar->selectAsPairs(new SimpleUrl('/')), array('a=A'));
|
|
||||||
$jar->agePrematurely(2);
|
|
||||||
$jar->restartSession("Wed, 25-Dec-02 04:24:19 GMT");
|
|
||||||
$this->assertEqual($jar->selectAsPairs(new SimpleUrl('/')), array());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCookieClearing() {
|
|
||||||
$jar = new SimpleCookieJar();
|
|
||||||
$jar->setCookie('a', 'abc', false, '/');
|
|
||||||
$jar->setCookie('a', '', false, '/');
|
|
||||||
$this->assertEqual($jar->selectAsPairs(new SimpleUrl('/')), array('a='));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCookieClearByLoweringDate() {
|
|
||||||
$jar = new SimpleCookieJar();
|
|
||||||
$jar->setCookie('a', 'abc', false, '/', 'Wed, 25-Dec-02 04:24:21 GMT');
|
|
||||||
$jar->setCookie('a', 'def', false, '/', 'Wed, 25-Dec-02 04:24:19 GMT');
|
|
||||||
$this->assertEqual($jar->selectAsPairs(new SimpleUrl('/')), array('a=def'));
|
|
||||||
$jar->restartSession('Wed, 25-Dec-02 04:24:20 GMT');
|
|
||||||
$this->assertEqual($jar->selectAsPairs(new SimpleUrl('/')), array());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,15 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: detached_test.php 1884 2009-07-01 16:30:40Z lastcraft $
|
|
||||||
require_once('../detached.php');
|
|
||||||
require_once('../reporter.php');
|
|
||||||
|
|
||||||
// The following URL will depend on your own installation.
|
|
||||||
$command = 'php ' . dirname(__FILE__) . '/visual_test.php xml';
|
|
||||||
|
|
||||||
$test = new TestSuite('Remote tests');
|
|
||||||
$test->add(new DetachedTestCase($command));
|
|
||||||
if (SimpleReporter::inCli()) {
|
|
||||||
exit ($test->run(new TextReporter()) ? 0 : 1);
|
|
||||||
}
|
|
||||||
$test->run(new HtmlReporter());
|
|
||||||
?>
|
|
|
@ -1,88 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: dumper_test.php 1505 2007-04-30 23:39:59Z lastcraft $
|
|
||||||
require_once(dirname(__FILE__) . '/../autorun.php');
|
|
||||||
|
|
||||||
class DumperDummy {
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfTextFormatting extends UnitTestCase {
|
|
||||||
|
|
||||||
function testClipping() {
|
|
||||||
$dumper = new SimpleDumper();
|
|
||||||
$this->assertEqual(
|
|
||||||
$dumper->clipString("Hello", 6),
|
|
||||||
"Hello",
|
|
||||||
"Hello, 6->%s");
|
|
||||||
$this->assertEqual(
|
|
||||||
$dumper->clipString("Hello", 5),
|
|
||||||
"Hello",
|
|
||||||
"Hello, 5->%s");
|
|
||||||
$this->assertEqual(
|
|
||||||
$dumper->clipString("Hello world", 3),
|
|
||||||
"Hel...",
|
|
||||||
"Hello world, 3->%s");
|
|
||||||
$this->assertEqual(
|
|
||||||
$dumper->clipString("Hello world", 6, 3),
|
|
||||||
"Hello ...",
|
|
||||||
"Hello world, 6, 3->%s");
|
|
||||||
$this->assertEqual(
|
|
||||||
$dumper->clipString("Hello world", 3, 6),
|
|
||||||
"...o w...",
|
|
||||||
"Hello world, 3, 6->%s");
|
|
||||||
$this->assertEqual(
|
|
||||||
$dumper->clipString("Hello world", 4, 11),
|
|
||||||
"...orld",
|
|
||||||
"Hello world, 4, 11->%s");
|
|
||||||
$this->assertEqual(
|
|
||||||
$dumper->clipString("Hello world", 4, 12),
|
|
||||||
"...orld",
|
|
||||||
"Hello world, 4, 12->%s");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testDescribeNull() {
|
|
||||||
$dumper = new SimpleDumper();
|
|
||||||
$this->assertPattern('/null/i', $dumper->describeValue(null));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testDescribeBoolean() {
|
|
||||||
$dumper = new SimpleDumper();
|
|
||||||
$this->assertPattern('/boolean/i', $dumper->describeValue(true));
|
|
||||||
$this->assertPattern('/true/i', $dumper->describeValue(true));
|
|
||||||
$this->assertPattern('/false/i', $dumper->describeValue(false));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testDescribeString() {
|
|
||||||
$dumper = new SimpleDumper();
|
|
||||||
$this->assertPattern('/string/i', $dumper->describeValue('Hello'));
|
|
||||||
$this->assertPattern('/Hello/', $dumper->describeValue('Hello'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testDescribeInteger() {
|
|
||||||
$dumper = new SimpleDumper();
|
|
||||||
$this->assertPattern('/integer/i', $dumper->describeValue(35));
|
|
||||||
$this->assertPattern('/35/', $dumper->describeValue(35));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testDescribeFloat() {
|
|
||||||
$dumper = new SimpleDumper();
|
|
||||||
$this->assertPattern('/float/i', $dumper->describeValue(0.99));
|
|
||||||
$this->assertPattern('/0\.99/', $dumper->describeValue(0.99));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testDescribeArray() {
|
|
||||||
$dumper = new SimpleDumper();
|
|
||||||
$this->assertPattern('/array/i', $dumper->describeValue(array(1, 4)));
|
|
||||||
$this->assertPattern('/2/i', $dumper->describeValue(array(1, 4)));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testDescribeObject() {
|
|
||||||
$dumper = new SimpleDumper();
|
|
||||||
$this->assertPattern(
|
|
||||||
'/object/i',
|
|
||||||
$dumper->describeValue(new DumperDummy()));
|
|
||||||
$this->assertPattern(
|
|
||||||
'/DumperDummy/i',
|
|
||||||
$dumper->describeValue(new DumperDummy()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,32 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: eclipse_test.php 1739 2008-04-09 20:48:37Z edwardzyang $
|
|
||||||
|
|
||||||
//To run this from the eclipse plugin...you need to make sure that the
|
|
||||||
//SimpleTest path in the preferences is the same as the location of the
|
|
||||||
//eclipse.php file below otherwise you end up with two "different" eclipse.php
|
|
||||||
//files included and that does not work...
|
|
||||||
|
|
||||||
include_once(dirname(__FILE__) . '/../eclipse.php');
|
|
||||||
Mock::generate('SimpleSocket');
|
|
||||||
|
|
||||||
class TestOfEclipse extends UnitTestCase {
|
|
||||||
|
|
||||||
function testPass() {
|
|
||||||
$listener = &new MockSimpleSocket();
|
|
||||||
|
|
||||||
$fullpath = realpath(dirname(__FILE__).'/support/test1.php');
|
|
||||||
$testpath = EclipseReporter::escapeVal($fullpath);
|
|
||||||
$expected = "{status:\"pass\",message:\"pass1 at [$testpath line 4]\",group:\"$testpath\",case:\"test1\",method:\"test_pass\"}";
|
|
||||||
//this should work...but it doesn't so the next line and the last line are the hacks
|
|
||||||
//$listener->expectOnce('write',array($expected));
|
|
||||||
$listener->setReturnValue('write',-1);
|
|
||||||
|
|
||||||
$pathparts = pathinfo($fullpath);
|
|
||||||
$filename = $pathparts['basename'];
|
|
||||||
$test= &new TestSuite($filename);
|
|
||||||
$test->addTestFile($fullpath);
|
|
||||||
$test->run(new EclipseReporter($listener));
|
|
||||||
$this->assertEqual($expected,$listener->output);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,240 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: encoding_test.php 1963 2009-10-07 11:57:52Z maetl_ $
|
|
||||||
require_once(dirname(__FILE__) . '/../autorun.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../url.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../socket.php');
|
|
||||||
|
|
||||||
Mock::generate('SimpleSocket');
|
|
||||||
|
|
||||||
class TestOfEncodedParts extends UnitTestCase {
|
|
||||||
|
|
||||||
function testFormEncodedAsKeyEqualsValue() {
|
|
||||||
$pair = new SimpleEncodedPair('a', 'A');
|
|
||||||
$this->assertEqual($pair->asRequest(), 'a=A');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMimeEncodedAsHeadersAndContent() {
|
|
||||||
$pair = new SimpleEncodedPair('a', 'A');
|
|
||||||
$this->assertEqual(
|
|
||||||
$pair->asMime(),
|
|
||||||
"Content-Disposition: form-data; name=\"a\"\r\n\r\nA");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testAttachmentEncodedAsHeadersWithDispositionAndContent() {
|
|
||||||
$part = new SimpleAttachment('a', 'A', 'aaa.txt');
|
|
||||||
$this->assertEqual(
|
|
||||||
$part->asMime(),
|
|
||||||
"Content-Disposition: form-data; name=\"a\"; filename=\"aaa.txt\"\r\n" .
|
|
||||||
"Content-Type: text/plain\r\n\r\nA");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfEncoding extends UnitTestCase {
|
|
||||||
private $content_so_far;
|
|
||||||
|
|
||||||
function write($content) {
|
|
||||||
$this->content_so_far .= $content;
|
|
||||||
}
|
|
||||||
|
|
||||||
function clear() {
|
|
||||||
$this->content_so_far = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
function assertWritten($encoding, $content, $message = '%s') {
|
|
||||||
$this->clear();
|
|
||||||
$encoding->writeTo($this);
|
|
||||||
$this->assertIdentical($this->content_so_far, $content, $message);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testGetEmpty() {
|
|
||||||
$encoding = new SimpleGetEncoding();
|
|
||||||
$this->assertIdentical($encoding->getValue('a'), false);
|
|
||||||
$this->assertIdentical($encoding->asUrlRequest(), '');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testPostEmpty() {
|
|
||||||
$encoding = new SimplePostEncoding();
|
|
||||||
$this->assertIdentical($encoding->getValue('a'), false);
|
|
||||||
$this->assertWritten($encoding, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testPrefilled() {
|
|
||||||
$encoding = new SimplePostEncoding(array('a' => 'aaa'));
|
|
||||||
$this->assertIdentical($encoding->getValue('a'), 'aaa');
|
|
||||||
$this->assertWritten($encoding, 'a=aaa');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testPrefilledWithTwoLevels() {
|
|
||||||
$query = array('a' => array('aa' => 'aaa'));
|
|
||||||
$encoding = new SimplePostEncoding($query);
|
|
||||||
$this->assertTrue($encoding->hasMoreThanOneLevel($query));
|
|
||||||
$this->assertEqual($encoding->rewriteArrayWithMultipleLevels($query), array('a[aa]' => 'aaa'));
|
|
||||||
$this->assertIdentical($encoding->getValue('a[aa]'), 'aaa');
|
|
||||||
$this->assertWritten($encoding, 'a%5Baa%5D=aaa');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testPrefilledWithThreeLevels() {
|
|
||||||
$query = array('a' => array('aa' => array('aaa' => 'aaaa')));
|
|
||||||
$encoding = new SimplePostEncoding($query);
|
|
||||||
$this->assertTrue($encoding->hasMoreThanOneLevel($query));
|
|
||||||
$this->assertEqual($encoding->rewriteArrayWithMultipleLevels($query), array('a[aa][aaa]' => 'aaaa'));
|
|
||||||
$this->assertIdentical($encoding->getValue('a[aa][aaa]'), 'aaaa');
|
|
||||||
$this->assertWritten($encoding, 'a%5Baa%5D%5Baaa%5D=aaaa');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testPrefilledWithObject() {
|
|
||||||
$encoding = new SimplePostEncoding(new SimpleEncoding(array('a' => 'aaa')));
|
|
||||||
$this->assertIdentical($encoding->getValue('a'), 'aaa');
|
|
||||||
$this->assertWritten($encoding, 'a=aaa');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMultiplePrefilled() {
|
|
||||||
$query = array('a' => array('a1', 'a2'));
|
|
||||||
$encoding = new SimplePostEncoding($query);
|
|
||||||
$this->assertTrue($encoding->hasMoreThanOneLevel($query));
|
|
||||||
$this->assertEqual($encoding->rewriteArrayWithMultipleLevels($query), array('a[0]' => 'a1', 'a[1]' => 'a2'));
|
|
||||||
$this->assertIdentical($encoding->getValue('a[0]'), 'a1');
|
|
||||||
$this->assertIdentical($encoding->getValue('a[1]'), 'a2');
|
|
||||||
$this->assertWritten($encoding, 'a%5B0%5D=a1&a%5B1%5D=a2');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSingleParameter() {
|
|
||||||
$encoding = new SimplePostEncoding();
|
|
||||||
$encoding->add('a', 'Hello');
|
|
||||||
$this->assertEqual($encoding->getValue('a'), 'Hello');
|
|
||||||
$this->assertWritten($encoding, 'a=Hello');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFalseParameter() {
|
|
||||||
$encoding = new SimplePostEncoding();
|
|
||||||
$encoding->add('a', false);
|
|
||||||
$this->assertEqual($encoding->getValue('a'), false);
|
|
||||||
$this->assertWritten($encoding, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testUrlEncoding() {
|
|
||||||
$encoding = new SimplePostEncoding();
|
|
||||||
$encoding->add('a', 'Hello there!');
|
|
||||||
$this->assertWritten($encoding, 'a=Hello+there%21');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testUrlEncodingOfKey() {
|
|
||||||
$encoding = new SimplePostEncoding();
|
|
||||||
$encoding->add('a!', 'Hello');
|
|
||||||
$this->assertWritten($encoding, 'a%21=Hello');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMultipleParameter() {
|
|
||||||
$encoding = new SimplePostEncoding();
|
|
||||||
$encoding->add('a', 'Hello');
|
|
||||||
$encoding->add('b', 'Goodbye');
|
|
||||||
$this->assertWritten($encoding, 'a=Hello&b=Goodbye');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testEmptyParameters() {
|
|
||||||
$encoding = new SimplePostEncoding();
|
|
||||||
$encoding->add('a', '');
|
|
||||||
$encoding->add('b', '');
|
|
||||||
$this->assertWritten($encoding, 'a=&b=');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testRepeatedParameter() {
|
|
||||||
$encoding = new SimplePostEncoding();
|
|
||||||
$encoding->add('a', 'Hello');
|
|
||||||
$encoding->add('a', 'Goodbye');
|
|
||||||
$this->assertIdentical($encoding->getValue('a'), array('Hello', 'Goodbye'));
|
|
||||||
$this->assertWritten($encoding, 'a=Hello&a=Goodbye');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testAddingLists() {
|
|
||||||
$encoding = new SimplePostEncoding();
|
|
||||||
$encoding->add('a', array('Hello', 'Goodbye'));
|
|
||||||
$this->assertIdentical($encoding->getValue('a'), array('Hello', 'Goodbye'));
|
|
||||||
$this->assertWritten($encoding, 'a=Hello&a=Goodbye');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMergeInHash() {
|
|
||||||
$encoding = new SimpleGetEncoding(array('a' => 'A1', 'b' => 'B'));
|
|
||||||
$encoding->merge(array('a' => 'A2'));
|
|
||||||
$this->assertIdentical($encoding->getValue('a'), array('A1', 'A2'));
|
|
||||||
$this->assertIdentical($encoding->getValue('b'), 'B');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMergeInObject() {
|
|
||||||
$encoding = new SimpleGetEncoding(array('a' => 'A1', 'b' => 'B'));
|
|
||||||
$encoding->merge(new SimpleEncoding(array('a' => 'A2')));
|
|
||||||
$this->assertIdentical($encoding->getValue('a'), array('A1', 'A2'));
|
|
||||||
$this->assertIdentical($encoding->getValue('b'), 'B');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testPrefilledMultipart() {
|
|
||||||
$encoding = new SimpleMultipartEncoding(array('a' => 'aaa'), 'boundary');
|
|
||||||
$this->assertIdentical($encoding->getValue('a'), 'aaa');
|
|
||||||
$this->assertwritten($encoding,
|
|
||||||
"--boundary\r\n" .
|
|
||||||
"Content-Disposition: form-data; name=\"a\"\r\n" .
|
|
||||||
"\r\n" .
|
|
||||||
"aaa\r\n" .
|
|
||||||
"--boundary--\r\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testAttachment() {
|
|
||||||
$encoding = new SimpleMultipartEncoding(array(), 'boundary');
|
|
||||||
$encoding->attach('a', 'aaa', 'aaa.txt');
|
|
||||||
$this->assertIdentical($encoding->getValue('a'), 'aaa.txt');
|
|
||||||
$this->assertwritten($encoding,
|
|
||||||
"--boundary\r\n" .
|
|
||||||
"Content-Disposition: form-data; name=\"a\"; filename=\"aaa.txt\"\r\n" .
|
|
||||||
"Content-Type: text/plain\r\n" .
|
|
||||||
"\r\n" .
|
|
||||||
"aaa\r\n" .
|
|
||||||
"--boundary--\r\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testEntityEncodingDefaultContentType() {
|
|
||||||
$encoding = new SimpleEntityEncoding();
|
|
||||||
$this->assertIdentical($encoding->getContentType(), 'application/x-www-form-urlencoded');
|
|
||||||
$this->assertWritten($encoding, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testEntityEncodingTextBody() {
|
|
||||||
$encoding = new SimpleEntityEncoding('plain text');
|
|
||||||
$this->assertIdentical($encoding->getContentType(), 'text/plain');
|
|
||||||
$this->assertWritten($encoding, 'plain text');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testEntityEncodingXmlBody() {
|
|
||||||
$encoding = new SimpleEntityEncoding('<p><a>xml</b><b>text</b></p>', 'text/xml');
|
|
||||||
$this->assertIdentical($encoding->getContentType(), 'text/xml');
|
|
||||||
$this->assertWritten($encoding, '<p><a>xml</b><b>text</b></p>');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfEncodingHeaders extends UnitTestCase {
|
|
||||||
|
|
||||||
function testEmptyEncodingWritesZeroContentLength() {
|
|
||||||
$socket = new MockSimpleSocket();
|
|
||||||
$socket->expectAt(0, 'write', array("Content-Length: 0\r\n"));
|
|
||||||
$socket->expectAt(1, 'write', array("Content-Type: application/x-www-form-urlencoded\r\n"));
|
|
||||||
$encoding = new SimpleEntityEncoding();
|
|
||||||
$encoding->writeHeadersTo($socket);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testTextEncodingWritesDefaultContentType() {
|
|
||||||
$socket = new MockSimpleSocket();
|
|
||||||
$socket->expectAt(0, 'write', array("Content-Length: 18\r\n"));
|
|
||||||
$socket->expectAt(1, 'write', array("Content-Type: text/plain\r\n"));
|
|
||||||
$encoding = new SimpleEntityEncoding('one two three four');
|
|
||||||
$encoding->writeHeadersTo($socket);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testEmptyMultipartEncodingWritesEndBoundaryContentLength() {
|
|
||||||
$socket = new MockSimpleSocket();
|
|
||||||
$socket->expectAt(0, 'write', array("Content-Length: 14\r\n"));
|
|
||||||
$socket->expectAt(1, 'write', array("Content-Type: multipart/form-data; boundary=boundary\r\n"));
|
|
||||||
$encoding = new SimpleMultipartEncoding(array(), 'boundary');
|
|
||||||
$encoding->writeHeadersTo($socket);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,229 +0,0 @@
|
||||||
<?php
|
|
||||||
require_once(dirname(__FILE__) . '/../autorun.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../errors.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../expectation.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../test_case.php');
|
|
||||||
Mock::generate('SimpleTestCase');
|
|
||||||
Mock::generate('SimpleExpectation');
|
|
||||||
SimpleTest::ignore('MockSimpleTestCase');
|
|
||||||
|
|
||||||
class TestOfErrorQueue extends UnitTestCase {
|
|
||||||
|
|
||||||
function setUp() {
|
|
||||||
$context = SimpleTest::getContext();
|
|
||||||
$queue = $context->get('SimpleErrorQueue');
|
|
||||||
$queue->clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
function tearDown() {
|
|
||||||
$context = SimpleTest::getContext();
|
|
||||||
$queue = $context->get('SimpleErrorQueue');
|
|
||||||
$queue->clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
function testExpectationMatchCancelsIncomingError() {
|
|
||||||
$test = new MockSimpleTestCase();
|
|
||||||
$test->expectOnce('assert', array(
|
|
||||||
new IdenticalExpectation(new AnythingExpectation()),
|
|
||||||
'B',
|
|
||||||
'a message'));
|
|
||||||
$test->setReturnValue('assert', true);
|
|
||||||
$test->expectNever('error');
|
|
||||||
$queue = new SimpleErrorQueue();
|
|
||||||
$queue->setTestCase($test);
|
|
||||||
$queue->expectError(new AnythingExpectation(), 'a message');
|
|
||||||
$queue->add(1024, 'B', 'b.php', 100);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfErrorTrap extends UnitTestCase {
|
|
||||||
private $old;
|
|
||||||
|
|
||||||
function setUp() {
|
|
||||||
$this->old = error_reporting(E_ALL);
|
|
||||||
set_error_handler('SimpleTestErrorHandler');
|
|
||||||
}
|
|
||||||
|
|
||||||
function tearDown() {
|
|
||||||
restore_error_handler();
|
|
||||||
error_reporting($this->old);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testQueueStartsEmpty() {
|
|
||||||
$context = SimpleTest::getContext();
|
|
||||||
$queue = $context->get('SimpleErrorQueue');
|
|
||||||
$this->assertFalse($queue->extract());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testErrorsAreSwallowedByMatchingExpectation() {
|
|
||||||
$this->expectError('Ouch!');
|
|
||||||
trigger_error('Ouch!');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testErrorsAreSwallowedInOrder() {
|
|
||||||
$this->expectError('a');
|
|
||||||
$this->expectError('b');
|
|
||||||
trigger_error('a');
|
|
||||||
trigger_error('b');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testAnyErrorCanBeSwallowed() {
|
|
||||||
$this->expectError();
|
|
||||||
trigger_error('Ouch!');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testErrorCanBeSwallowedByPatternMatching() {
|
|
||||||
$this->expectError(new PatternExpectation('/ouch/i'));
|
|
||||||
trigger_error('Ouch!');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testErrorWithPercentsPassesWithNoSprintfError() {
|
|
||||||
$this->expectError("%");
|
|
||||||
trigger_error('%');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfErrors extends UnitTestCase {
|
|
||||||
private $old;
|
|
||||||
|
|
||||||
function setUp() {
|
|
||||||
$this->old = error_reporting(E_ALL);
|
|
||||||
}
|
|
||||||
|
|
||||||
function tearDown() {
|
|
||||||
error_reporting($this->old);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testDefaultWhenAllReported() {
|
|
||||||
error_reporting(E_ALL);
|
|
||||||
$this->expectError('Ouch!');
|
|
||||||
trigger_error('Ouch!');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testNoticeWhenReported() {
|
|
||||||
error_reporting(E_ALL);
|
|
||||||
$this->expectError('Ouch!');
|
|
||||||
trigger_error('Ouch!', E_USER_NOTICE);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testWarningWhenReported() {
|
|
||||||
error_reporting(E_ALL);
|
|
||||||
$this->expectError('Ouch!');
|
|
||||||
trigger_error('Ouch!', E_USER_WARNING);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testErrorWhenReported() {
|
|
||||||
error_reporting(E_ALL);
|
|
||||||
$this->expectError('Ouch!');
|
|
||||||
trigger_error('Ouch!', E_USER_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testNoNoticeWhenNotReported() {
|
|
||||||
error_reporting(0);
|
|
||||||
trigger_error('Ouch!', E_USER_NOTICE);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testNoWarningWhenNotReported() {
|
|
||||||
error_reporting(0);
|
|
||||||
trigger_error('Ouch!', E_USER_WARNING);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testNoticeSuppressedWhenReported() {
|
|
||||||
error_reporting(E_ALL);
|
|
||||||
@trigger_error('Ouch!', E_USER_NOTICE);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testWarningSuppressedWhenReported() {
|
|
||||||
error_reporting(E_ALL);
|
|
||||||
@trigger_error('Ouch!', E_USER_WARNING);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testErrorWithPercentsReportedWithNoSprintfError() {
|
|
||||||
$this->expectError('%');
|
|
||||||
trigger_error('%');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfPHP52RecoverableErrors extends UnitTestCase {
|
|
||||||
function skip() {
|
|
||||||
$this->skipIf(
|
|
||||||
version_compare(phpversion(), '5.2', '<'),
|
|
||||||
'E_RECOVERABLE_ERROR not tested for PHP below 5.2');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testError() {
|
|
||||||
eval('
|
|
||||||
class RecoverableErrorTestingStub {
|
|
||||||
function ouch(RecoverableErrorTestingStub $obj) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
');
|
|
||||||
|
|
||||||
$stub = new RecoverableErrorTestingStub();
|
|
||||||
$this->expectError(new PatternExpectation('/must be an instance of RecoverableErrorTestingStub/i'));
|
|
||||||
$stub->ouch(new stdClass());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfErrorsExcludingPHP52AndAbove extends UnitTestCase {
|
|
||||||
function skip() {
|
|
||||||
$this->skipIf(
|
|
||||||
version_compare(phpversion(), '5.2', '>='),
|
|
||||||
'E_USER_ERROR not tested for PHP 5.2 and above');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testNoErrorWhenNotReported() {
|
|
||||||
error_reporting(0);
|
|
||||||
trigger_error('Ouch!', E_USER_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testErrorSuppressedWhenReported() {
|
|
||||||
error_reporting(E_ALL);
|
|
||||||
@trigger_error('Ouch!', E_USER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SimpleTest::ignore('TestOfNotEnoughErrors');
|
|
||||||
/**
|
|
||||||
* This test is ignored as it is used by {@link TestRunnerForLeftOverAndNotEnoughErrors}
|
|
||||||
* to verify that it fails as expected.
|
|
||||||
*
|
|
||||||
* @ignore
|
|
||||||
*/
|
|
||||||
class TestOfNotEnoughErrors extends UnitTestCase {
|
|
||||||
function testExpectTwoErrorsThrowOne() {
|
|
||||||
$this->expectError('Error 1');
|
|
||||||
trigger_error('Error 1');
|
|
||||||
$this->expectError('Error 2');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SimpleTest::ignore('TestOfLeftOverErrors');
|
|
||||||
/**
|
|
||||||
* This test is ignored as it is used by {@link TestRunnerForLeftOverAndNotEnoughErrors}
|
|
||||||
* to verify that it fails as expected.
|
|
||||||
*
|
|
||||||
* @ignore
|
|
||||||
*/
|
|
||||||
class TestOfLeftOverErrors extends UnitTestCase {
|
|
||||||
function testExpectOneErrorGetTwo() {
|
|
||||||
$this->expectError('Error 1');
|
|
||||||
trigger_error('Error 1');
|
|
||||||
trigger_error('Error 2');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestRunnerForLeftOverAndNotEnoughErrors extends UnitTestCase {
|
|
||||||
function testRunLeftOverErrorsTestCase() {
|
|
||||||
$test = new TestOfLeftOverErrors();
|
|
||||||
$this->assertFalse($test->run(new SimpleReporter()));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testRunNotEnoughErrors() {
|
|
||||||
$test = new TestOfNotEnoughErrors();
|
|
||||||
$this->assertFalse($test->run(new SimpleReporter()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Add stacked error handler test
|
|
||||||
?>
|
|
|
@ -1,183 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: exceptions_test.php 1882 2009-07-01 14:30:05Z lastcraft $
|
|
||||||
require_once(dirname(__FILE__) . '/../autorun.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../exceptions.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../expectation.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../test_case.php');
|
|
||||||
Mock::generate('SimpleTestCase');
|
|
||||||
Mock::generate('SimpleExpectation');
|
|
||||||
|
|
||||||
class MyTestException extends Exception {}
|
|
||||||
class HigherTestException extends MyTestException {}
|
|
||||||
class OtherTestException extends Exception {}
|
|
||||||
|
|
||||||
class TestOfExceptionExpectation extends UnitTestCase {
|
|
||||||
|
|
||||||
function testExceptionClassAsStringWillMatchExceptionsRootedOnThatClass() {
|
|
||||||
$expectation = new ExceptionExpectation('MyTestException');
|
|
||||||
$this->assertTrue($expectation->test(new MyTestException()));
|
|
||||||
$this->assertTrue($expectation->test(new HigherTestException()));
|
|
||||||
$this->assertFalse($expectation->test(new OtherTestException()));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMatchesClassAndMessageWhenExceptionExpected() {
|
|
||||||
$expectation = new ExceptionExpectation(new MyTestException('Hello'));
|
|
||||||
$this->assertTrue($expectation->test(new MyTestException('Hello')));
|
|
||||||
$this->assertFalse($expectation->test(new HigherTestException('Hello')));
|
|
||||||
$this->assertFalse($expectation->test(new OtherTestException('Hello')));
|
|
||||||
$this->assertFalse($expectation->test(new MyTestException('Goodbye')));
|
|
||||||
$this->assertFalse($expectation->test(new MyTestException()));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMessagelessExceptionMatchesOnlyOnClass() {
|
|
||||||
$expectation = new ExceptionExpectation(new MyTestException());
|
|
||||||
$this->assertTrue($expectation->test(new MyTestException()));
|
|
||||||
$this->assertFalse($expectation->test(new HigherTestException()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfExceptionTrap extends UnitTestCase {
|
|
||||||
|
|
||||||
function testNoExceptionsInQueueMeansNoTestMessages() {
|
|
||||||
$test = new MockSimpleTestCase();
|
|
||||||
$test->expectNever('assert');
|
|
||||||
$queue = new SimpleExceptionTrap();
|
|
||||||
$this->assertFalse($queue->isExpected($test, new Exception()));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMatchingExceptionGivesTrue() {
|
|
||||||
$expectation = new MockSimpleExpectation();
|
|
||||||
$expectation->setReturnValue('test', true);
|
|
||||||
$test = new MockSimpleTestCase();
|
|
||||||
$test->setReturnValue('assert', true);
|
|
||||||
$queue = new SimpleExceptionTrap();
|
|
||||||
$queue->expectException($expectation, 'message');
|
|
||||||
$this->assertTrue($queue->isExpected($test, new Exception()));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMatchingExceptionTriggersAssertion() {
|
|
||||||
$test = new MockSimpleTestCase();
|
|
||||||
$test->expectOnce('assert', array(
|
|
||||||
'*',
|
|
||||||
new ExceptionExpectation(new Exception()),
|
|
||||||
'message'));
|
|
||||||
$queue = new SimpleExceptionTrap();
|
|
||||||
$queue->expectException(new ExceptionExpectation(new Exception()), 'message');
|
|
||||||
$queue->isExpected($test, new Exception());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfCatchingExceptions extends UnitTestCase {
|
|
||||||
|
|
||||||
function testCanCatchAnyExpectedException() {
|
|
||||||
$this->expectException();
|
|
||||||
throw new Exception();
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanMatchExceptionByClass() {
|
|
||||||
$this->expectException('MyTestException');
|
|
||||||
throw new HigherTestException();
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanMatchExceptionExactly() {
|
|
||||||
$this->expectException(new Exception('Ouch'));
|
|
||||||
throw new Exception('Ouch');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testLastListedExceptionIsTheOneThatCounts() {
|
|
||||||
$this->expectException('OtherTestException');
|
|
||||||
$this->expectException('MyTestException');
|
|
||||||
throw new HigherTestException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfIgnoringExceptions extends UnitTestCase {
|
|
||||||
|
|
||||||
function testCanIgnoreAnyException() {
|
|
||||||
$this->ignoreException();
|
|
||||||
throw new Exception();
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanIgnoreSpecificException() {
|
|
||||||
$this->ignoreException('MyTestException');
|
|
||||||
throw new MyTestException();
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanIgnoreExceptionExactly() {
|
|
||||||
$this->ignoreException(new Exception('Ouch'));
|
|
||||||
throw new Exception('Ouch');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testIgnoredExceptionsDoNotMaskExpectedExceptions() {
|
|
||||||
$this->ignoreException('Exception');
|
|
||||||
$this->expectException('MyTestException');
|
|
||||||
throw new MyTestException();
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanIgnoreMultipleExceptions() {
|
|
||||||
$this->ignoreException('MyTestException');
|
|
||||||
$this->ignoreException('OtherTestException');
|
|
||||||
throw new OtherTestException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfCallingTearDownAfterExceptions extends UnitTestCase {
|
|
||||||
private $debri = 0;
|
|
||||||
|
|
||||||
function tearDown() {
|
|
||||||
$this->debri--;
|
|
||||||
}
|
|
||||||
|
|
||||||
function testLeaveSomeDebri() {
|
|
||||||
$this->debri++;
|
|
||||||
$this->expectException();
|
|
||||||
throw new Exception(__FUNCTION__);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testDebriWasRemovedOnce() {
|
|
||||||
$this->assertEqual($this->debri, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfExceptionThrownInSetUpDoesNotRunTestBody extends UnitTestCase {
|
|
||||||
|
|
||||||
function setUp() {
|
|
||||||
$this->expectException();
|
|
||||||
throw new Exception();
|
|
||||||
}
|
|
||||||
|
|
||||||
function testShouldNotBeRun() {
|
|
||||||
$this->fail('This test body should not be run');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testShouldNotBeRunEither() {
|
|
||||||
$this->fail('This test body should not be run either');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfExpectExceptionWithSetUp extends UnitTestCase {
|
|
||||||
|
|
||||||
function setUp() {
|
|
||||||
$this->expectException();
|
|
||||||
}
|
|
||||||
|
|
||||||
function testThisExceptionShouldBeCaught() {
|
|
||||||
throw new Exception();
|
|
||||||
}
|
|
||||||
|
|
||||||
function testJustThrowingMyTestException() {
|
|
||||||
throw new MyTestException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfThrowingExceptionsInTearDown extends UnitTestCase {
|
|
||||||
|
|
||||||
function tearDown() {
|
|
||||||
throw new Exception();
|
|
||||||
}
|
|
||||||
|
|
||||||
function testDoesntFatal() {
|
|
||||||
$this->expectException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,317 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: expectation_test.php 2009 2011-04-28 08:57:25Z pp11 $
|
|
||||||
require_once(dirname(__FILE__) . '/../autorun.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../expectation.php');
|
|
||||||
|
|
||||||
class TestOfEquality extends UnitTestCase {
|
|
||||||
|
|
||||||
function testBoolean() {
|
|
||||||
$is_true = new EqualExpectation(true);
|
|
||||||
$this->assertTrue($is_true->test(true));
|
|
||||||
$this->assertFalse($is_true->test(false));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testStringMatch() {
|
|
||||||
$hello = new EqualExpectation("Hello");
|
|
||||||
$this->assertTrue($hello->test("Hello"));
|
|
||||||
$this->assertFalse($hello->test("Goodbye"));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testInteger() {
|
|
||||||
$fifteen = new EqualExpectation(15);
|
|
||||||
$this->assertTrue($fifteen->test(15));
|
|
||||||
$this->assertFalse($fifteen->test(14));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFloat() {
|
|
||||||
$pi = new EqualExpectation(3.14);
|
|
||||||
$this->assertTrue($pi->test(3.14));
|
|
||||||
$this->assertFalse($pi->test(3.15));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testArray() {
|
|
||||||
$colours = new EqualExpectation(array("r", "g", "b"));
|
|
||||||
$this->assertTrue($colours->test(array("r", "g", "b")));
|
|
||||||
$this->assertFalse($colours->test(array("g", "b", "r")));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testHash() {
|
|
||||||
$is_blue = new EqualExpectation(array("r" => 0, "g" => 0, "b" => 255));
|
|
||||||
$this->assertTrue($is_blue->test(array("r" => 0, "g" => 0, "b" => 255)));
|
|
||||||
$this->assertFalse($is_blue->test(array("r" => 0, "g" => 255, "b" => 0)));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testHashWithOutOfOrderKeysShouldStillMatch() {
|
|
||||||
$any_order = new EqualExpectation(array('a' => 1, 'b' => 2));
|
|
||||||
$this->assertTrue($any_order->test(array('b' => 2, 'a' => 1)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfWithin extends UnitTestCase {
|
|
||||||
|
|
||||||
function testWithinFloatingPointMargin() {
|
|
||||||
$within = new WithinMarginExpectation(1.0, 0.2);
|
|
||||||
$this->assertFalse($within->test(0.7));
|
|
||||||
$this->assertTrue($within->test(0.8));
|
|
||||||
$this->assertTrue($within->test(0.9));
|
|
||||||
$this->assertTrue($within->test(1.1));
|
|
||||||
$this->assertTrue($within->test(1.2));
|
|
||||||
$this->assertFalse($within->test(1.3));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testOutsideFloatingPointMargin() {
|
|
||||||
$within = new OutsideMarginExpectation(1.0, 0.2);
|
|
||||||
$this->assertTrue($within->test(0.7));
|
|
||||||
$this->assertFalse($within->test(0.8));
|
|
||||||
$this->assertFalse($within->test(1.2));
|
|
||||||
$this->assertTrue($within->test(1.3));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfInequality extends UnitTestCase {
|
|
||||||
|
|
||||||
function testStringMismatch() {
|
|
||||||
$not_hello = new NotEqualExpectation("Hello");
|
|
||||||
$this->assertTrue($not_hello->test("Goodbye"));
|
|
||||||
$this->assertFalse($not_hello->test("Hello"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class RecursiveNasty {
|
|
||||||
private $me;
|
|
||||||
|
|
||||||
function RecursiveNasty() {
|
|
||||||
$this->me = $this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class OpaqueContainer {
|
|
||||||
private $stuff;
|
|
||||||
private $value;
|
|
||||||
|
|
||||||
public function __construct($value) {
|
|
||||||
$this->value = $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class DerivedOpaqueContainer extends OpaqueContainer {
|
|
||||||
// Deliberately have a variable whose name with the same suffix as a later
|
|
||||||
// variable
|
|
||||||
private $new_value = 1;
|
|
||||||
|
|
||||||
// Deliberately obscures the variable of the same name in the base
|
|
||||||
// class.
|
|
||||||
private $value;
|
|
||||||
|
|
||||||
public function __construct($value, $base_value) {
|
|
||||||
parent::__construct($base_value);
|
|
||||||
$this->value = $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfIdentity extends UnitTestCase {
|
|
||||||
|
|
||||||
function testType() {
|
|
||||||
$string = new IdenticalExpectation("37");
|
|
||||||
$this->assertTrue($string->test("37"));
|
|
||||||
$this->assertFalse($string->test(37));
|
|
||||||
$this->assertFalse($string->test("38"));
|
|
||||||
}
|
|
||||||
|
|
||||||
function _testNastyPhp5Bug() {
|
|
||||||
$this->assertFalse(new RecursiveNasty() != new RecursiveNasty());
|
|
||||||
}
|
|
||||||
|
|
||||||
function _testReallyHorribleRecursiveStructure() {
|
|
||||||
$hopeful = new IdenticalExpectation(new RecursiveNasty());
|
|
||||||
$this->assertTrue($hopeful->test(new RecursiveNasty()));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanComparePrivateMembers() {
|
|
||||||
$expectFive = new IdenticalExpectation(new OpaqueContainer(5));
|
|
||||||
$this->assertTrue($expectFive->test(new OpaqueContainer(5)));
|
|
||||||
$this->assertFalse($expectFive->test(new OpaqueContainer(6)));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanComparePrivateMembersOfObjectsInArrays() {
|
|
||||||
$expectFive = new IdenticalExpectation(array(new OpaqueContainer(5)));
|
|
||||||
$this->assertTrue($expectFive->test(array(new OpaqueContainer(5))));
|
|
||||||
$this->assertFalse($expectFive->test(array(new OpaqueContainer(6))));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanComparePrivateMembersOfObjectsWherePrivateMemberOfBaseClassIsObscured() {
|
|
||||||
$expectFive = new IdenticalExpectation(array(new DerivedOpaqueContainer(1,2)));
|
|
||||||
$this->assertTrue($expectFive->test(array(new DerivedOpaqueContainer(1,2))));
|
|
||||||
$this->assertFalse($expectFive->test(array(new DerivedOpaqueContainer(0,2))));
|
|
||||||
$this->assertFalse($expectFive->test(array(new DerivedOpaqueContainer(0,9))));
|
|
||||||
$this->assertFalse($expectFive->test(array(new DerivedOpaqueContainer(1,0))));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TransparentContainer {
|
|
||||||
public $value;
|
|
||||||
|
|
||||||
public function __construct($value) {
|
|
||||||
$this->value = $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfMemberComparison extends UnitTestCase {
|
|
||||||
|
|
||||||
function testMemberExpectationCanMatchPublicMember() {
|
|
||||||
$expect_five = new MemberExpectation('value', 5);
|
|
||||||
$this->assertTrue($expect_five->test(new TransparentContainer(5)));
|
|
||||||
$this->assertFalse($expect_five->test(new TransparentContainer(8)));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMemberExpectationCanMatchPrivateMember() {
|
|
||||||
$expect_five = new MemberExpectation('value', 5);
|
|
||||||
$this->assertTrue($expect_five->test(new OpaqueContainer(5)));
|
|
||||||
$this->assertFalse($expect_five->test(new OpaqueContainer(8)));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMemberExpectationCanMatchPrivateMemberObscuredByDerivedClass() {
|
|
||||||
$expect_five = new MemberExpectation('value', 5);
|
|
||||||
$this->assertTrue($expect_five->test(new DerivedOpaqueContainer(5,8)));
|
|
||||||
$this->assertTrue($expect_five->test(new DerivedOpaqueContainer(5,5)));
|
|
||||||
$this->assertFalse($expect_five->test(new DerivedOpaqueContainer(8,8)));
|
|
||||||
$this->assertFalse($expect_five->test(new DerivedOpaqueContainer(8,5)));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class DummyReferencedObject{}
|
|
||||||
|
|
||||||
class TestOfReference extends UnitTestCase {
|
|
||||||
|
|
||||||
function testReference() {
|
|
||||||
$foo = "foo";
|
|
||||||
$ref = &$foo;
|
|
||||||
$not_ref = $foo;
|
|
||||||
$bar = "bar";
|
|
||||||
|
|
||||||
$expect = new ReferenceExpectation($foo);
|
|
||||||
$this->assertTrue($expect->test($ref));
|
|
||||||
$this->assertFalse($expect->test($not_ref));
|
|
||||||
$this->assertFalse($expect->test($bar));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfNonIdentity extends UnitTestCase {
|
|
||||||
|
|
||||||
function testType() {
|
|
||||||
$string = new NotIdenticalExpectation("37");
|
|
||||||
$this->assertTrue($string->test("38"));
|
|
||||||
$this->assertTrue($string->test(37));
|
|
||||||
$this->assertFalse($string->test("37"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfPatterns extends UnitTestCase {
|
|
||||||
|
|
||||||
function testWanted() {
|
|
||||||
$pattern = new PatternExpectation('/hello/i');
|
|
||||||
$this->assertTrue($pattern->test("Hello world"));
|
|
||||||
$this->assertFalse($pattern->test("Goodbye world"));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testUnwanted() {
|
|
||||||
$pattern = new NoPatternExpectation('/hello/i');
|
|
||||||
$this->assertFalse($pattern->test("Hello world"));
|
|
||||||
$this->assertTrue($pattern->test("Goodbye world"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ExpectedMethodTarget {
|
|
||||||
function hasThisMethod() {}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfMethodExistence extends UnitTestCase {
|
|
||||||
|
|
||||||
function testHasMethod() {
|
|
||||||
$instance = new ExpectedMethodTarget();
|
|
||||||
$expectation = new MethodExistsExpectation('hasThisMethod');
|
|
||||||
$this->assertTrue($expectation->test($instance));
|
|
||||||
$expectation = new MethodExistsExpectation('doesNotHaveThisMethod');
|
|
||||||
$this->assertFalse($expectation->test($instance));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfIsA extends UnitTestCase {
|
|
||||||
|
|
||||||
function testString() {
|
|
||||||
$expectation = new IsAExpectation('string');
|
|
||||||
$this->assertTrue($expectation->test('Hello'));
|
|
||||||
$this->assertFalse($expectation->test(5));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testBoolean() {
|
|
||||||
$expectation = new IsAExpectation('boolean');
|
|
||||||
$this->assertTrue($expectation->test(true));
|
|
||||||
$this->assertFalse($expectation->test(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testBool() {
|
|
||||||
$expectation = new IsAExpectation('bool');
|
|
||||||
$this->assertTrue($expectation->test(true));
|
|
||||||
$this->assertFalse($expectation->test(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testDouble() {
|
|
||||||
$expectation = new IsAExpectation('double');
|
|
||||||
$this->assertTrue($expectation->test(5.0));
|
|
||||||
$this->assertFalse($expectation->test(5));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFloat() {
|
|
||||||
$expectation = new IsAExpectation('float');
|
|
||||||
$this->assertTrue($expectation->test(5.0));
|
|
||||||
$this->assertFalse($expectation->test(5));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testReal() {
|
|
||||||
$expectation = new IsAExpectation('real');
|
|
||||||
$this->assertTrue($expectation->test(5.0));
|
|
||||||
$this->assertFalse($expectation->test(5));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testInteger() {
|
|
||||||
$expectation = new IsAExpectation('integer');
|
|
||||||
$this->assertTrue($expectation->test(5));
|
|
||||||
$this->assertFalse($expectation->test(5.0));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testInt() {
|
|
||||||
$expectation = new IsAExpectation('int');
|
|
||||||
$this->assertTrue($expectation->test(5));
|
|
||||||
$this->assertFalse($expectation->test(5.0));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testScalar() {
|
|
||||||
$expectation = new IsAExpectation('scalar');
|
|
||||||
$this->assertTrue($expectation->test(5));
|
|
||||||
$this->assertFalse($expectation->test(array(5)));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testNumeric() {
|
|
||||||
$expectation = new IsAExpectation('numeric');
|
|
||||||
$this->assertTrue($expectation->test(5));
|
|
||||||
$this->assertFalse($expectation->test('string'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testNull() {
|
|
||||||
$expectation = new IsAExpectation('null');
|
|
||||||
$this->assertTrue($expectation->test(null));
|
|
||||||
$this->assertFalse($expectation->test('string'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfNotA extends UnitTestCase {
|
|
||||||
|
|
||||||
function testString() {
|
|
||||||
$expectation = new NotAExpectation('string');
|
|
||||||
$this->assertFalse($expectation->test('Hello'));
|
|
||||||
$this->assertTrue($expectation->test(5));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,344 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: form_test.php 1996 2010-07-27 09:11:59Z pp11 $
|
|
||||||
require_once(dirname(__FILE__) . '/../autorun.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../url.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../form.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../page.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../encoding.php');
|
|
||||||
Mock::generate('SimplePage');
|
|
||||||
|
|
||||||
class TestOfForm extends UnitTestCase {
|
|
||||||
|
|
||||||
function page($url, $action = false) {
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$page->returns('getUrl', new SimpleUrl($url));
|
|
||||||
$page->returns('expandUrl', new SimpleUrl($url));
|
|
||||||
return $page;
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFormAttributes() {
|
|
||||||
$tag = new SimpleFormTag(array('method' => 'GET', 'action' => 'here.php', 'id' => '33'));
|
|
||||||
$form = new SimpleForm($tag, $this->page('http://host/a/index.html'));
|
|
||||||
$this->assertEqual($form->getMethod(), 'get');
|
|
||||||
$this->assertIdentical($form->getId(), '33');
|
|
||||||
$this->assertNull($form->getValue(new SimpleByName('a')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testAction() {
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$page->expectOnce('expandUrl', array(new SimpleUrl('here.php')));
|
|
||||||
$page->setReturnValue('expandUrl', new SimpleUrl('http://host/here.php'));
|
|
||||||
$tag = new SimpleFormTag(array('method' => 'GET', 'action' => 'here.php'));
|
|
||||||
$form = new SimpleForm($tag, $page);
|
|
||||||
$this->assertEqual($form->getAction(), new SimpleUrl('http://host/here.php'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testEmptyAction() {
|
|
||||||
$tag = new SimpleFormTag(array('method' => 'GET', 'action' => '', 'id' => '33'));
|
|
||||||
$form = new SimpleForm($tag, $this->page('http://host/a/index.html'));
|
|
||||||
$this->assertEqual(
|
|
||||||
$form->getAction(),
|
|
||||||
new SimpleUrl('http://host/a/index.html'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMissingAction() {
|
|
||||||
$tag = new SimpleFormTag(array('method' => 'GET'));
|
|
||||||
$form = new SimpleForm($tag, $this->page('http://host/a/index.html'));
|
|
||||||
$this->assertEqual(
|
|
||||||
$form->getAction(),
|
|
||||||
new SimpleUrl('http://host/a/index.html'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testRootAction() {
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$page->expectOnce('expandUrl', array(new SimpleUrl('/')));
|
|
||||||
$page->setReturnValue('expandUrl', new SimpleUrl('http://host/'));
|
|
||||||
$tag = new SimpleFormTag(array('method' => 'GET', 'action' => '/'));
|
|
||||||
$form = new SimpleForm($tag, $page);
|
|
||||||
$this->assertEqual(
|
|
||||||
$form->getAction(),
|
|
||||||
new SimpleUrl('http://host/'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testDefaultFrameTargetOnForm() {
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$page->expectOnce('expandUrl', array(new SimpleUrl('here.php')));
|
|
||||||
$page->setReturnValue('expandUrl', new SimpleUrl('http://host/here.php'));
|
|
||||||
$tag = new SimpleFormTag(array('method' => 'GET', 'action' => 'here.php'));
|
|
||||||
$form = new SimpleForm($tag, $page);
|
|
||||||
$form->setDefaultTarget('frame');
|
|
||||||
$expected = new SimpleUrl('http://host/here.php');
|
|
||||||
$expected->setTarget('frame');
|
|
||||||
$this->assertEqual($form->getAction(), $expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testTextWidget() {
|
|
||||||
$form = new SimpleForm(new SimpleFormTag(array()), $this->page('htp://host'));
|
|
||||||
$form->addWidget(new SimpleTextTag(
|
|
||||||
array('name' => 'me', 'type' => 'text', 'value' => 'Myself')));
|
|
||||||
$this->assertIdentical($form->getValue(new SimpleByName('me')), 'Myself');
|
|
||||||
$this->assertTrue($form->setField(new SimpleByName('me'), 'Not me'));
|
|
||||||
$this->assertFalse($form->setField(new SimpleByName('not_present'), 'Not me'));
|
|
||||||
$this->assertIdentical($form->getValue(new SimpleByName('me')), 'Not me');
|
|
||||||
$this->assertNull($form->getValue(new SimpleByName('not_present')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testTextWidgetById() {
|
|
||||||
$form = new SimpleForm(new SimpleFormTag(array()), $this->page('htp://host'));
|
|
||||||
$form->addWidget(new SimpleTextTag(
|
|
||||||
array('name' => 'me', 'type' => 'text', 'value' => 'Myself', 'id' => 50)));
|
|
||||||
$this->assertIdentical($form->getValue(new SimpleById(50)), 'Myself');
|
|
||||||
$this->assertTrue($form->setField(new SimpleById(50), 'Not me'));
|
|
||||||
$this->assertIdentical($form->getValue(new SimpleById(50)), 'Not me');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testTextWidgetByLabel() {
|
|
||||||
$form = new SimpleForm(new SimpleFormTag(array()), $this->page('htp://host'));
|
|
||||||
$widget = new SimpleTextTag(array('name' => 'me', 'type' => 'text', 'value' => 'a'));
|
|
||||||
$form->addWidget($widget);
|
|
||||||
$widget->setLabel('thing');
|
|
||||||
$this->assertIdentical($form->getValue(new SimpleByLabel('thing')), 'a');
|
|
||||||
$this->assertTrue($form->setField(new SimpleByLabel('thing'), 'b'));
|
|
||||||
$this->assertIdentical($form->getValue(new SimpleByLabel('thing')), 'b');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSubmitEmpty() {
|
|
||||||
$form = new SimpleForm(new SimpleFormTag(array()), $this->page('htp://host'));
|
|
||||||
$this->assertIdentical($form->submit(), new SimpleGetEncoding());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSubmitButton() {
|
|
||||||
$form = new SimpleForm(new SimpleFormTag(array()), $this->page('http://host'));
|
|
||||||
$form->addWidget(new SimpleSubmitTag(
|
|
||||||
array('type' => 'submit', 'name' => 'go', 'value' => 'Go!', 'id' => '9')));
|
|
||||||
$this->assertTrue($form->hasSubmit(new SimpleByName('go')));
|
|
||||||
$this->assertEqual($form->getValue(new SimpleByName('go')), 'Go!');
|
|
||||||
$this->assertEqual($form->getValue(new SimpleById(9)), 'Go!');
|
|
||||||
$this->assertEqual(
|
|
||||||
$form->submitButton(new SimpleByName('go')),
|
|
||||||
new SimpleGetEncoding(array('go' => 'Go!')));
|
|
||||||
$this->assertEqual(
|
|
||||||
$form->submitButton(new SimpleByLabel('Go!')),
|
|
||||||
new SimpleGetEncoding(array('go' => 'Go!')));
|
|
||||||
$this->assertEqual(
|
|
||||||
$form->submitButton(new SimpleById(9)),
|
|
||||||
new SimpleGetEncoding(array('go' => 'Go!')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSubmitWithAdditionalParameters() {
|
|
||||||
$form = new SimpleForm(new SimpleFormTag(array()), $this->page('http://host'));
|
|
||||||
$form->addWidget(new SimpleSubmitTag(
|
|
||||||
array('type' => 'submit', 'name' => 'go', 'value' => 'Go!')));
|
|
||||||
$this->assertEqual(
|
|
||||||
$form->submitButton(new SimpleByLabel('Go!'), array('a' => 'A')),
|
|
||||||
new SimpleGetEncoding(array('go' => 'Go!', 'a' => 'A')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSubmitButtonWithLabelOfSubmit() {
|
|
||||||
$form = new SimpleForm(new SimpleFormTag(array()), $this->page('http://host'));
|
|
||||||
$form->addWidget(new SimpleSubmitTag(
|
|
||||||
array('type' => 'submit', 'name' => 'test', 'value' => 'Submit')));
|
|
||||||
$this->assertEqual(
|
|
||||||
$form->submitButton(new SimpleByName('test')),
|
|
||||||
new SimpleGetEncoding(array('test' => 'Submit')));
|
|
||||||
$this->assertEqual(
|
|
||||||
$form->submitButton(new SimpleByLabel('Submit')),
|
|
||||||
new SimpleGetEncoding(array('test' => 'Submit')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSubmitButtonWithWhitespacePaddedLabelOfSubmit() {
|
|
||||||
$form = new SimpleForm(new SimpleFormTag(array()), $this->page('http://host'));
|
|
||||||
$form->addWidget(new SimpleSubmitTag(
|
|
||||||
array('type' => 'submit', 'name' => 'test', 'value' => ' Submit ')));
|
|
||||||
$this->assertEqual(
|
|
||||||
$form->submitButton(new SimpleByLabel('Submit')),
|
|
||||||
new SimpleGetEncoding(array('test' => ' Submit ')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testImageSubmitButton() {
|
|
||||||
$form = new SimpleForm(new SimpleFormTag(array()), $this->page('htp://host'));
|
|
||||||
$form->addWidget(new SimpleImageSubmitTag(array(
|
|
||||||
'type' => 'image',
|
|
||||||
'src' => 'source.jpg',
|
|
||||||
'name' => 'go',
|
|
||||||
'alt' => 'Go!',
|
|
||||||
'id' => '9')));
|
|
||||||
$this->assertTrue($form->hasImage(new SimpleByLabel('Go!')));
|
|
||||||
$this->assertEqual(
|
|
||||||
$form->submitImage(new SimpleByLabel('Go!'), 100, 101),
|
|
||||||
new SimpleGetEncoding(array('go.x' => 100, 'go.y' => 101)));
|
|
||||||
$this->assertTrue($form->hasImage(new SimpleByName('go')));
|
|
||||||
$this->assertEqual(
|
|
||||||
$form->submitImage(new SimpleByName('go'), 100, 101),
|
|
||||||
new SimpleGetEncoding(array('go.x' => 100, 'go.y' => 101)));
|
|
||||||
$this->assertTrue($form->hasImage(new SimpleById(9)));
|
|
||||||
$this->assertEqual(
|
|
||||||
$form->submitImage(new SimpleById(9), 100, 101),
|
|
||||||
new SimpleGetEncoding(array('go.x' => 100, 'go.y' => 101)));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testImageSubmitButtonWithAdditionalData() {
|
|
||||||
$form = new SimpleForm(new SimpleFormTag(array()), $this->page('htp://host'));
|
|
||||||
$form->addWidget(new SimpleImageSubmitTag(array(
|
|
||||||
'type' => 'image',
|
|
||||||
'src' => 'source.jpg',
|
|
||||||
'name' => 'go',
|
|
||||||
'alt' => 'Go!')));
|
|
||||||
$this->assertEqual(
|
|
||||||
$form->submitImage(new SimpleByLabel('Go!'), 100, 101, array('a' => 'A')),
|
|
||||||
new SimpleGetEncoding(array('go.x' => 100, 'go.y' => 101, 'a' => 'A')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testButtonTag() {
|
|
||||||
$form = new SimpleForm(new SimpleFormTag(array()), $this->page('http://host'));
|
|
||||||
$widget = new SimpleButtonTag(
|
|
||||||
array('type' => 'submit', 'name' => 'go', 'value' => 'Go', 'id' => '9'));
|
|
||||||
$widget->addContent('Go!');
|
|
||||||
$form->addWidget($widget);
|
|
||||||
$this->assertTrue($form->hasSubmit(new SimpleByName('go')));
|
|
||||||
$this->assertTrue($form->hasSubmit(new SimpleByLabel('Go!')));
|
|
||||||
$this->assertEqual(
|
|
||||||
$form->submitButton(new SimpleByName('go')),
|
|
||||||
new SimpleGetEncoding(array('go' => 'Go')));
|
|
||||||
$this->assertEqual(
|
|
||||||
$form->submitButton(new SimpleByLabel('Go!')),
|
|
||||||
new SimpleGetEncoding(array('go' => 'Go')));
|
|
||||||
$this->assertEqual(
|
|
||||||
$form->submitButton(new SimpleById(9)),
|
|
||||||
new SimpleGetEncoding(array('go' => 'Go')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMultipleFieldsWithSameNameSubmitted() {
|
|
||||||
$form = new SimpleForm(new SimpleFormTag(array()), $this->page('htp://host'));
|
|
||||||
$input = new SimpleTextTag(array('name' => 'elements[]', 'value' => '1'));
|
|
||||||
$form->addWidget($input);
|
|
||||||
$input = new SimpleTextTag(array('name' => 'elements[]', 'value' => '2'));
|
|
||||||
$form->addWidget($input);
|
|
||||||
$form->setField(new SimpleByLabelOrName('elements[]'), '3', 1);
|
|
||||||
$form->setField(new SimpleByLabelOrName('elements[]'), '4', 2);
|
|
||||||
$submit = $form->submit();
|
|
||||||
$requests = $submit->getAll();
|
|
||||||
$this->assertEqual(count($requests), 2);
|
|
||||||
$this->assertIdentical($requests[0], new SimpleEncodedPair('elements[]', '3'));
|
|
||||||
$this->assertIdentical($requests[1], new SimpleEncodedPair('elements[]', '4'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSingleSelectFieldSubmitted() {
|
|
||||||
$form = new SimpleForm(new SimpleFormTag(array()), $this->page('htp://host'));
|
|
||||||
$select = new SimpleSelectionTag(array('name' => 'a'));
|
|
||||||
$select->addTag(new SimpleOptionTag(
|
|
||||||
array('value' => 'aaa', 'selected' => '')));
|
|
||||||
$form->addWidget($select);
|
|
||||||
$this->assertIdentical(
|
|
||||||
$form->submit(),
|
|
||||||
new SimpleGetEncoding(array('a' => 'aaa')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSingleSelectFieldSubmittedWithPost() {
|
|
||||||
$form = new SimpleForm(new SimpleFormTag(array('method' => 'post')), $this->page('htp://host'));
|
|
||||||
$select = new SimpleSelectionTag(array('name' => 'a'));
|
|
||||||
$select->addTag(new SimpleOptionTag(
|
|
||||||
array('value' => 'aaa', 'selected' => '')));
|
|
||||||
$form->addWidget($select);
|
|
||||||
$this->assertIdentical(
|
|
||||||
$form->submit(),
|
|
||||||
new SimplePostEncoding(array('a' => 'aaa')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testUnchecked() {
|
|
||||||
$form = new SimpleForm(new SimpleFormTag(array()), $this->page('htp://host'));
|
|
||||||
$form->addWidget(new SimpleCheckboxTag(
|
|
||||||
array('name' => 'me', 'type' => 'checkbox')));
|
|
||||||
$this->assertIdentical($form->getValue(new SimpleByName('me')), false);
|
|
||||||
$this->assertTrue($form->setField(new SimpleByName('me'), 'on'));
|
|
||||||
$this->assertEqual($form->getValue(new SimpleByName('me')), 'on');
|
|
||||||
$this->assertFalse($form->setField(new SimpleByName('me'), 'other'));
|
|
||||||
$this->assertEqual($form->getValue(new SimpleByName('me')), 'on');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testChecked() {
|
|
||||||
$form = new SimpleForm(new SimpleFormTag(array()), $this->page('htp://host'));
|
|
||||||
$form->addWidget(new SimpleCheckboxTag(
|
|
||||||
array('name' => 'me', 'value' => 'a', 'type' => 'checkbox', 'checked' => '')));
|
|
||||||
$this->assertIdentical($form->getValue(new SimpleByName('me')), 'a');
|
|
||||||
$this->assertTrue($form->setField(new SimpleByName('me'), 'a'));
|
|
||||||
$this->assertEqual($form->getValue(new SimpleByName('me')), 'a');
|
|
||||||
$this->assertTrue($form->setField(new SimpleByName('me'), false));
|
|
||||||
$this->assertEqual($form->getValue(new SimpleByName('me')), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSingleUncheckedRadioButton() {
|
|
||||||
$form = new SimpleForm(new SimpleFormTag(array()), $this->page('htp://host'));
|
|
||||||
$form->addWidget(new SimpleRadioButtonTag(
|
|
||||||
array('name' => 'me', 'value' => 'a', 'type' => 'radio')));
|
|
||||||
$this->assertIdentical($form->getValue(new SimpleByName('me')), false);
|
|
||||||
$this->assertTrue($form->setField(new SimpleByName('me'), 'a'));
|
|
||||||
$this->assertEqual($form->getValue(new SimpleByName('me')), 'a');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSingleCheckedRadioButton() {
|
|
||||||
$form = new SimpleForm(new SimpleFormTag(array()), $this->page('htp://host'));
|
|
||||||
$form->addWidget(new SimpleRadioButtonTag(
|
|
||||||
array('name' => 'me', 'value' => 'a', 'type' => 'radio', 'checked' => '')));
|
|
||||||
$this->assertIdentical($form->getValue(new SimpleByName('me')), 'a');
|
|
||||||
$this->assertFalse($form->setField(new SimpleByName('me'), 'other'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testUncheckedRadioButtons() {
|
|
||||||
$form = new SimpleForm(new SimpleFormTag(array()), $this->page('htp://host'));
|
|
||||||
$form->addWidget(new SimpleRadioButtonTag(
|
|
||||||
array('name' => 'me', 'value' => 'a', 'type' => 'radio')));
|
|
||||||
$form->addWidget(new SimpleRadioButtonTag(
|
|
||||||
array('name' => 'me', 'value' => 'b', 'type' => 'radio')));
|
|
||||||
$this->assertIdentical($form->getValue(new SimpleByName('me')), false);
|
|
||||||
$this->assertTrue($form->setField(new SimpleByName('me'), 'a'));
|
|
||||||
$this->assertIdentical($form->getValue(new SimpleByName('me')), 'a');
|
|
||||||
$this->assertTrue($form->setField(new SimpleByName('me'), 'b'));
|
|
||||||
$this->assertIdentical($form->getValue(new SimpleByName('me')), 'b');
|
|
||||||
$this->assertFalse($form->setField(new SimpleByName('me'), 'c'));
|
|
||||||
$this->assertIdentical($form->getValue(new SimpleByName('me')), 'b');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCheckedRadioButtons() {
|
|
||||||
$form = new SimpleForm(new SimpleFormTag(array()), $this->page('htp://host'));
|
|
||||||
$form->addWidget(new SimpleRadioButtonTag(
|
|
||||||
array('name' => 'me', 'value' => 'a', 'type' => 'radio')));
|
|
||||||
$form->addWidget(new SimpleRadioButtonTag(
|
|
||||||
array('name' => 'me', 'value' => 'b', 'type' => 'radio', 'checked' => '')));
|
|
||||||
$this->assertIdentical($form->getValue(new SimpleByName('me')), 'b');
|
|
||||||
$this->assertTrue($form->setField(new SimpleByName('me'), 'a'));
|
|
||||||
$this->assertIdentical($form->getValue(new SimpleByName('me')), 'a');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMultipleFieldsWithSameKey() {
|
|
||||||
$form = new SimpleForm(new SimpleFormTag(array()), $this->page('htp://host'));
|
|
||||||
$form->addWidget(new SimpleCheckboxTag(
|
|
||||||
array('name' => 'a', 'type' => 'checkbox', 'value' => 'me')));
|
|
||||||
$form->addWidget(new SimpleCheckboxTag(
|
|
||||||
array('name' => 'a', 'type' => 'checkbox', 'value' => 'you')));
|
|
||||||
$this->assertIdentical($form->getValue(new SimpleByName('a')), false);
|
|
||||||
$this->assertTrue($form->setField(new SimpleByName('a'), 'me'));
|
|
||||||
$this->assertIdentical($form->getValue(new SimpleByName('a')), 'me');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testRemoveGetParamsFromAction() {
|
|
||||||
Mock::generatePartial('SimplePage', 'MockPartialSimplePage', array('getUrl'));
|
|
||||||
$page = new MockPartialSimplePage();
|
|
||||||
$page->returns('getUrl', new SimpleUrl('htp://host/'));
|
|
||||||
|
|
||||||
# Keep GET params in "action", if the form has no widgets
|
|
||||||
$form = new SimpleForm(new SimpleFormTag(array('action'=>'?test=1')), $page);
|
|
||||||
$this->assertEqual($form->getAction()->asString(), 'htp://host/');
|
|
||||||
|
|
||||||
$form = new SimpleForm(new SimpleFormTag(array('action'=>'?test=1')), $page);
|
|
||||||
$form->addWidget(new SimpleTextTag(array('name' => 'me', 'type' => 'text', 'value' => 'a')));
|
|
||||||
$this->assertEqual($form->getAction()->asString(), 'htp://host/');
|
|
||||||
|
|
||||||
$form = new SimpleForm(new SimpleFormTag(array('action'=>'')), $page);
|
|
||||||
$this->assertEqual($form->getAction()->asString(), 'htp://host/');
|
|
||||||
|
|
||||||
$form = new SimpleForm(new SimpleFormTag(array('action'=>'?test=1', 'method'=>'post')), $page);
|
|
||||||
$this->assertEqual($form->getAction()->asString(), 'htp://host/?test=1');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,549 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: frames_test.php 1899 2009-07-28 19:33:42Z lastcraft $
|
|
||||||
require_once(dirname(__FILE__) . '/../autorun.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../tag.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../page.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../frames.php');
|
|
||||||
Mock::generate('SimplePage');
|
|
||||||
Mock::generate('SimpleForm');
|
|
||||||
|
|
||||||
class TestOfFrameset extends UnitTestCase {
|
|
||||||
|
|
||||||
function testTitleReadFromFramesetPage() {
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$page->setReturnValue('getTitle', 'This page');
|
|
||||||
$frameset = new SimpleFrameset($page);
|
|
||||||
$this->assertEqual($frameset->getTitle(), 'This page');
|
|
||||||
}
|
|
||||||
|
|
||||||
function TestHeadersReadFromFramesetByDefault() {
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$page->setReturnValue('getHeaders', 'Header: content');
|
|
||||||
$page->setReturnValue('getMimeType', 'text/xml');
|
|
||||||
$page->setReturnValue('getResponseCode', 401);
|
|
||||||
$page->setReturnValue('getTransportError', 'Could not parse headers');
|
|
||||||
$page->setReturnValue('getAuthentication', 'Basic');
|
|
||||||
$page->setReturnValue('getRealm', 'Safe place');
|
|
||||||
|
|
||||||
$frameset = new SimpleFrameset($page);
|
|
||||||
|
|
||||||
$this->assertIdentical($frameset->getHeaders(), 'Header: content');
|
|
||||||
$this->assertIdentical($frameset->getMimeType(), 'text/xml');
|
|
||||||
$this->assertIdentical($frameset->getResponseCode(), 401);
|
|
||||||
$this->assertIdentical($frameset->getTransportError(), 'Could not parse headers');
|
|
||||||
$this->assertIdentical($frameset->getAuthentication(), 'Basic');
|
|
||||||
$this->assertIdentical($frameset->getRealm(), 'Safe place');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testEmptyFramesetHasNoContent() {
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$page->setReturnValue('getRaw', 'This content');
|
|
||||||
$frameset = new SimpleFrameset($page);
|
|
||||||
$this->assertEqual($frameset->getRaw(), '');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testRawContentIsFromOnlyFrame() {
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$page->expectNever('getRaw');
|
|
||||||
|
|
||||||
$frame = new MockSimplePage();
|
|
||||||
$frame->setReturnValue('getRaw', 'Stuff');
|
|
||||||
|
|
||||||
$frameset = new SimpleFrameset($page);
|
|
||||||
$frameset->addFrame($frame);
|
|
||||||
$this->assertEqual($frameset->getRaw(), 'Stuff');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testRawContentIsFromAllFrames() {
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$page->expectNever('getRaw');
|
|
||||||
|
|
||||||
$frame1 = new MockSimplePage();
|
|
||||||
$frame1->setReturnValue('getRaw', 'Stuff1');
|
|
||||||
|
|
||||||
$frame2 = new MockSimplePage();
|
|
||||||
$frame2->setReturnValue('getRaw', 'Stuff2');
|
|
||||||
|
|
||||||
$frameset = new SimpleFrameset($page);
|
|
||||||
$frameset->addFrame($frame1);
|
|
||||||
$frameset->addFrame($frame2);
|
|
||||||
$this->assertEqual($frameset->getRaw(), 'Stuff1Stuff2');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testTextContentIsFromOnlyFrame() {
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$page->expectNever('getText');
|
|
||||||
|
|
||||||
$frame = new MockSimplePage();
|
|
||||||
$frame->setReturnValue('getText', 'Stuff');
|
|
||||||
|
|
||||||
$frameset = new SimpleFrameset($page);
|
|
||||||
$frameset->addFrame($frame);
|
|
||||||
$this->assertEqual($frameset->getText(), 'Stuff');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testTextContentIsFromAllFrames() {
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$page->expectNever('getText');
|
|
||||||
|
|
||||||
$frame1 = new MockSimplePage();
|
|
||||||
$frame1->setReturnValue('getText', 'Stuff1');
|
|
||||||
|
|
||||||
$frame2 = new MockSimplePage();
|
|
||||||
$frame2->setReturnValue('getText', 'Stuff2');
|
|
||||||
|
|
||||||
$frameset = new SimpleFrameset($page);
|
|
||||||
$frameset->addFrame($frame1);
|
|
||||||
$frameset->addFrame($frame2);
|
|
||||||
$this->assertEqual($frameset->getText(), 'Stuff1 Stuff2');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFieldFoundIsFirstInFramelist() {
|
|
||||||
$frame1 = new MockSimplePage();
|
|
||||||
$frame1->setReturnValue('getField', null);
|
|
||||||
$frame1->expectOnce('getField', array(new SimpleByName('a')));
|
|
||||||
|
|
||||||
$frame2 = new MockSimplePage();
|
|
||||||
$frame2->setReturnValue('getField', 'A');
|
|
||||||
$frame2->expectOnce('getField', array(new SimpleByName('a')));
|
|
||||||
|
|
||||||
$frame3 = new MockSimplePage();
|
|
||||||
$frame3->expectNever('getField');
|
|
||||||
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$frameset = new SimpleFrameset($page);
|
|
||||||
$frameset->addFrame($frame1);
|
|
||||||
$frameset->addFrame($frame2);
|
|
||||||
$frameset->addFrame($frame3);
|
|
||||||
$this->assertIdentical($frameset->getField(new SimpleByName('a')), 'A');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFrameReplacementByIndex() {
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$page->expectNever('getRaw');
|
|
||||||
|
|
||||||
$frame1 = new MockSimplePage();
|
|
||||||
$frame1->setReturnValue('getRaw', 'Stuff1');
|
|
||||||
|
|
||||||
$frame2 = new MockSimplePage();
|
|
||||||
$frame2->setReturnValue('getRaw', 'Stuff2');
|
|
||||||
|
|
||||||
$frameset = new SimpleFrameset($page);
|
|
||||||
$frameset->addFrame($frame1);
|
|
||||||
$frameset->setFrame(array(1), $frame2);
|
|
||||||
$this->assertEqual($frameset->getRaw(), 'Stuff2');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFrameReplacementByName() {
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$page->expectNever('getRaw');
|
|
||||||
|
|
||||||
$frame1 = new MockSimplePage();
|
|
||||||
$frame1->setReturnValue('getRaw', 'Stuff1');
|
|
||||||
|
|
||||||
$frame2 = new MockSimplePage();
|
|
||||||
$frame2->setReturnValue('getRaw', 'Stuff2');
|
|
||||||
|
|
||||||
$frameset = new SimpleFrameset($page);
|
|
||||||
$frameset->addFrame($frame1, 'a');
|
|
||||||
$frameset->setFrame(array('a'), $frame2);
|
|
||||||
$this->assertEqual($frameset->getRaw(), 'Stuff2');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfFrameNavigation extends UnitTestCase {
|
|
||||||
|
|
||||||
function testStartsWithoutFrameFocus() {
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$frameset = new SimpleFrameset($page);
|
|
||||||
$frameset->addFrame(new MockSimplePage());
|
|
||||||
$this->assertFalse($frameset->getFrameFocus());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanFocusOnSingleFrame() {
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$page->expectNever('getRaw');
|
|
||||||
|
|
||||||
$frame = new MockSimplePage();
|
|
||||||
$frame->setReturnValue('getFrameFocus', array());
|
|
||||||
$frame->setReturnValue('getRaw', 'Stuff');
|
|
||||||
|
|
||||||
$frameset = new SimpleFrameset($page);
|
|
||||||
$frameset->addFrame($frame);
|
|
||||||
|
|
||||||
$this->assertFalse($frameset->setFrameFocusByIndex(0));
|
|
||||||
$this->assertTrue($frameset->setFrameFocusByIndex(1));
|
|
||||||
$this->assertEqual($frameset->getRaw(), 'Stuff');
|
|
||||||
$this->assertFalse($frameset->setFrameFocusByIndex(2));
|
|
||||||
$this->assertIdentical($frameset->getFrameFocus(), array(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testContentComesFromFrameInFocus() {
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
|
|
||||||
$frame1 = new MockSimplePage();
|
|
||||||
$frame1->setReturnValue('getRaw', 'Stuff1');
|
|
||||||
$frame1->setReturnValue('getFrameFocus', array());
|
|
||||||
|
|
||||||
$frame2 = new MockSimplePage();
|
|
||||||
$frame2->setReturnValue('getRaw', 'Stuff2');
|
|
||||||
$frame2->setReturnValue('getFrameFocus', array());
|
|
||||||
|
|
||||||
$frameset = new SimpleFrameset($page);
|
|
||||||
$frameset->addFrame($frame1);
|
|
||||||
$frameset->addFrame($frame2);
|
|
||||||
|
|
||||||
$this->assertTrue($frameset->setFrameFocusByIndex(1));
|
|
||||||
$this->assertEqual($frameset->getFrameFocus(), array(1));
|
|
||||||
$this->assertEqual($frameset->getRaw(), 'Stuff1');
|
|
||||||
|
|
||||||
$this->assertTrue($frameset->setFrameFocusByIndex(2));
|
|
||||||
$this->assertEqual($frameset->getFrameFocus(), array(2));
|
|
||||||
$this->assertEqual($frameset->getRaw(), 'Stuff2');
|
|
||||||
|
|
||||||
$this->assertFalse($frameset->setFrameFocusByIndex(3));
|
|
||||||
$this->assertEqual($frameset->getFrameFocus(), array(2));
|
|
||||||
|
|
||||||
$frameset->clearFrameFocus();
|
|
||||||
$this->assertEqual($frameset->getRaw(), 'Stuff1Stuff2');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanFocusByName() {
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
|
|
||||||
$frame1 = new MockSimplePage();
|
|
||||||
$frame1->setReturnValue('getRaw', 'Stuff1');
|
|
||||||
$frame1->setReturnValue('getFrameFocus', array());
|
|
||||||
|
|
||||||
$frame2 = new MockSimplePage();
|
|
||||||
$frame2->setReturnValue('getRaw', 'Stuff2');
|
|
||||||
$frame2->setReturnValue('getFrameFocus', array());
|
|
||||||
|
|
||||||
$frameset = new SimpleFrameset($page);
|
|
||||||
$frameset->addFrame($frame1, 'A');
|
|
||||||
$frameset->addFrame($frame2, 'B');
|
|
||||||
|
|
||||||
$this->assertTrue($frameset->setFrameFocus('A'));
|
|
||||||
$this->assertEqual($frameset->getFrameFocus(), array('A'));
|
|
||||||
$this->assertEqual($frameset->getRaw(), 'Stuff1');
|
|
||||||
|
|
||||||
$this->assertTrue($frameset->setFrameFocusByIndex(2));
|
|
||||||
$this->assertEqual($frameset->getFrameFocus(), array('B'));
|
|
||||||
$this->assertEqual($frameset->getRaw(), 'Stuff2');
|
|
||||||
|
|
||||||
$this->assertFalse($frameset->setFrameFocus('z'));
|
|
||||||
|
|
||||||
$frameset->clearFrameFocus();
|
|
||||||
$this->assertEqual($frameset->getRaw(), 'Stuff1Stuff2');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfFramesetPageInterface extends UnitTestCase {
|
|
||||||
private $page_interface;
|
|
||||||
private $frameset_interface;
|
|
||||||
|
|
||||||
function __construct() {
|
|
||||||
parent::__construct();
|
|
||||||
$this->page_interface = $this->getPageMethods();
|
|
||||||
$this->frameset_interface = $this->getFramesetMethods();
|
|
||||||
}
|
|
||||||
|
|
||||||
function assertListInAnyOrder($list, $expected) {
|
|
||||||
sort($list);
|
|
||||||
sort($expected);
|
|
||||||
$this->assertEqual($list, $expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getPageMethods() {
|
|
||||||
$methods = array();
|
|
||||||
foreach (get_class_methods('SimplePage') as $method) {
|
|
||||||
if (strtolower($method) == strtolower('SimplePage')) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (strtolower($method) == strtolower('getFrameset')) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (strncmp($method, '_', 1) == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (in_array($method, array('setTitle', 'setBase', 'setForms', 'normalise', 'setFrames', 'addLink'))) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$methods[] = $method;
|
|
||||||
}
|
|
||||||
return $methods;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getFramesetMethods() {
|
|
||||||
$methods = array();
|
|
||||||
foreach (get_class_methods('SimpleFrameset') as $method) {
|
|
||||||
if (strtolower($method) == strtolower('SimpleFrameset')) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (strncmp($method, '_', 1) == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (strncmp($method, 'add', 3) == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$methods[] = $method;
|
|
||||||
}
|
|
||||||
return $methods;
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFramsetHasPageInterface() {
|
|
||||||
$difference = array();
|
|
||||||
foreach ($this->page_interface as $method) {
|
|
||||||
if (! in_array($method, $this->frameset_interface)) {
|
|
||||||
$this->fail("No [$method] in Frameset class");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$this->pass('Frameset covers Page interface');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testHeadersReadFromFrameIfInFocus() {
|
|
||||||
$frame = new MockSimplePage();
|
|
||||||
$frame->setReturnValue('getUrl', new SimpleUrl('http://localhost/stuff'));
|
|
||||||
|
|
||||||
$frame->setReturnValue('getRequest', 'POST stuff');
|
|
||||||
$frame->setReturnValue('getMethod', 'POST');
|
|
||||||
$frame->setReturnValue('getRequestData', array('a' => 'A'));
|
|
||||||
$frame->setReturnValue('getHeaders', 'Header: content');
|
|
||||||
$frame->setReturnValue('getMimeType', 'text/xml');
|
|
||||||
$frame->setReturnValue('getResponseCode', 401);
|
|
||||||
$frame->setReturnValue('getTransportError', 'Could not parse headers');
|
|
||||||
$frame->setReturnValue('getAuthentication', 'Basic');
|
|
||||||
$frame->setReturnValue('getRealm', 'Safe place');
|
|
||||||
|
|
||||||
$frameset = new SimpleFrameset(new MockSimplePage());
|
|
||||||
$frameset->addFrame($frame);
|
|
||||||
$frameset->setFrameFocusByIndex(1);
|
|
||||||
|
|
||||||
$url = new SimpleUrl('http://localhost/stuff');
|
|
||||||
$url->setTarget(1);
|
|
||||||
$this->assertIdentical($frameset->getUrl(), $url);
|
|
||||||
|
|
||||||
$this->assertIdentical($frameset->getRequest(), 'POST stuff');
|
|
||||||
$this->assertIdentical($frameset->getMethod(), 'POST');
|
|
||||||
$this->assertIdentical($frameset->getRequestData(), array('a' => 'A'));
|
|
||||||
$this->assertIdentical($frameset->getHeaders(), 'Header: content');
|
|
||||||
$this->assertIdentical($frameset->getMimeType(), 'text/xml');
|
|
||||||
$this->assertIdentical($frameset->getResponseCode(), 401);
|
|
||||||
$this->assertIdentical($frameset->getTransportError(), 'Could not parse headers');
|
|
||||||
$this->assertIdentical($frameset->getAuthentication(), 'Basic');
|
|
||||||
$this->assertIdentical($frameset->getRealm(), 'Safe place');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testUrlsComeFromBothFrames() {
|
|
||||||
$page = new MockSimplePage();
|
|
||||||
$page->expectNever('getUrls');
|
|
||||||
|
|
||||||
$frame1 = new MockSimplePage();
|
|
||||||
$frame1->setReturnValue(
|
|
||||||
'getUrls',
|
|
||||||
array('http://www.lastcraft.com/', 'http://myserver/'));
|
|
||||||
|
|
||||||
$frame2 = new MockSimplePage();
|
|
||||||
$frame2->setReturnValue(
|
|
||||||
'getUrls',
|
|
||||||
array('http://www.lastcraft.com/', 'http://test/'));
|
|
||||||
|
|
||||||
$frameset = new SimpleFrameset($page);
|
|
||||||
$frameset->addFrame($frame1);
|
|
||||||
$frameset->addFrame($frame2);
|
|
||||||
$this->assertListInAnyOrder(
|
|
||||||
$frameset->getUrls(),
|
|
||||||
array('http://www.lastcraft.com/', 'http://myserver/', 'http://test/'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testLabelledUrlsComeFromBothFrames() {
|
|
||||||
$frame1 = new MockSimplePage();
|
|
||||||
$frame1->setReturnValue(
|
|
||||||
'getUrlsByLabel',
|
|
||||||
array(new SimpleUrl('goodbye.php')),
|
|
||||||
array('a'));
|
|
||||||
|
|
||||||
$frame2 = new MockSimplePage();
|
|
||||||
$frame2->setReturnValue(
|
|
||||||
'getUrlsByLabel',
|
|
||||||
array(new SimpleUrl('hello.php')),
|
|
||||||
array('a'));
|
|
||||||
|
|
||||||
$frameset = new SimpleFrameset(new MockSimplePage());
|
|
||||||
$frameset->addFrame($frame1);
|
|
||||||
$frameset->addFrame($frame2, 'Two');
|
|
||||||
|
|
||||||
$expected1 = new SimpleUrl('goodbye.php');
|
|
||||||
$expected1->setTarget(1);
|
|
||||||
$expected2 = new SimpleUrl('hello.php');
|
|
||||||
$expected2->setTarget('Two');
|
|
||||||
$this->assertEqual(
|
|
||||||
$frameset->getUrlsByLabel('a'),
|
|
||||||
array($expected1, $expected2));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testUrlByIdComesFromFirstFrameToRespond() {
|
|
||||||
$frame1 = new MockSimplePage();
|
|
||||||
$frame1->setReturnValue('getUrlById', new SimpleUrl('four.php'), array(4));
|
|
||||||
$frame1->setReturnValue('getUrlById', false, array(5));
|
|
||||||
|
|
||||||
$frame2 = new MockSimplePage();
|
|
||||||
$frame2->setReturnValue('getUrlById', false, array(4));
|
|
||||||
$frame2->setReturnValue('getUrlById', new SimpleUrl('five.php'), array(5));
|
|
||||||
|
|
||||||
$frameset = new SimpleFrameset(new MockSimplePage());
|
|
||||||
$frameset->addFrame($frame1);
|
|
||||||
$frameset->addFrame($frame2);
|
|
||||||
|
|
||||||
$four = new SimpleUrl('four.php');
|
|
||||||
$four->setTarget(1);
|
|
||||||
$this->assertEqual($frameset->getUrlById(4), $four);
|
|
||||||
$five = new SimpleUrl('five.php');
|
|
||||||
$five->setTarget(2);
|
|
||||||
$this->assertEqual($frameset->getUrlById(5), $five);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testReadUrlsFromFrameInFocus() {
|
|
||||||
$frame1 = new MockSimplePage();
|
|
||||||
$frame1->setReturnValue('getUrls', array('a'));
|
|
||||||
$frame1->setReturnValue('getUrlsByLabel', array(new SimpleUrl('l')));
|
|
||||||
$frame1->setReturnValue('getUrlById', new SimpleUrl('i'));
|
|
||||||
|
|
||||||
$frame2 = new MockSimplePage();
|
|
||||||
$frame2->expectNever('getUrls');
|
|
||||||
$frame2->expectNever('getUrlsByLabel');
|
|
||||||
$frame2->expectNever('getUrlById');
|
|
||||||
|
|
||||||
$frameset = new SimpleFrameset(new MockSimplePage());
|
|
||||||
$frameset->addFrame($frame1, 'A');
|
|
||||||
$frameset->addFrame($frame2, 'B');
|
|
||||||
$frameset->setFrameFocus('A');
|
|
||||||
|
|
||||||
$this->assertIdentical($frameset->getUrls(), array('a'));
|
|
||||||
$expected = new SimpleUrl('l');
|
|
||||||
$expected->setTarget('A');
|
|
||||||
$this->assertIdentical($frameset->getUrlsByLabel('label'), array($expected));
|
|
||||||
$expected = new SimpleUrl('i');
|
|
||||||
$expected->setTarget('A');
|
|
||||||
$this->assertIdentical($frameset->getUrlById(99), $expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testReadFrameTaggedUrlsFromFrameInFocus() {
|
|
||||||
$frame = new MockSimplePage();
|
|
||||||
|
|
||||||
$by_label = new SimpleUrl('l');
|
|
||||||
$by_label->setTarget('L');
|
|
||||||
$frame->setReturnValue('getUrlsByLabel', array($by_label));
|
|
||||||
|
|
||||||
$by_id = new SimpleUrl('i');
|
|
||||||
$by_id->setTarget('I');
|
|
||||||
$frame->setReturnValue('getUrlById', $by_id);
|
|
||||||
|
|
||||||
$frameset = new SimpleFrameset(new MockSimplePage());
|
|
||||||
$frameset->addFrame($frame, 'A');
|
|
||||||
$frameset->setFrameFocus('A');
|
|
||||||
|
|
||||||
$this->assertIdentical($frameset->getUrlsByLabel('label'), array($by_label));
|
|
||||||
$this->assertIdentical($frameset->getUrlById(99), $by_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFindingFormsById() {
|
|
||||||
$frame = new MockSimplePage();
|
|
||||||
$form = new MockSimpleForm();
|
|
||||||
$frame->returns('getFormById', $form, array('a'));
|
|
||||||
|
|
||||||
$frameset = new SimpleFrameset(new MockSimplePage());
|
|
||||||
$frameset->addFrame(new MockSimplePage(), 'A');
|
|
||||||
$frameset->addFrame($frame, 'B');
|
|
||||||
$this->assertSame($frameset->getFormById('a'), $form);
|
|
||||||
|
|
||||||
$frameset->setFrameFocus('A');
|
|
||||||
$this->assertNull($frameset->getFormById('a'));
|
|
||||||
|
|
||||||
$frameset->setFrameFocus('B');
|
|
||||||
$this->assertSame($frameset->getFormById('a'), $form);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFindingFormsBySubmit() {
|
|
||||||
$frame = new MockSimplePage();
|
|
||||||
$form = new MockSimpleForm();
|
|
||||||
$frame->returns(
|
|
||||||
'getFormBySubmit',
|
|
||||||
$form,
|
|
||||||
array(new SimpleByLabel('a')));
|
|
||||||
|
|
||||||
$frameset = new SimpleFrameset(new MockSimplePage());
|
|
||||||
$frameset->addFrame(new MockSimplePage(), 'A');
|
|
||||||
$frameset->addFrame($frame, 'B');
|
|
||||||
$this->assertSame($frameset->getFormBySubmit(new SimpleByLabel('a')), $form);
|
|
||||||
|
|
||||||
$frameset->setFrameFocus('A');
|
|
||||||
$this->assertNull($frameset->getFormBySubmit(new SimpleByLabel('a')));
|
|
||||||
|
|
||||||
$frameset->setFrameFocus('B');
|
|
||||||
$this->assertSame($frameset->getFormBySubmit(new SimpleByLabel('a')), $form);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFindingFormsByImage() {
|
|
||||||
$frame = new MockSimplePage();
|
|
||||||
$form = new MockSimpleForm();
|
|
||||||
$frame->returns(
|
|
||||||
'getFormByImage',
|
|
||||||
$form,
|
|
||||||
array(new SimpleByLabel('a')));
|
|
||||||
|
|
||||||
$frameset = new SimpleFrameset(new MockSimplePage());
|
|
||||||
$frameset->addFrame(new MockSimplePage(), 'A');
|
|
||||||
$frameset->addFrame($frame, 'B');
|
|
||||||
$this->assertSame($frameset->getFormByImage(new SimpleByLabel('a')), $form);
|
|
||||||
|
|
||||||
$frameset->setFrameFocus('A');
|
|
||||||
$this->assertNull($frameset->getFormByImage(new SimpleByLabel('a')));
|
|
||||||
|
|
||||||
$frameset->setFrameFocus('B');
|
|
||||||
$this->assertSame($frameset->getFormByImage(new SimpleByLabel('a')), $form);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSettingAllFrameFieldsWhenNoFrameFocus() {
|
|
||||||
$frame1 = new MockSimplePage();
|
|
||||||
$frame1->expectOnce('setField', array(new SimpleById(22), 'A'));
|
|
||||||
|
|
||||||
$frame2 = new MockSimplePage();
|
|
||||||
$frame2->expectOnce('setField', array(new SimpleById(22), 'A'));
|
|
||||||
|
|
||||||
$frameset = new SimpleFrameset(new MockSimplePage());
|
|
||||||
$frameset->addFrame($frame1, 'A');
|
|
||||||
$frameset->addFrame($frame2, 'B');
|
|
||||||
$frameset->setField(new SimpleById(22), 'A');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testOnlySettingFieldFromFocusedFrame() {
|
|
||||||
$frame1 = new MockSimplePage();
|
|
||||||
$frame1->expectOnce('setField', array(new SimpleByLabelOrName('a'), 'A'));
|
|
||||||
|
|
||||||
$frame2 = new MockSimplePage();
|
|
||||||
$frame2->expectNever('setField');
|
|
||||||
|
|
||||||
$frameset = new SimpleFrameset(new MockSimplePage());
|
|
||||||
$frameset->addFrame($frame1, 'A');
|
|
||||||
$frameset->addFrame($frame2, 'B');
|
|
||||||
$frameset->setFrameFocus('A');
|
|
||||||
$frameset->setField(new SimpleByLabelOrName('a'), 'A');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testOnlyGettingFieldFromFocusedFrame() {
|
|
||||||
$frame1 = new MockSimplePage();
|
|
||||||
$frame1->setReturnValue('getField', 'f', array(new SimpleByName('a')));
|
|
||||||
|
|
||||||
$frame2 = new MockSimplePage();
|
|
||||||
$frame2->expectNever('getField');
|
|
||||||
|
|
||||||
$frameset = new SimpleFrameset(new MockSimplePage());
|
|
||||||
$frameset->addFrame($frame1, 'A');
|
|
||||||
$frameset->addFrame($frame2, 'B');
|
|
||||||
$frameset->setFrameFocus('A');
|
|
||||||
$this->assertIdentical($frameset->getField(new SimpleByName('a')), 'f');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,492 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: http_test.php 1964 2009-10-13 15:27:31Z maetl_ $
|
|
||||||
require_once(dirname(__FILE__) . '/../autorun.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../encoding.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../http.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../socket.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../cookies.php');
|
|
||||||
Mock::generate('SimpleSocket');
|
|
||||||
Mock::generate('SimpleCookieJar');
|
|
||||||
Mock::generate('SimpleRoute');
|
|
||||||
Mock::generatePartial(
|
|
||||||
'SimpleRoute',
|
|
||||||
'PartialSimpleRoute',
|
|
||||||
array('createSocket'));
|
|
||||||
Mock::generatePartial(
|
|
||||||
'SimpleProxyRoute',
|
|
||||||
'PartialSimpleProxyRoute',
|
|
||||||
array('createSocket'));
|
|
||||||
|
|
||||||
class TestOfDirectRoute extends UnitTestCase {
|
|
||||||
|
|
||||||
function testDefaultGetRequest() {
|
|
||||||
$socket = new MockSimpleSocket();
|
|
||||||
$socket->expectAt(0, 'write', array("GET /here.html HTTP/1.0\r\n"));
|
|
||||||
$socket->expectAt(1, 'write', array("Host: a.valid.host\r\n"));
|
|
||||||
$socket->expectAt(2, 'write', array("Connection: close\r\n"));
|
|
||||||
$socket->expectCallCount('write', 3);
|
|
||||||
$route = new PartialSimpleRoute();
|
|
||||||
$route->setReturnReference('createSocket', $socket);
|
|
||||||
$route->__construct(new SimpleUrl('http://a.valid.host/here.html'));
|
|
||||||
$this->assertSame($route->createConnection('GET', 15), $socket);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testDefaultPostRequest() {
|
|
||||||
$socket = new MockSimpleSocket();
|
|
||||||
$socket->expectAt(0, 'write', array("POST /here.html HTTP/1.0\r\n"));
|
|
||||||
$socket->expectAt(1, 'write', array("Host: a.valid.host\r\n"));
|
|
||||||
$socket->expectAt(2, 'write', array("Connection: close\r\n"));
|
|
||||||
$socket->expectCallCount('write', 3);
|
|
||||||
$route = new PartialSimpleRoute();
|
|
||||||
$route->setReturnReference('createSocket', $socket);
|
|
||||||
$route->__construct(new SimpleUrl('http://a.valid.host/here.html'));
|
|
||||||
|
|
||||||
$route->createConnection('POST', 15);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testDefaultDeleteRequest() {
|
|
||||||
$socket = new MockSimpleSocket();
|
|
||||||
$socket->expectAt(0, 'write', array("DELETE /here.html HTTP/1.0\r\n"));
|
|
||||||
$socket->expectAt(1, 'write', array("Host: a.valid.host\r\n"));
|
|
||||||
$socket->expectAt(2, 'write', array("Connection: close\r\n"));
|
|
||||||
$socket->expectCallCount('write', 3);
|
|
||||||
$route = new PartialSimpleRoute();
|
|
||||||
$route->setReturnReference('createSocket', $socket);
|
|
||||||
$route->__construct(new SimpleUrl('http://a.valid.host/here.html'));
|
|
||||||
$this->assertSame($route->createConnection('DELETE', 15), $socket);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testDefaultHeadRequest() {
|
|
||||||
$socket = new MockSimpleSocket();
|
|
||||||
$socket->expectAt(0, 'write', array("HEAD /here.html HTTP/1.0\r\n"));
|
|
||||||
$socket->expectAt(1, 'write', array("Host: a.valid.host\r\n"));
|
|
||||||
$socket->expectAt(2, 'write', array("Connection: close\r\n"));
|
|
||||||
$socket->expectCallCount('write', 3);
|
|
||||||
$route = new PartialSimpleRoute();
|
|
||||||
$route->setReturnReference('createSocket', $socket);
|
|
||||||
$route->__construct(new SimpleUrl('http://a.valid.host/here.html'));
|
|
||||||
$this->assertSame($route->createConnection('HEAD', 15), $socket);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testGetWithPort() {
|
|
||||||
$socket = new MockSimpleSocket();
|
|
||||||
$socket->expectAt(0, 'write', array("GET /here.html HTTP/1.0\r\n"));
|
|
||||||
$socket->expectAt(1, 'write', array("Host: a.valid.host:81\r\n"));
|
|
||||||
$socket->expectAt(2, 'write', array("Connection: close\r\n"));
|
|
||||||
$socket->expectCallCount('write', 3);
|
|
||||||
|
|
||||||
$route = new PartialSimpleRoute();
|
|
||||||
$route->setReturnReference('createSocket', $socket);
|
|
||||||
$route->__construct(new SimpleUrl('http://a.valid.host:81/here.html'));
|
|
||||||
|
|
||||||
$route->createConnection('GET', 15);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testGetWithParameters() {
|
|
||||||
$socket = new MockSimpleSocket();
|
|
||||||
$socket->expectAt(0, 'write', array("GET /here.html?a=1&b=2 HTTP/1.0\r\n"));
|
|
||||||
$socket->expectAt(1, 'write', array("Host: a.valid.host\r\n"));
|
|
||||||
$socket->expectAt(2, 'write', array("Connection: close\r\n"));
|
|
||||||
$socket->expectCallCount('write', 3);
|
|
||||||
|
|
||||||
$route = new PartialSimpleRoute();
|
|
||||||
$route->setReturnReference('createSocket', $socket);
|
|
||||||
$route->__construct(new SimpleUrl('http://a.valid.host/here.html?a=1&b=2'));
|
|
||||||
|
|
||||||
$route->createConnection('GET', 15);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfProxyRoute extends UnitTestCase {
|
|
||||||
|
|
||||||
function testDefaultGet() {
|
|
||||||
$socket = new MockSimpleSocket();
|
|
||||||
$socket->expectAt(0, 'write', array("GET http://a.valid.host/here.html HTTP/1.0\r\n"));
|
|
||||||
$socket->expectAt(1, 'write', array("Host: my-proxy:8080\r\n"));
|
|
||||||
$socket->expectAt(2, 'write', array("Connection: close\r\n"));
|
|
||||||
$socket->expectCallCount('write', 3);
|
|
||||||
|
|
||||||
$route = new PartialSimpleProxyRoute();
|
|
||||||
$route->setReturnReference('createSocket', $socket);
|
|
||||||
$route->__construct(
|
|
||||||
new SimpleUrl('http://a.valid.host/here.html'),
|
|
||||||
new SimpleUrl('http://my-proxy'));
|
|
||||||
$route->createConnection('GET', 15);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testDefaultPost() {
|
|
||||||
$socket = new MockSimpleSocket();
|
|
||||||
$socket->expectAt(0, 'write', array("POST http://a.valid.host/here.html HTTP/1.0\r\n"));
|
|
||||||
$socket->expectAt(1, 'write', array("Host: my-proxy:8080\r\n"));
|
|
||||||
$socket->expectAt(2, 'write', array("Connection: close\r\n"));
|
|
||||||
$socket->expectCallCount('write', 3);
|
|
||||||
|
|
||||||
$route = new PartialSimpleProxyRoute();
|
|
||||||
$route->setReturnReference('createSocket', $socket);
|
|
||||||
$route->__construct(
|
|
||||||
new SimpleUrl('http://a.valid.host/here.html'),
|
|
||||||
new SimpleUrl('http://my-proxy'));
|
|
||||||
$route->createConnection('POST', 15);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testGetWithPort() {
|
|
||||||
$socket = new MockSimpleSocket();
|
|
||||||
$socket->expectAt(0, 'write', array("GET http://a.valid.host:81/here.html HTTP/1.0\r\n"));
|
|
||||||
$socket->expectAt(1, 'write', array("Host: my-proxy:8081\r\n"));
|
|
||||||
$socket->expectAt(2, 'write', array("Connection: close\r\n"));
|
|
||||||
$socket->expectCallCount('write', 3);
|
|
||||||
|
|
||||||
$route = new PartialSimpleProxyRoute();
|
|
||||||
$route->setReturnReference('createSocket', $socket);
|
|
||||||
$route->__construct(
|
|
||||||
new SimpleUrl('http://a.valid.host:81/here.html'),
|
|
||||||
new SimpleUrl('http://my-proxy:8081'));
|
|
||||||
$route->createConnection('GET', 15);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testGetWithParameters() {
|
|
||||||
$socket = new MockSimpleSocket();
|
|
||||||
$socket->expectAt(0, 'write', array("GET http://a.valid.host/here.html?a=1&b=2 HTTP/1.0\r\n"));
|
|
||||||
$socket->expectAt(1, 'write', array("Host: my-proxy:8080\r\n"));
|
|
||||||
$socket->expectAt(2, 'write', array("Connection: close\r\n"));
|
|
||||||
$socket->expectCallCount('write', 3);
|
|
||||||
|
|
||||||
$route = new PartialSimpleProxyRoute();
|
|
||||||
$route->setReturnReference('createSocket', $socket);
|
|
||||||
$route->__construct(
|
|
||||||
new SimpleUrl('http://a.valid.host/here.html?a=1&b=2'),
|
|
||||||
new SimpleUrl('http://my-proxy'));
|
|
||||||
$route->createConnection('GET', 15);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testGetWithAuthentication() {
|
|
||||||
$encoded = base64_encode('Me:Secret');
|
|
||||||
|
|
||||||
$socket = new MockSimpleSocket();
|
|
||||||
$socket->expectAt(0, 'write', array("GET http://a.valid.host/here.html HTTP/1.0\r\n"));
|
|
||||||
$socket->expectAt(1, 'write', array("Host: my-proxy:8080\r\n"));
|
|
||||||
$socket->expectAt(2, 'write', array("Proxy-Authorization: Basic $encoded\r\n"));
|
|
||||||
$socket->expectAt(3, 'write', array("Connection: close\r\n"));
|
|
||||||
$socket->expectCallCount('write', 4);
|
|
||||||
|
|
||||||
$route = new PartialSimpleProxyRoute();
|
|
||||||
$route->setReturnReference('createSocket', $socket);
|
|
||||||
$route->__construct(
|
|
||||||
new SimpleUrl('http://a.valid.host/here.html'),
|
|
||||||
new SimpleUrl('http://my-proxy'),
|
|
||||||
'Me',
|
|
||||||
'Secret');
|
|
||||||
$route->createConnection('GET', 15);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfHttpRequest extends UnitTestCase {
|
|
||||||
|
|
||||||
function testReadingBadConnection() {
|
|
||||||
$socket = new MockSimpleSocket();
|
|
||||||
$route = new MockSimpleRoute();
|
|
||||||
$route->setReturnReference('createConnection', $socket);
|
|
||||||
$request = new SimpleHttpRequest($route, new SimpleGetEncoding());
|
|
||||||
$reponse = $request->fetch(15);
|
|
||||||
$this->assertTrue($reponse->isError());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testReadingGoodConnection() {
|
|
||||||
$socket = new MockSimpleSocket();
|
|
||||||
$socket->expectOnce('write', array("\r\n"));
|
|
||||||
|
|
||||||
$route = new MockSimpleRoute();
|
|
||||||
$route->setReturnReference('createConnection', $socket);
|
|
||||||
$route->expect('createConnection', array('GET', 15));
|
|
||||||
|
|
||||||
$request = new SimpleHttpRequest($route, new SimpleGetEncoding());
|
|
||||||
$this->assertIsA($request->fetch(15), 'SimpleHttpResponse');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testWritingAdditionalHeaders() {
|
|
||||||
$socket = new MockSimpleSocket();
|
|
||||||
$socket->expectAt(0, 'write', array("My: stuff\r\n"));
|
|
||||||
$socket->expectAt(1, 'write', array("\r\n"));
|
|
||||||
$socket->expectCallCount('write', 2);
|
|
||||||
|
|
||||||
$route = new MockSimpleRoute();
|
|
||||||
$route->setReturnReference('createConnection', $socket);
|
|
||||||
|
|
||||||
$request = new SimpleHttpRequest($route, new SimpleGetEncoding());
|
|
||||||
$request->addHeaderLine('My: stuff');
|
|
||||||
$request->fetch(15);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCookieWriting() {
|
|
||||||
$socket = new MockSimpleSocket();
|
|
||||||
$socket->expectAt(0, 'write', array("Cookie: a=A\r\n"));
|
|
||||||
$socket->expectAt(1, 'write', array("\r\n"));
|
|
||||||
$socket->expectCallCount('write', 2);
|
|
||||||
|
|
||||||
$route = new MockSimpleRoute();
|
|
||||||
$route->setReturnReference('createConnection', $socket);
|
|
||||||
|
|
||||||
$jar = new SimpleCookieJar();
|
|
||||||
$jar->setCookie('a', 'A');
|
|
||||||
|
|
||||||
$request = new SimpleHttpRequest($route, new SimpleGetEncoding());
|
|
||||||
$request->readCookiesFromJar($jar, new SimpleUrl('/'));
|
|
||||||
$this->assertIsA($request->fetch(15), 'SimpleHttpResponse');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMultipleCookieWriting() {
|
|
||||||
$socket = new MockSimpleSocket();
|
|
||||||
$socket->expectAt(0, 'write', array("Cookie: a=A;b=B\r\n"));
|
|
||||||
|
|
||||||
$route = new MockSimpleRoute();
|
|
||||||
$route->setReturnReference('createConnection', $socket);
|
|
||||||
|
|
||||||
$jar = new SimpleCookieJar();
|
|
||||||
$jar->setCookie('a', 'A');
|
|
||||||
$jar->setCookie('b', 'B');
|
|
||||||
|
|
||||||
$request = new SimpleHttpRequest($route, new SimpleGetEncoding());
|
|
||||||
$request->readCookiesFromJar($jar, new SimpleUrl('/'));
|
|
||||||
$request->fetch(15);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testReadingDeleteConnection() {
|
|
||||||
$socket = new MockSimpleSocket();
|
|
||||||
|
|
||||||
$route = new MockSimpleRoute();
|
|
||||||
$route->setReturnReference('createConnection', $socket);
|
|
||||||
$route->expect('createConnection', array('DELETE', 15));
|
|
||||||
|
|
||||||
$request = new SimpleHttpRequest($route, new SimpleDeleteEncoding());
|
|
||||||
$this->assertIsA($request->fetch(15), 'SimpleHttpResponse');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfHttpPostRequest extends UnitTestCase {
|
|
||||||
|
|
||||||
function testReadingBadConnectionCausesErrorBecauseOfDeadSocket() {
|
|
||||||
$socket = new MockSimpleSocket();
|
|
||||||
$route = new MockSimpleRoute();
|
|
||||||
$route->setReturnReference('createConnection', $socket);
|
|
||||||
$request = new SimpleHttpRequest($route, new SimplePostEncoding());
|
|
||||||
$reponse = $request->fetch(15);
|
|
||||||
$this->assertTrue($reponse->isError());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testReadingGoodConnection() {
|
|
||||||
$socket = new MockSimpleSocket();
|
|
||||||
$socket->expectAt(0, 'write', array("Content-Length: 0\r\n"));
|
|
||||||
$socket->expectAt(1, 'write', array("Content-Type: application/x-www-form-urlencoded\r\n"));
|
|
||||||
$socket->expectAt(2, 'write', array("\r\n"));
|
|
||||||
$socket->expectAt(3, 'write', array(""));
|
|
||||||
|
|
||||||
$route = new MockSimpleRoute();
|
|
||||||
$route->setReturnReference('createConnection', $socket);
|
|
||||||
$route->expect('createConnection', array('POST', 15));
|
|
||||||
|
|
||||||
$request = new SimpleHttpRequest($route, new SimplePostEncoding());
|
|
||||||
$this->assertIsA($request->fetch(15), 'SimpleHttpResponse');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testContentHeadersCalculatedWithUrlEncodedParams() {
|
|
||||||
$socket = new MockSimpleSocket();
|
|
||||||
$socket->expectAt(0, 'write', array("Content-Length: 3\r\n"));
|
|
||||||
$socket->expectAt(1, 'write', array("Content-Type: application/x-www-form-urlencoded\r\n"));
|
|
||||||
$socket->expectAt(2, 'write', array("\r\n"));
|
|
||||||
$socket->expectAt(3, 'write', array("a=A"));
|
|
||||||
|
|
||||||
$route = new MockSimpleRoute();
|
|
||||||
$route->setReturnReference('createConnection', $socket);
|
|
||||||
$route->expect('createConnection', array('POST', 15));
|
|
||||||
|
|
||||||
$request = new SimpleHttpRequest(
|
|
||||||
$route,
|
|
||||||
new SimplePostEncoding(array('a' => 'A')));
|
|
||||||
$this->assertIsA($request->fetch(15), 'SimpleHttpResponse');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testContentHeadersCalculatedWithRawEntityBody() {
|
|
||||||
$socket = new MockSimpleSocket();
|
|
||||||
$socket->expectAt(0, 'write', array("Content-Length: 8\r\n"));
|
|
||||||
$socket->expectAt(1, 'write', array("Content-Type: text/plain\r\n"));
|
|
||||||
$socket->expectAt(2, 'write', array("\r\n"));
|
|
||||||
$socket->expectAt(3, 'write', array("raw body"));
|
|
||||||
|
|
||||||
$route = new MockSimpleRoute();
|
|
||||||
$route->setReturnReference('createConnection', $socket);
|
|
||||||
$route->expect('createConnection', array('POST', 15));
|
|
||||||
|
|
||||||
$request = new SimpleHttpRequest(
|
|
||||||
$route,
|
|
||||||
new SimplePostEncoding('raw body'));
|
|
||||||
$this->assertIsA($request->fetch(15), 'SimpleHttpResponse');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testContentHeadersCalculatedWithXmlEntityBody() {
|
|
||||||
$socket = new MockSimpleSocket();
|
|
||||||
$socket->expectAt(0, 'write', array("Content-Length: 27\r\n"));
|
|
||||||
$socket->expectAt(1, 'write', array("Content-Type: text/xml\r\n"));
|
|
||||||
$socket->expectAt(2, 'write', array("\r\n"));
|
|
||||||
$socket->expectAt(3, 'write', array("<a><b>one</b><c>two</c></a>"));
|
|
||||||
|
|
||||||
$route = new MockSimpleRoute();
|
|
||||||
$route->setReturnReference('createConnection', $socket);
|
|
||||||
$route->expect('createConnection', array('POST', 15));
|
|
||||||
|
|
||||||
$request = new SimpleHttpRequest(
|
|
||||||
$route,
|
|
||||||
new SimplePostEncoding('<a><b>one</b><c>two</c></a>', 'text/xml'));
|
|
||||||
$this->assertIsA($request->fetch(15), 'SimpleHttpResponse');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfHttpHeaders extends UnitTestCase {
|
|
||||||
|
|
||||||
function testParseBasicHeaders() {
|
|
||||||
$headers = new SimpleHttpHeaders(
|
|
||||||
"HTTP/1.1 200 OK\r\n" .
|
|
||||||
"Date: Mon, 18 Nov 2002 15:50:29 GMT\r\n" .
|
|
||||||
"Content-Type: text/plain\r\n" .
|
|
||||||
"Server: Apache/1.3.24 (Win32) PHP/4.2.3\r\n" .
|
|
||||||
"Connection: close");
|
|
||||||
$this->assertIdentical($headers->getHttpVersion(), "1.1");
|
|
||||||
$this->assertIdentical($headers->getResponseCode(), 200);
|
|
||||||
$this->assertEqual($headers->getMimeType(), "text/plain");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testNonStandardResponseHeader() {
|
|
||||||
$headers = new SimpleHttpHeaders(
|
|
||||||
"HTTP/1.1 302 (HTTP-Version SP Status-Code CRLF)\r\n" .
|
|
||||||
"Connection: close");
|
|
||||||
$this->assertIdentical($headers->getResponseCode(), 302);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanParseMultipleCookies() {
|
|
||||||
$jar = new MockSimpleCookieJar();
|
|
||||||
$jar->expectAt(0, 'setCookie', array('a', 'aaa', 'host', '/here/', 'Wed, 25 Dec 2002 04:24:20 GMT'));
|
|
||||||
$jar->expectAt(1, 'setCookie', array('b', 'bbb', 'host', '/', false));
|
|
||||||
|
|
||||||
$headers = new SimpleHttpHeaders(
|
|
||||||
"HTTP/1.1 200 OK\r\n" .
|
|
||||||
"Date: Mon, 18 Nov 2002 15:50:29 GMT\r\n" .
|
|
||||||
"Content-Type: text/plain\r\n" .
|
|
||||||
"Server: Apache/1.3.24 (Win32) PHP/4.2.3\r\n" .
|
|
||||||
"Set-Cookie: a=aaa; expires=Wed, 25-Dec-02 04:24:20 GMT; path=/here/\r\n" .
|
|
||||||
"Set-Cookie: b=bbb\r\n" .
|
|
||||||
"Connection: close");
|
|
||||||
$headers->writeCookiesToJar($jar, new SimpleUrl('http://host'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanRecogniseRedirect() {
|
|
||||||
$headers = new SimpleHttpHeaders("HTTP/1.1 301 OK\r\n" .
|
|
||||||
"Content-Type: text/plain\r\n" .
|
|
||||||
"Content-Length: 0\r\n" .
|
|
||||||
"Location: http://www.somewhere-else.com/\r\n" .
|
|
||||||
"Connection: close");
|
|
||||||
$this->assertIdentical($headers->getResponseCode(), 301);
|
|
||||||
$this->assertEqual($headers->getLocation(), "http://www.somewhere-else.com/");
|
|
||||||
$this->assertTrue($headers->isRedirect());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanParseChallenge() {
|
|
||||||
$headers = new SimpleHttpHeaders("HTTP/1.1 401 Authorization required\r\n" .
|
|
||||||
"Content-Type: text/plain\r\n" .
|
|
||||||
"Connection: close\r\n" .
|
|
||||||
"WWW-Authenticate: Basic realm=\"Somewhere\"");
|
|
||||||
$this->assertEqual($headers->getAuthentication(), 'Basic');
|
|
||||||
$this->assertEqual($headers->getRealm(), 'Somewhere');
|
|
||||||
$this->assertTrue($headers->isChallenge());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfHttpResponse extends UnitTestCase {
|
|
||||||
|
|
||||||
function testBadRequest() {
|
|
||||||
$socket = new MockSimpleSocket();
|
|
||||||
$socket->setReturnValue('getSent', '');
|
|
||||||
|
|
||||||
$response = new SimpleHttpResponse($socket, new SimpleUrl('here'), new SimpleGetEncoding());
|
|
||||||
$this->assertTrue($response->isError());
|
|
||||||
$this->assertPattern('/Nothing fetched/', $response->getError());
|
|
||||||
$this->assertIdentical($response->getContent(), false);
|
|
||||||
$this->assertIdentical($response->getSent(), '');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testBadSocketDuringResponse() {
|
|
||||||
$socket = new MockSimpleSocket();
|
|
||||||
$socket->setReturnValueAt(0, "read", "HTTP/1.1 200 OK\r\n");
|
|
||||||
$socket->setReturnValueAt(1, "read", "Date: Mon, 18 Nov 2002 15:50:29 GMT\r\n");
|
|
||||||
$socket->setReturnValue("read", "");
|
|
||||||
$socket->setReturnValue('getSent', 'HTTP/1.1 ...');
|
|
||||||
|
|
||||||
$response = new SimpleHttpResponse($socket, new SimpleUrl('here'), new SimpleGetEncoding());
|
|
||||||
$this->assertTrue($response->isError());
|
|
||||||
$this->assertEqual($response->getContent(), '');
|
|
||||||
$this->assertEqual($response->getSent(), 'HTTP/1.1 ...');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testIncompleteHeader() {
|
|
||||||
$socket = new MockSimpleSocket();
|
|
||||||
$socket->setReturnValueAt(0, "read", "HTTP/1.1 200 OK\r\n");
|
|
||||||
$socket->setReturnValueAt(1, "read", "Date: Mon, 18 Nov 2002 15:50:29 GMT\r\n");
|
|
||||||
$socket->setReturnValueAt(2, "read", "Content-Type: text/plain\r\n");
|
|
||||||
$socket->setReturnValue("read", "");
|
|
||||||
|
|
||||||
$response = new SimpleHttpResponse($socket, new SimpleUrl('here'), new SimpleGetEncoding());
|
|
||||||
$this->assertTrue($response->isError());
|
|
||||||
$this->assertEqual($response->getContent(), "");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testParseOfResponseHeadersWhenChunked() {
|
|
||||||
$socket = new MockSimpleSocket();
|
|
||||||
$socket->setReturnValueAt(0, "read", "HTTP/1.1 200 OK\r\nDate: Mon, 18 Nov 2002 15:50:29 GMT\r\n");
|
|
||||||
$socket->setReturnValueAt(1, "read", "Content-Type: text/plain\r\n");
|
|
||||||
$socket->setReturnValueAt(2, "read", "Server: Apache/1.3.24 (Win32) PHP/4.2.3\r\nConne");
|
|
||||||
$socket->setReturnValueAt(3, "read", "ction: close\r\n\r\nthis is a test file\n");
|
|
||||||
$socket->setReturnValueAt(4, "read", "with two lines in it\n");
|
|
||||||
$socket->setReturnValue("read", "");
|
|
||||||
|
|
||||||
$response = new SimpleHttpResponse($socket, new SimpleUrl('here'), new SimpleGetEncoding());
|
|
||||||
$this->assertFalse($response->isError());
|
|
||||||
$this->assertEqual(
|
|
||||||
$response->getContent(),
|
|
||||||
"this is a test file\nwith two lines in it\n");
|
|
||||||
$headers = $response->getHeaders();
|
|
||||||
$this->assertIdentical($headers->getHttpVersion(), "1.1");
|
|
||||||
$this->assertIdentical($headers->getResponseCode(), 200);
|
|
||||||
$this->assertEqual($headers->getMimeType(), "text/plain");
|
|
||||||
$this->assertFalse($headers->isRedirect());
|
|
||||||
$this->assertFalse($headers->getLocation());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testRedirect() {
|
|
||||||
$socket = new MockSimpleSocket();
|
|
||||||
$socket->setReturnValueAt(0, "read", "HTTP/1.1 301 OK\r\n");
|
|
||||||
$socket->setReturnValueAt(1, "read", "Content-Type: text/plain\r\n");
|
|
||||||
$socket->setReturnValueAt(2, "read", "Location: http://www.somewhere-else.com/\r\n");
|
|
||||||
$socket->setReturnValueAt(3, "read", "Connection: close\r\n");
|
|
||||||
$socket->setReturnValueAt(4, "read", "\r\n");
|
|
||||||
$socket->setReturnValue("read", "");
|
|
||||||
|
|
||||||
$response = new SimpleHttpResponse($socket, new SimpleUrl('here'), new SimpleGetEncoding());
|
|
||||||
$headers = $response->getHeaders();
|
|
||||||
$this->assertTrue($headers->isRedirect());
|
|
||||||
$this->assertEqual($headers->getLocation(), "http://www.somewhere-else.com/");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testRedirectWithPort() {
|
|
||||||
$socket = new MockSimpleSocket();
|
|
||||||
$socket->setReturnValueAt(0, "read", "HTTP/1.1 301 OK\r\n");
|
|
||||||
$socket->setReturnValueAt(1, "read", "Content-Type: text/plain\r\n");
|
|
||||||
$socket->setReturnValueAt(2, "read", "Location: http://www.somewhere-else.com:80/\r\n");
|
|
||||||
$socket->setReturnValueAt(3, "read", "Connection: close\r\n");
|
|
||||||
$socket->setReturnValueAt(4, "read", "\r\n");
|
|
||||||
$socket->setReturnValue("read", "");
|
|
||||||
|
|
||||||
$response = new SimpleHttpResponse($socket, new SimpleUrl('here'), new SimpleGetEncoding());
|
|
||||||
$headers = $response->getHeaders();
|
|
||||||
$this->assertTrue($headers->isRedirect());
|
|
||||||
$this->assertEqual($headers->getLocation(), "http://www.somewhere-else.com:80/");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,137 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: interfaces_test.php 1981 2010-03-23 23:29:56Z lastcraft $
|
|
||||||
require_once(dirname(__FILE__) . '/../autorun.php');
|
|
||||||
if (function_exists('spl_classes')) {
|
|
||||||
include(dirname(__FILE__) . '/support/spl_examples.php');
|
|
||||||
}
|
|
||||||
if (version_compare(PHP_VERSION, '5.1', '>=')) {
|
|
||||||
include(dirname(__FILE__) . '/interfaces_test_php5_1.php');
|
|
||||||
}
|
|
||||||
|
|
||||||
interface DummyInterface {
|
|
||||||
function aMethod();
|
|
||||||
function anotherMethod($a);
|
|
||||||
function &referenceMethod(&$a);
|
|
||||||
}
|
|
||||||
|
|
||||||
Mock::generate('DummyInterface');
|
|
||||||
Mock::generatePartial('DummyInterface', 'PartialDummyInterface', array());
|
|
||||||
|
|
||||||
class TestOfMockInterfaces extends UnitTestCase {
|
|
||||||
|
|
||||||
function testCanMockAnInterface() {
|
|
||||||
$mock = new MockDummyInterface();
|
|
||||||
$this->assertIsA($mock, 'SimpleMock');
|
|
||||||
$this->assertIsA($mock, 'MockDummyInterface');
|
|
||||||
$this->assertTrue(method_exists($mock, 'aMethod'));
|
|
||||||
$this->assertTrue(method_exists($mock, 'anotherMethod'));
|
|
||||||
$this->assertNull($mock->aMethod());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMockedInterfaceExpectsParameters() {
|
|
||||||
$mock = new MockDummyInterface();
|
|
||||||
$this->expectError();
|
|
||||||
$mock->anotherMethod();
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCannotPartiallyMockAnInterface() {
|
|
||||||
$this->assertFalse(class_exists('PartialDummyInterface'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfSpl extends UnitTestCase {
|
|
||||||
|
|
||||||
function skip() {
|
|
||||||
$this->skipUnless(function_exists('spl_classes'), 'No SPL module loaded');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanMockAllSplClasses() {
|
|
||||||
if (! function_exists('spl_classes')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
foreach(spl_classes() as $class) {
|
|
||||||
if ($class == 'SplHeap' or $class = 'SplFileObject') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (version_compare(PHP_VERSION, '5.1', '<') &&
|
|
||||||
$class == 'CachingIterator' ||
|
|
||||||
$class == 'CachingRecursiveIterator' ||
|
|
||||||
$class == 'FilterIterator' ||
|
|
||||||
$class == 'LimitIterator' ||
|
|
||||||
$class == 'ParentIterator') {
|
|
||||||
// These iterators require an iterator be passed to them during
|
|
||||||
// construction in PHP 5.0; there is no way for SimpleTest
|
|
||||||
// to supply such an iterator, however, so support for it is
|
|
||||||
// disabled.
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$mock_class = "Mock$class";
|
|
||||||
Mock::generate($class);
|
|
||||||
$this->assertIsA(new $mock_class(), $mock_class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function testExtensionOfCommonSplClasses() {
|
|
||||||
Mock::generate('IteratorImplementation');
|
|
||||||
$this->assertIsA(
|
|
||||||
new IteratorImplementation(),
|
|
||||||
'IteratorImplementation');
|
|
||||||
Mock::generate('IteratorAggregateImplementation');
|
|
||||||
$this->assertIsA(
|
|
||||||
new IteratorAggregateImplementation(),
|
|
||||||
'IteratorAggregateImplementation');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class WithHint {
|
|
||||||
function hinted(DummyInterface $object) { }
|
|
||||||
}
|
|
||||||
|
|
||||||
class ImplementsDummy implements DummyInterface {
|
|
||||||
function aMethod() { }
|
|
||||||
function anotherMethod($a) { }
|
|
||||||
function &referenceMethod(&$a) { }
|
|
||||||
function extraMethod($a = false) { }
|
|
||||||
}
|
|
||||||
Mock::generate('ImplementsDummy');
|
|
||||||
|
|
||||||
class TestOfImplementations extends UnitTestCase {
|
|
||||||
|
|
||||||
function testMockedInterfaceCanPassThroughTypeHint() {
|
|
||||||
$mock = new MockDummyInterface();
|
|
||||||
$hinter = new WithHint();
|
|
||||||
$hinter->hinted($mock);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testImplementedInterfacesAreCarried() {
|
|
||||||
$mock = new MockImplementsDummy();
|
|
||||||
$hinter = new WithHint();
|
|
||||||
$hinter->hinted($mock);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testNoSpuriousWarningsWhenSkippingDefaultedParameter() {
|
|
||||||
$mock = new MockImplementsDummy();
|
|
||||||
$mock->extraMethod();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
interface SampleInterfaceWithConstruct {
|
|
||||||
function __construct($something);
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfInterfaceMocksWithConstruct extends UnitTestCase {
|
|
||||||
function TODO_testBasicConstructOfAnInterface() { // Fails in PHP 5.3dev
|
|
||||||
Mock::generate('SampleInterfaceWithConstruct');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
interface SampleInterfaceWithClone {
|
|
||||||
function __clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfSampleInterfaceWithClone extends UnitTestCase {
|
|
||||||
function testCanMockWithoutErrors() {
|
|
||||||
Mock::generate('SampleInterfaceWithClone');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,14 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
interface SampleInterfaceWithHintInSignature {
|
|
||||||
function method(array $hinted);
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfInterfaceMocksWithHintInSignature extends UnitTestCase {
|
|
||||||
function testBasicConstructOfAnInterfaceWithHintInSignature() {
|
|
||||||
Mock::generate('SampleInterfaceWithHintInSignature');
|
|
||||||
$mock = new MockSampleInterfaceWithHintInSignature();
|
|
||||||
$this->assertIsA($mock, 'SampleInterfaceWithHintInSignature');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: live_test.php 1748 2008-04-14 01:50:41Z lastcraft $
|
|
||||||
require_once(dirname(__FILE__) . '/../autorun.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../socket.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../http.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../compatibility.php');
|
|
||||||
|
|
||||||
if (SimpleTest::getDefaultProxy()) {
|
|
||||||
SimpleTest::ignore('LiveHttpTestCase');
|
|
||||||
}
|
|
||||||
|
|
||||||
class LiveHttpTestCase extends UnitTestCase {
|
|
||||||
|
|
||||||
function testBadSocket() {
|
|
||||||
$socket = new SimpleSocket('bad_url', 111, 5);
|
|
||||||
$this->assertTrue($socket->isError());
|
|
||||||
$this->assertPattern(
|
|
||||||
'/Cannot open \\[bad_url:111\\] with \\[/',
|
|
||||||
$socket->getError());
|
|
||||||
$this->assertFalse($socket->isOpen());
|
|
||||||
$this->assertFalse($socket->write('A message'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSocketClosure() {
|
|
||||||
$socket = new SimpleSocket('www.lastcraft.com', 80, 15, 8);
|
|
||||||
$this->assertTrue($socket->isOpen());
|
|
||||||
$this->assertTrue($socket->write("GET /test/network_confirm.php HTTP/1.0\r\n"));
|
|
||||||
$socket->write("Host: www.lastcraft.com\r\n");
|
|
||||||
$socket->write("Connection: close\r\n\r\n");
|
|
||||||
$this->assertEqual($socket->read(), "HTTP/1.1");
|
|
||||||
$socket->close();
|
|
||||||
$this->assertIdentical($socket->read(), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testRecordOfSentCharacters() {
|
|
||||||
$socket = new SimpleSocket('www.lastcraft.com', 80, 15);
|
|
||||||
$this->assertTrue($socket->write("GET /test/network_confirm.php HTTP/1.0\r\n"));
|
|
||||||
$socket->write("Host: www.lastcraft.com\r\n");
|
|
||||||
$socket->write("Connection: close\r\n\r\n");
|
|
||||||
$socket->close();
|
|
||||||
$this->assertEqual($socket->getSent(),
|
|
||||||
"GET /test/network_confirm.php HTTP/1.0\r\n" .
|
|
||||||
"Host: www.lastcraft.com\r\n" .
|
|
||||||
"Connection: close\r\n\r\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,985 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: mock_objects_test.php 1900 2009-07-29 11:44:37Z lastcraft $
|
|
||||||
require_once(dirname(__FILE__) . '/../autorun.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../expectation.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../mock_objects.php');
|
|
||||||
|
|
||||||
class TestOfAnythingExpectation extends UnitTestCase {
|
|
||||||
function testSimpleInteger() {
|
|
||||||
$expectation = new AnythingExpectation();
|
|
||||||
$this->assertTrue($expectation->test(33));
|
|
||||||
$this->assertTrue($expectation->test(false));
|
|
||||||
$this->assertTrue($expectation->test(null));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfParametersExpectation extends UnitTestCase {
|
|
||||||
|
|
||||||
function testEmptyMatch() {
|
|
||||||
$expectation = new ParametersExpectation(array());
|
|
||||||
$this->assertTrue($expectation->test(array()));
|
|
||||||
$this->assertFalse($expectation->test(array(33)));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSingleMatch() {
|
|
||||||
$expectation = new ParametersExpectation(array(0));
|
|
||||||
$this->assertFalse($expectation->test(array(1)));
|
|
||||||
$this->assertTrue($expectation->test(array(0)));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testAnyMatch() {
|
|
||||||
$expectation = new ParametersExpectation(false);
|
|
||||||
$this->assertTrue($expectation->test(array()));
|
|
||||||
$this->assertTrue($expectation->test(array(1, 2)));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMissingParameter() {
|
|
||||||
$expectation = new ParametersExpectation(array(0));
|
|
||||||
$this->assertFalse($expectation->test(array()));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testNullParameter() {
|
|
||||||
$expectation = new ParametersExpectation(array(null));
|
|
||||||
$this->assertTrue($expectation->test(array(null)));
|
|
||||||
$this->assertFalse($expectation->test(array()));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testAnythingExpectations() {
|
|
||||||
$expectation = new ParametersExpectation(array(new AnythingExpectation()));
|
|
||||||
$this->assertFalse($expectation->test(array()));
|
|
||||||
$this->assertIdentical($expectation->test(array(null)), true);
|
|
||||||
$this->assertIdentical($expectation->test(array(13)), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testOtherExpectations() {
|
|
||||||
$expectation = new ParametersExpectation(
|
|
||||||
array(new PatternExpectation('/hello/i')));
|
|
||||||
$this->assertFalse($expectation->test(array('Goodbye')));
|
|
||||||
$this->assertTrue($expectation->test(array('hello')));
|
|
||||||
$this->assertTrue($expectation->test(array('Hello')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testIdentityOnly() {
|
|
||||||
$expectation = new ParametersExpectation(array("0"));
|
|
||||||
$this->assertFalse($expectation->test(array(0)));
|
|
||||||
$this->assertTrue($expectation->test(array("0")));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testLongList() {
|
|
||||||
$expectation = new ParametersExpectation(
|
|
||||||
array("0", 0, new AnythingExpectation(), false));
|
|
||||||
$this->assertTrue($expectation->test(array("0", 0, 37, false)));
|
|
||||||
$this->assertFalse($expectation->test(array("0", 0, 37, true)));
|
|
||||||
$this->assertFalse($expectation->test(array("0", 0, 37)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfSimpleSignatureMap extends UnitTestCase {
|
|
||||||
|
|
||||||
function testEmpty() {
|
|
||||||
$map = new SimpleSignatureMap();
|
|
||||||
$this->assertFalse($map->isMatch("any", array()));
|
|
||||||
$this->assertNull($map->findFirstAction("any", array()));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testDifferentCallSignaturesCanHaveDifferentReferences() {
|
|
||||||
$map = new SimpleSignatureMap();
|
|
||||||
$fred = 'Fred';
|
|
||||||
$jim = 'jim';
|
|
||||||
$map->add(array(0), $fred);
|
|
||||||
$map->add(array('0'), $jim);
|
|
||||||
$this->assertSame($fred, $map->findFirstAction(array(0)));
|
|
||||||
$this->assertSame($jim, $map->findFirstAction(array('0')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testWildcard() {
|
|
||||||
$fred = 'Fred';
|
|
||||||
$map = new SimpleSignatureMap();
|
|
||||||
$map->add(array(new AnythingExpectation(), 1, 3), $fred);
|
|
||||||
$this->assertTrue($map->isMatch(array(2, 1, 3)));
|
|
||||||
$this->assertSame($map->findFirstAction(array(2, 1, 3)), $fred);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testAllWildcard() {
|
|
||||||
$fred = 'Fred';
|
|
||||||
$map = new SimpleSignatureMap();
|
|
||||||
$this->assertFalse($map->isMatch(array(2, 1, 3)));
|
|
||||||
$map->add('', $fred);
|
|
||||||
$this->assertTrue($map->isMatch(array(2, 1, 3)));
|
|
||||||
$this->assertSame($map->findFirstAction(array(2, 1, 3)), $fred);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testOrdering() {
|
|
||||||
$map = new SimpleSignatureMap();
|
|
||||||
$map->add(array(1, 2), new SimpleByValue("1, 2"));
|
|
||||||
$map->add(array(1, 3), new SimpleByValue("1, 3"));
|
|
||||||
$map->add(array(1), new SimpleByValue("1"));
|
|
||||||
$map->add(array(1, 4), new SimpleByValue("1, 4"));
|
|
||||||
$map->add(array(new AnythingExpectation()), new SimpleByValue("Any"));
|
|
||||||
$map->add(array(2), new SimpleByValue("2"));
|
|
||||||
$map->add("", new SimpleByValue("Default"));
|
|
||||||
$map->add(array(), new SimpleByValue("None"));
|
|
||||||
$this->assertEqual($map->findFirstAction(array(1, 2)), new SimpleByValue("1, 2"));
|
|
||||||
$this->assertEqual($map->findFirstAction(array(1, 3)), new SimpleByValue("1, 3"));
|
|
||||||
$this->assertEqual($map->findFirstAction(array(1, 4)), new SimpleByValue("1, 4"));
|
|
||||||
$this->assertEqual($map->findFirstAction(array(1)), new SimpleByValue("1"));
|
|
||||||
$this->assertEqual($map->findFirstAction(array(2)), new SimpleByValue("Any"));
|
|
||||||
$this->assertEqual($map->findFirstAction(array(3)), new SimpleByValue("Any"));
|
|
||||||
$this->assertEqual($map->findFirstAction(array()), new SimpleByValue("Default"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfCallSchedule extends UnitTestCase {
|
|
||||||
function testCanBeSetToAlwaysReturnTheSameReference() {
|
|
||||||
$a = 5;
|
|
||||||
$schedule = new SimpleCallSchedule();
|
|
||||||
$schedule->register('aMethod', false, new SimpleByReference($a));
|
|
||||||
$this->assertReference($schedule->respond(0, 'aMethod', array()), $a);
|
|
||||||
$this->assertReference($schedule->respond(1, 'aMethod', array()), $a);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSpecificSignaturesOverrideTheAlwaysCase() {
|
|
||||||
$any = 'any';
|
|
||||||
$one = 'two';
|
|
||||||
$schedule = new SimpleCallSchedule();
|
|
||||||
$schedule->register('aMethod', array(1), new SimpleByReference($one));
|
|
||||||
$schedule->register('aMethod', false, new SimpleByReference($any));
|
|
||||||
$this->assertReference($schedule->respond(0, 'aMethod', array(2)), $any);
|
|
||||||
$this->assertReference($schedule->respond(0, 'aMethod', array(1)), $one);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testReturnsCanBeSetOverTime() {
|
|
||||||
$one = 'one';
|
|
||||||
$two = 'two';
|
|
||||||
$schedule = new SimpleCallSchedule();
|
|
||||||
$schedule->registerAt(0, 'aMethod', false, new SimpleByReference($one));
|
|
||||||
$schedule->registerAt(1, 'aMethod', false, new SimpleByReference($two));
|
|
||||||
$this->assertReference($schedule->respond(0, 'aMethod', array()), $one);
|
|
||||||
$this->assertReference($schedule->respond(1, 'aMethod', array()), $two);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testReturnsOverTimecanBeAlteredByTheArguments() {
|
|
||||||
$one = '1';
|
|
||||||
$two = '2';
|
|
||||||
$two_a = '2a';
|
|
||||||
$schedule = new SimpleCallSchedule();
|
|
||||||
$schedule->registerAt(0, 'aMethod', false, new SimpleByReference($one));
|
|
||||||
$schedule->registerAt(1, 'aMethod', array('a'), new SimpleByReference($two_a));
|
|
||||||
$schedule->registerAt(1, 'aMethod', false, new SimpleByReference($two));
|
|
||||||
$this->assertReference($schedule->respond(0, 'aMethod', array()), $one);
|
|
||||||
$this->assertReference($schedule->respond(1, 'aMethod', array()), $two);
|
|
||||||
$this->assertReference($schedule->respond(1, 'aMethod', array('a')), $two_a);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanReturnByValue() {
|
|
||||||
$a = 5;
|
|
||||||
$schedule = new SimpleCallSchedule();
|
|
||||||
$schedule->register('aMethod', false, new SimpleByValue($a));
|
|
||||||
$this->assertCopy($schedule->respond(0, 'aMethod', array()), $a);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanThrowException() {
|
|
||||||
if (version_compare(phpversion(), '5', '>=')) {
|
|
||||||
$schedule = new SimpleCallSchedule();
|
|
||||||
$schedule->register('aMethod', false, new SimpleThrower(new Exception('Ouch')));
|
|
||||||
$this->expectException(new Exception('Ouch'));
|
|
||||||
$schedule->respond(0, 'aMethod', array());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanEmitError() {
|
|
||||||
$schedule = new SimpleCallSchedule();
|
|
||||||
$schedule->register('aMethod', false, new SimpleErrorThrower('Ouch', E_USER_WARNING));
|
|
||||||
$this->expectError('Ouch');
|
|
||||||
$schedule->respond(0, 'aMethod', array());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Dummy {
|
|
||||||
function Dummy() {
|
|
||||||
}
|
|
||||||
|
|
||||||
function aMethod() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function &aReferenceMethod() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function anotherMethod() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Mock::generate('Dummy');
|
|
||||||
Mock::generate('Dummy', 'AnotherMockDummy');
|
|
||||||
Mock::generate('Dummy', 'MockDummyWithExtraMethods', array('extraMethod'));
|
|
||||||
|
|
||||||
class TestOfMockGeneration extends UnitTestCase {
|
|
||||||
|
|
||||||
function testCloning() {
|
|
||||||
$mock = new MockDummy();
|
|
||||||
$this->assertTrue(method_exists($mock, "aMethod"));
|
|
||||||
$this->assertNull($mock->aMethod());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCloningWithExtraMethod() {
|
|
||||||
$mock = new MockDummyWithExtraMethods();
|
|
||||||
$this->assertTrue(method_exists($mock, "extraMethod"));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCloningWithChosenClassName() {
|
|
||||||
$mock = new AnotherMockDummy();
|
|
||||||
$this->assertTrue(method_exists($mock, "aMethod"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfMockReturns extends UnitTestCase {
|
|
||||||
|
|
||||||
function testDefaultReturn() {
|
|
||||||
$mock = new MockDummy();
|
|
||||||
$mock->returnsByValue("aMethod", "aaa");
|
|
||||||
$this->assertIdentical($mock->aMethod(), "aaa");
|
|
||||||
$this->assertIdentical($mock->aMethod(), "aaa");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testParameteredReturn() {
|
|
||||||
$mock = new MockDummy();
|
|
||||||
$mock->returnsByValue('aMethod', 'aaa', array(1, 2, 3));
|
|
||||||
$this->assertNull($mock->aMethod());
|
|
||||||
$this->assertIdentical($mock->aMethod(1, 2, 3), 'aaa');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSetReturnGivesObjectReference() {
|
|
||||||
$mock = new MockDummy();
|
|
||||||
$object = new Dummy();
|
|
||||||
$mock->returns('aMethod', $object, array(1, 2, 3));
|
|
||||||
$this->assertSame($mock->aMethod(1, 2, 3), $object);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSetReturnReferenceGivesOriginalReference() {
|
|
||||||
$mock = new MockDummy();
|
|
||||||
$object = 1;
|
|
||||||
$mock->returnsByReference('aReferenceMethod', $object, array(1, 2, 3));
|
|
||||||
$this->assertReference($mock->aReferenceMethod(1, 2, 3), $object);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testReturnValueCanBeChosenJustByPatternMatchingArguments() {
|
|
||||||
$mock = new MockDummy();
|
|
||||||
$mock->returnsByValue(
|
|
||||||
"aMethod",
|
|
||||||
"aaa",
|
|
||||||
array(new PatternExpectation('/hello/i')));
|
|
||||||
$this->assertIdentical($mock->aMethod('Hello'), 'aaa');
|
|
||||||
$this->assertNull($mock->aMethod('Goodbye'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMultipleMethods() {
|
|
||||||
$mock = new MockDummy();
|
|
||||||
$mock->returnsByValue("aMethod", 100, array(1));
|
|
||||||
$mock->returnsByValue("aMethod", 200, array(2));
|
|
||||||
$mock->returnsByValue("anotherMethod", 10, array(1));
|
|
||||||
$mock->returnsByValue("anotherMethod", 20, array(2));
|
|
||||||
$this->assertIdentical($mock->aMethod(1), 100);
|
|
||||||
$this->assertIdentical($mock->anotherMethod(1), 10);
|
|
||||||
$this->assertIdentical($mock->aMethod(2), 200);
|
|
||||||
$this->assertIdentical($mock->anotherMethod(2), 20);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testReturnSequence() {
|
|
||||||
$mock = new MockDummy();
|
|
||||||
$mock->returnsByValueAt(0, "aMethod", "aaa");
|
|
||||||
$mock->returnsByValueAt(1, "aMethod", "bbb");
|
|
||||||
$mock->returnsByValueAt(3, "aMethod", "ddd");
|
|
||||||
$this->assertIdentical($mock->aMethod(), "aaa");
|
|
||||||
$this->assertIdentical($mock->aMethod(), "bbb");
|
|
||||||
$this->assertNull($mock->aMethod());
|
|
||||||
$this->assertIdentical($mock->aMethod(), "ddd");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSetReturnReferenceAtGivesOriginal() {
|
|
||||||
$mock = new MockDummy();
|
|
||||||
$object = 100;
|
|
||||||
$mock->returnsByReferenceAt(1, "aReferenceMethod", $object);
|
|
||||||
$this->assertNull($mock->aReferenceMethod());
|
|
||||||
$this->assertReference($mock->aReferenceMethod(), $object);
|
|
||||||
$this->assertNull($mock->aReferenceMethod());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testReturnsAtGivesOriginalObjectHandle() {
|
|
||||||
$mock = new MockDummy();
|
|
||||||
$object = new Dummy();
|
|
||||||
$mock->returnsAt(1, "aMethod", $object);
|
|
||||||
$this->assertNull($mock->aMethod());
|
|
||||||
$this->assertSame($mock->aMethod(), $object);
|
|
||||||
$this->assertNull($mock->aMethod());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testComplicatedReturnSequence() {
|
|
||||||
$mock = new MockDummy();
|
|
||||||
$object = new Dummy();
|
|
||||||
$mock->returnsAt(1, "aMethod", "aaa", array("a"));
|
|
||||||
$mock->returnsAt(1, "aMethod", "bbb");
|
|
||||||
$mock->returnsAt(2, "aMethod", $object, array('*', 2));
|
|
||||||
$mock->returnsAt(2, "aMethod", "value", array('*', 3));
|
|
||||||
$mock->returns("aMethod", 3, array(3));
|
|
||||||
$this->assertNull($mock->aMethod());
|
|
||||||
$this->assertEqual($mock->aMethod("a"), "aaa");
|
|
||||||
$this->assertSame($mock->aMethod(1, 2), $object);
|
|
||||||
$this->assertEqual($mock->aMethod(3), 3);
|
|
||||||
$this->assertNull($mock->aMethod());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMultipleMethodSequences() {
|
|
||||||
$mock = new MockDummy();
|
|
||||||
$mock->returnsByValueAt(0, "aMethod", "aaa");
|
|
||||||
$mock->returnsByValueAt(1, "aMethod", "bbb");
|
|
||||||
$mock->returnsByValueAt(0, "anotherMethod", "ccc");
|
|
||||||
$mock->returnsByValueAt(1, "anotherMethod", "ddd");
|
|
||||||
$this->assertIdentical($mock->aMethod(), "aaa");
|
|
||||||
$this->assertIdentical($mock->anotherMethod(), "ccc");
|
|
||||||
$this->assertIdentical($mock->aMethod(), "bbb");
|
|
||||||
$this->assertIdentical($mock->anotherMethod(), "ddd");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSequenceFallback() {
|
|
||||||
$mock = new MockDummy();
|
|
||||||
$mock->returnsByValueAt(0, "aMethod", "aaa", array('a'));
|
|
||||||
$mock->returnsByValueAt(1, "aMethod", "bbb", array('a'));
|
|
||||||
$mock->returnsByValue("aMethod", "AAA");
|
|
||||||
$this->assertIdentical($mock->aMethod('a'), "aaa");
|
|
||||||
$this->assertIdentical($mock->aMethod('b'), "AAA");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMethodInterference() {
|
|
||||||
$mock = new MockDummy();
|
|
||||||
$mock->returnsByValueAt(0, "anotherMethod", "aaa");
|
|
||||||
$mock->returnsByValue("aMethod", "AAA");
|
|
||||||
$this->assertIdentical($mock->aMethod(), "AAA");
|
|
||||||
$this->assertIdentical($mock->anotherMethod(), "aaa");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfMockExpectationsThatPass extends UnitTestCase {
|
|
||||||
|
|
||||||
function testAnyArgument() {
|
|
||||||
$mock = new MockDummy();
|
|
||||||
$mock->expect('aMethod', array('*'));
|
|
||||||
$mock->aMethod(1);
|
|
||||||
$mock->aMethod('hello');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testAnyTwoArguments() {
|
|
||||||
$mock = new MockDummy();
|
|
||||||
$mock->expect('aMethod', array('*', '*'));
|
|
||||||
$mock->aMethod(1, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSpecificArgument() {
|
|
||||||
$mock = new MockDummy();
|
|
||||||
$mock->expect('aMethod', array(1));
|
|
||||||
$mock->aMethod(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testExpectation() {
|
|
||||||
$mock = new MockDummy();
|
|
||||||
$mock->expect('aMethod', array(new IsAExpectation('Dummy')));
|
|
||||||
$mock->aMethod(new Dummy());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testArgumentsInSequence() {
|
|
||||||
$mock = new MockDummy();
|
|
||||||
$mock->expectAt(0, 'aMethod', array(1, 2));
|
|
||||||
$mock->expectAt(1, 'aMethod', array(3, 4));
|
|
||||||
$mock->aMethod(1, 2);
|
|
||||||
$mock->aMethod(3, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testAtLeastOnceSatisfiedByOneCall() {
|
|
||||||
$mock = new MockDummy();
|
|
||||||
$mock->expectAtLeastOnce('aMethod');
|
|
||||||
$mock->aMethod();
|
|
||||||
}
|
|
||||||
|
|
||||||
function testAtLeastOnceSatisfiedByTwoCalls() {
|
|
||||||
$mock = new MockDummy();
|
|
||||||
$mock->expectAtLeastOnce('aMethod');
|
|
||||||
$mock->aMethod();
|
|
||||||
$mock->aMethod();
|
|
||||||
}
|
|
||||||
|
|
||||||
function testOnceSatisfiedByOneCall() {
|
|
||||||
$mock = new MockDummy();
|
|
||||||
$mock->expectOnce('aMethod');
|
|
||||||
$mock->aMethod();
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMinimumCallsSatisfiedByEnoughCalls() {
|
|
||||||
$mock = new MockDummy();
|
|
||||||
$mock->expectMinimumCallCount('aMethod', 1);
|
|
||||||
$mock->aMethod();
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMinimumCallsSatisfiedByTooManyCalls() {
|
|
||||||
$mock = new MockDummy();
|
|
||||||
$mock->expectMinimumCallCount('aMethod', 3);
|
|
||||||
$mock->aMethod();
|
|
||||||
$mock->aMethod();
|
|
||||||
$mock->aMethod();
|
|
||||||
$mock->aMethod();
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMaximumCallsSatisfiedByEnoughCalls() {
|
|
||||||
$mock = new MockDummy();
|
|
||||||
$mock->expectMaximumCallCount('aMethod', 1);
|
|
||||||
$mock->aMethod();
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMaximumCallsSatisfiedByNoCalls() {
|
|
||||||
$mock = new MockDummy();
|
|
||||||
$mock->expectMaximumCallCount('aMethod', 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class MockWithInjectedTestCase extends SimpleMock {
|
|
||||||
protected function getCurrentTestCase() {
|
|
||||||
return SimpleTest::getContext()->getTest()->getMockedTest();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SimpleTest::setMockBaseClass('MockWithInjectedTestCase');
|
|
||||||
Mock::generate('Dummy', 'MockDummyWithInjectedTestCase');
|
|
||||||
SimpleTest::setMockBaseClass('SimpleMock');
|
|
||||||
Mock::generate('SimpleTestCase');
|
|
||||||
|
|
||||||
class LikeExpectation extends IdenticalExpectation {
|
|
||||||
function __construct($expectation) {
|
|
||||||
$expectation->message = '';
|
|
||||||
parent::__construct($expectation);
|
|
||||||
}
|
|
||||||
|
|
||||||
function test($compare) {
|
|
||||||
$compare->message = '';
|
|
||||||
return parent::test($compare);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMessage($compare) {
|
|
||||||
$compare->message = '';
|
|
||||||
return parent::testMessage($compare);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfMockExpectations extends UnitTestCase {
|
|
||||||
private $test;
|
|
||||||
|
|
||||||
function setUp() {
|
|
||||||
$this->test = new MockSimpleTestCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
function getMockedTest() {
|
|
||||||
return $this->test;
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSettingExpectationOnNonMethodThrowsError() {
|
|
||||||
$mock = new MockDummyWithInjectedTestCase();
|
|
||||||
$this->expectError();
|
|
||||||
$mock->expectMaximumCallCount('aMissingMethod', 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMaxCallsDetectsOverrun() {
|
|
||||||
$this->test->expectOnce('assert', array(new MemberExpectation('count', 2), 3));
|
|
||||||
$mock = new MockDummyWithInjectedTestCase();
|
|
||||||
$mock->expectMaximumCallCount('aMethod', 2);
|
|
||||||
$mock->aMethod();
|
|
||||||
$mock->aMethod();
|
|
||||||
$mock->aMethod();
|
|
||||||
$mock->mock->atTestEnd('testSomething', $this->test);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testTallyOnMaxCallsSendsPassOnUnderrun() {
|
|
||||||
$this->test->expectOnce('assert', array(new MemberExpectation('count', 2), 2));
|
|
||||||
$mock = new MockDummyWithInjectedTestCase();
|
|
||||||
$mock->expectMaximumCallCount("aMethod", 2);
|
|
||||||
$mock->aMethod();
|
|
||||||
$mock->aMethod();
|
|
||||||
$mock->mock->atTestEnd('testSomething', $this->test);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testExpectNeverDetectsOverrun() {
|
|
||||||
$this->test->expectOnce('assert', array(new MemberExpectation('count', 0), 1));
|
|
||||||
$mock = new MockDummyWithInjectedTestCase();
|
|
||||||
$mock->expectNever('aMethod');
|
|
||||||
$mock->aMethod();
|
|
||||||
$mock->mock->atTestEnd('testSomething', $this->test);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testTallyOnExpectNeverStillSendsPassOnUnderrun() {
|
|
||||||
$this->test->expectOnce('assert', array(new MemberExpectation('count', 0), 0));
|
|
||||||
$mock = new MockDummyWithInjectedTestCase();
|
|
||||||
$mock->expectNever('aMethod');
|
|
||||||
$mock->mock->atTestEnd('testSomething', $this->test);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMinCalls() {
|
|
||||||
$this->test->expectOnce('assert', array(new MemberExpectation('count', 2), 2));
|
|
||||||
$mock = new MockDummyWithInjectedTestCase();
|
|
||||||
$mock->expectMinimumCallCount('aMethod', 2);
|
|
||||||
$mock->aMethod();
|
|
||||||
$mock->aMethod();
|
|
||||||
$mock->mock->atTestEnd('testSomething', $this->test);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFailedNever() {
|
|
||||||
$this->test->expectOnce('assert', array(new MemberExpectation('count', 0), 1));
|
|
||||||
$mock = new MockDummyWithInjectedTestCase();
|
|
||||||
$mock->expectNever('aMethod');
|
|
||||||
$mock->aMethod();
|
|
||||||
$mock->mock->atTestEnd('testSomething', $this->test);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testUnderOnce() {
|
|
||||||
$this->test->expectOnce('assert', array(new MemberExpectation('count', 1), 0));
|
|
||||||
$mock = new MockDummyWithInjectedTestCase();
|
|
||||||
$mock->expectOnce('aMethod');
|
|
||||||
$mock->mock->atTestEnd('testSomething', $this->test);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testOverOnce() {
|
|
||||||
$this->test->expectOnce('assert', array(new MemberExpectation('count', 1), 2));
|
|
||||||
$mock = new MockDummyWithInjectedTestCase();
|
|
||||||
$mock->expectOnce('aMethod');
|
|
||||||
$mock->aMethod();
|
|
||||||
$mock->aMethod();
|
|
||||||
$mock->mock->atTestEnd('testSomething', $this->test);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testUnderAtLeastOnce() {
|
|
||||||
$this->test->expectOnce('assert', array(new MemberExpectation('count', 1), 0));
|
|
||||||
$mock = new MockDummyWithInjectedTestCase();
|
|
||||||
$mock->expectAtLeastOnce("aMethod");
|
|
||||||
$mock->mock->atTestEnd('testSomething', $this->test);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testZeroArguments() {
|
|
||||||
$this->test->expectOnce('assert',
|
|
||||||
array(new MemberExpectation('expected', array()), array(), '*'));
|
|
||||||
$mock = new MockDummyWithInjectedTestCase();
|
|
||||||
$mock->expect('aMethod', array());
|
|
||||||
$mock->aMethod();
|
|
||||||
$mock->mock->atTestEnd('testSomething', $this->test);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testExpectedArguments() {
|
|
||||||
$this->test->expectOnce('assert',
|
|
||||||
array(new MemberExpectation('expected', array(1, 2, 3)), array(1, 2, 3), '*'));
|
|
||||||
$mock = new MockDummyWithInjectedTestCase();
|
|
||||||
$mock->expect('aMethod', array(1, 2, 3));
|
|
||||||
$mock->aMethod(1, 2, 3);
|
|
||||||
$mock->mock->atTestEnd('testSomething', $this->test);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFailedArguments() {
|
|
||||||
$this->test->expectOnce('assert',
|
|
||||||
array(new MemberExpectation('expected', array('this')), array('that'), '*'));
|
|
||||||
$mock = new MockDummyWithInjectedTestCase();
|
|
||||||
$mock->expect('aMethod', array('this'));
|
|
||||||
$mock->aMethod('that');
|
|
||||||
$mock->mock->atTestEnd('testSomething', $this->test);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testWildcardsAreTranslatedToAnythingExpectations() {
|
|
||||||
$this->test->expectOnce('assert',
|
|
||||||
array(new MemberExpectation('expected',
|
|
||||||
array(new AnythingExpectation(),
|
|
||||||
123,
|
|
||||||
new AnythingExpectation())),
|
|
||||||
array(100, 123, 101), '*'));
|
|
||||||
$mock = new MockDummyWithInjectedTestCase($this);
|
|
||||||
$mock->expect("aMethod", array('*', 123, '*'));
|
|
||||||
$mock->aMethod(100, 123, 101);
|
|
||||||
$mock->mock->atTestEnd('testSomething', $this->test);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSpecificPassingSequence() {
|
|
||||||
$this->test->expectAt(0, 'assert',
|
|
||||||
array(new MemberExpectation('expected', array(1, 2, 3)), array(1, 2, 3), '*'));
|
|
||||||
$this->test->expectAt(1, 'assert',
|
|
||||||
array(new MemberExpectation('expected', array('Hello')), array('Hello'), '*'));
|
|
||||||
$mock = new MockDummyWithInjectedTestCase();
|
|
||||||
$mock->expectAt(1, 'aMethod', array(1, 2, 3));
|
|
||||||
$mock->expectAt(2, 'aMethod', array('Hello'));
|
|
||||||
$mock->aMethod();
|
|
||||||
$mock->aMethod(1, 2, 3);
|
|
||||||
$mock->aMethod('Hello');
|
|
||||||
$mock->aMethod();
|
|
||||||
$mock->mock->atTestEnd('testSomething', $this->test);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testNonArrayForExpectedParametersGivesError() {
|
|
||||||
$mock = new MockDummyWithInjectedTestCase();
|
|
||||||
$this->expectError(new PatternExpectation('/\$args.*not an array/i'));
|
|
||||||
$mock->expect("aMethod", "foo");
|
|
||||||
$mock->aMethod();
|
|
||||||
$mock->mock->atTestEnd('testSomething', $this->test);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfMockComparisons extends UnitTestCase {
|
|
||||||
|
|
||||||
function testEqualComparisonOfMocksDoesNotCrash() {
|
|
||||||
$expectation = new EqualExpectation(new MockDummy());
|
|
||||||
$this->assertTrue($expectation->test(new MockDummy(), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testIdenticalComparisonOfMocksDoesNotCrash() {
|
|
||||||
$expectation = new IdenticalExpectation(new MockDummy());
|
|
||||||
$this->assertTrue($expectation->test(new MockDummy()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ClassWithSpecialMethods {
|
|
||||||
function __get($name) { }
|
|
||||||
function __set($name, $value) { }
|
|
||||||
function __isset($name) { }
|
|
||||||
function __unset($name) { }
|
|
||||||
function __call($method, $arguments) { }
|
|
||||||
function __toString() { }
|
|
||||||
}
|
|
||||||
Mock::generate('ClassWithSpecialMethods');
|
|
||||||
|
|
||||||
class TestOfSpecialMethodsAfterPHP51 extends UnitTestCase {
|
|
||||||
|
|
||||||
function skip() {
|
|
||||||
$this->skipIf(version_compare(phpversion(), '5.1', '<'), '__isset and __unset overloading not tested unless PHP 5.1+');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanEmulateIsset() {
|
|
||||||
$mock = new MockClassWithSpecialMethods();
|
|
||||||
$mock->returnsByValue('__isset', true);
|
|
||||||
$this->assertIdentical(isset($mock->a), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanExpectUnset() {
|
|
||||||
$mock = new MockClassWithSpecialMethods();
|
|
||||||
$mock->expectOnce('__unset', array('a'));
|
|
||||||
unset($mock->a);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfSpecialMethods extends UnitTestCase {
|
|
||||||
function skip() {
|
|
||||||
$this->skipIf(version_compare(phpversion(), '5', '<'), 'Overloading not tested unless PHP 5+');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanMockTheThingAtAll() {
|
|
||||||
$mock = new MockClassWithSpecialMethods();
|
|
||||||
}
|
|
||||||
|
|
||||||
function testReturnFromSpecialAccessor() {
|
|
||||||
$mock = new MockClassWithSpecialMethods();
|
|
||||||
$mock->returnsByValue('__get', '1st Return', array('first'));
|
|
||||||
$mock->returnsByValue('__get', '2nd Return', array('second'));
|
|
||||||
$this->assertEqual($mock->first, '1st Return');
|
|
||||||
$this->assertEqual($mock->second, '2nd Return');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testcanExpectTheSettingOfValue() {
|
|
||||||
$mock = new MockClassWithSpecialMethods();
|
|
||||||
$mock->expectOnce('__set', array('a', 'A'));
|
|
||||||
$mock->a = 'A';
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanSimulateAnOverloadmethod() {
|
|
||||||
$mock = new MockClassWithSpecialMethods();
|
|
||||||
$mock->expectOnce('__call', array('amOverloaded', array('A')));
|
|
||||||
$mock->returnsByValue('__call', 'aaa');
|
|
||||||
$this->assertIdentical($mock->amOverloaded('A'), 'aaa');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testToStringMagic() {
|
|
||||||
$mock = new MockClassWithSpecialMethods();
|
|
||||||
$mock->expectOnce('__toString');
|
|
||||||
$mock->returnsByValue('__toString', 'AAA');
|
|
||||||
ob_start();
|
|
||||||
print $mock;
|
|
||||||
$output = ob_get_contents();
|
|
||||||
ob_end_clean();
|
|
||||||
$this->assertEqual($output, 'AAA');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class WithStaticMethod {
|
|
||||||
static function aStaticMethod() { }
|
|
||||||
}
|
|
||||||
Mock::generate('WithStaticMethod');
|
|
||||||
|
|
||||||
class TestOfMockingClassesWithStaticMethods extends UnitTestCase {
|
|
||||||
|
|
||||||
function testStaticMethodIsMockedAsStatic() {
|
|
||||||
$mock = new WithStaticMethod();
|
|
||||||
$reflection = new ReflectionClass($mock);
|
|
||||||
$method = $reflection->getMethod('aStaticMethod');
|
|
||||||
$this->assertTrue($method->isStatic());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class MockTestException extends Exception { }
|
|
||||||
|
|
||||||
class TestOfThrowingExceptionsFromMocks extends UnitTestCase {
|
|
||||||
|
|
||||||
function testCanThrowOnMethodCall() {
|
|
||||||
$mock = new MockDummy();
|
|
||||||
$mock->throwOn('aMethod');
|
|
||||||
$this->expectException();
|
|
||||||
$mock->aMethod();
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanThrowSpecificExceptionOnMethodCall() {
|
|
||||||
$mock = new MockDummy();
|
|
||||||
$mock->throwOn('aMethod', new MockTestException());
|
|
||||||
$this->expectException();
|
|
||||||
$mock->aMethod();
|
|
||||||
}
|
|
||||||
|
|
||||||
function testThrowsOnlyWhenCallSignatureMatches() {
|
|
||||||
$mock = new MockDummy();
|
|
||||||
$mock->throwOn('aMethod', new MockTestException(), array(3));
|
|
||||||
$mock->aMethod(1);
|
|
||||||
$mock->aMethod(2);
|
|
||||||
$this->expectException();
|
|
||||||
$mock->aMethod(3);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanThrowOnParticularInvocation() {
|
|
||||||
$mock = new MockDummy();
|
|
||||||
$mock->throwAt(2, 'aMethod', new MockTestException());
|
|
||||||
$mock->aMethod();
|
|
||||||
$mock->aMethod();
|
|
||||||
$this->expectException();
|
|
||||||
$mock->aMethod();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfThrowingErrorsFromMocks extends UnitTestCase {
|
|
||||||
|
|
||||||
function testCanGenerateErrorFromMethodCall() {
|
|
||||||
$mock = new MockDummy();
|
|
||||||
$mock->errorOn('aMethod', 'Ouch!');
|
|
||||||
$this->expectError('Ouch!');
|
|
||||||
$mock->aMethod();
|
|
||||||
}
|
|
||||||
|
|
||||||
function testGeneratesErrorOnlyWhenCallSignatureMatches() {
|
|
||||||
$mock = new MockDummy();
|
|
||||||
$mock->errorOn('aMethod', 'Ouch!', array(3));
|
|
||||||
$mock->aMethod(1);
|
|
||||||
$mock->aMethod(2);
|
|
||||||
$this->expectError();
|
|
||||||
$mock->aMethod(3);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanGenerateErrorOnParticularInvocation() {
|
|
||||||
$mock = new MockDummy();
|
|
||||||
$mock->errorAt(2, 'aMethod', 'Ouch!');
|
|
||||||
$mock->aMethod();
|
|
||||||
$mock->aMethod();
|
|
||||||
$this->expectError();
|
|
||||||
$mock->aMethod();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Mock::generatePartial('Dummy', 'TestDummy', array('anotherMethod', 'aReferenceMethod'));
|
|
||||||
|
|
||||||
class TestOfPartialMocks extends UnitTestCase {
|
|
||||||
|
|
||||||
function testMethodReplacementWithNoBehaviourReturnsNull() {
|
|
||||||
$mock = new TestDummy();
|
|
||||||
$this->assertEqual($mock->aMethod(99), 99);
|
|
||||||
$this->assertNull($mock->anotherMethod());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSettingReturns() {
|
|
||||||
$mock = new TestDummy();
|
|
||||||
$mock->returnsByValue('anotherMethod', 33, array(3));
|
|
||||||
$mock->returnsByValue('anotherMethod', 22);
|
|
||||||
$mock->returnsByValueAt(2, 'anotherMethod', 44, array(3));
|
|
||||||
$this->assertEqual($mock->anotherMethod(), 22);
|
|
||||||
$this->assertEqual($mock->anotherMethod(3), 33);
|
|
||||||
$this->assertEqual($mock->anotherMethod(3), 44);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSetReturnReferenceGivesOriginal() {
|
|
||||||
$mock = new TestDummy();
|
|
||||||
$object = 99;
|
|
||||||
$mock->returnsByReferenceAt(0, 'aReferenceMethod', $object, array(3));
|
|
||||||
$this->assertReference($mock->aReferenceMethod(3), $object);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testReturnsAtGivesOriginalObjectHandle() {
|
|
||||||
$mock = new TestDummy();
|
|
||||||
$object = new Dummy();
|
|
||||||
$mock->returnsAt(0, 'anotherMethod', $object, array(3));
|
|
||||||
$this->assertSame($mock->anotherMethod(3), $object);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testExpectations() {
|
|
||||||
$mock = new TestDummy();
|
|
||||||
$mock->expectCallCount('anotherMethod', 2);
|
|
||||||
$mock->expect('anotherMethod', array(77));
|
|
||||||
$mock->expectAt(1, 'anotherMethod', array(66));
|
|
||||||
$mock->anotherMethod(77);
|
|
||||||
$mock->anotherMethod(66);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSettingExpectationOnMissingMethodThrowsError() {
|
|
||||||
$mock = new TestDummy();
|
|
||||||
$this->expectError();
|
|
||||||
$mock->expectCallCount('aMissingMethod', 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ConstructorSuperClass {
|
|
||||||
function ConstructorSuperClass() { }
|
|
||||||
}
|
|
||||||
|
|
||||||
class ConstructorSubClass extends ConstructorSuperClass { }
|
|
||||||
|
|
||||||
class TestOfPHP4StyleSuperClassConstruct extends UnitTestCase {
|
|
||||||
function testBasicConstruct() {
|
|
||||||
Mock::generate('ConstructorSubClass');
|
|
||||||
$mock = new MockConstructorSubClass();
|
|
||||||
$this->assertIsA($mock, 'ConstructorSubClass');
|
|
||||||
$this->assertTrue(method_exists($mock, 'ConstructorSuperClass'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfPHP5StaticMethodMocking extends UnitTestCase {
|
|
||||||
function testCanCreateAMockObjectWithStaticMethodsWithoutError() {
|
|
||||||
eval('
|
|
||||||
class SimpleObjectContainingStaticMethod {
|
|
||||||
static function someStatic() { }
|
|
||||||
}
|
|
||||||
');
|
|
||||||
Mock::generate('SimpleObjectContainingStaticMethod');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfPHP5AbstractMethodMocking extends UnitTestCase {
|
|
||||||
function testCanCreateAMockObjectFromAnAbstractWithProperFunctionDeclarations() {
|
|
||||||
eval('
|
|
||||||
abstract class SimpleAbstractClassContainingAbstractMethods {
|
|
||||||
abstract function anAbstract();
|
|
||||||
abstract function anAbstractWithParameter($foo);
|
|
||||||
abstract function anAbstractWithMultipleParameters($foo, $bar);
|
|
||||||
}
|
|
||||||
');
|
|
||||||
Mock::generate('SimpleAbstractClassContainingAbstractMethods');
|
|
||||||
$this->assertTrue(
|
|
||||||
method_exists(
|
|
||||||
// Testing with class name alone does not work in PHP 5.0
|
|
||||||
new MockSimpleAbstractClassContainingAbstractMethods,
|
|
||||||
'anAbstract'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$this->assertTrue(
|
|
||||||
method_exists(
|
|
||||||
new MockSimpleAbstractClassContainingAbstractMethods,
|
|
||||||
'anAbstractWithParameter'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$this->assertTrue(
|
|
||||||
method_exists(
|
|
||||||
new MockSimpleAbstractClassContainingAbstractMethods,
|
|
||||||
'anAbstractWithMultipleParameters'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMethodsDefinedAsAbstractInParentShouldHaveFullSignature() {
|
|
||||||
eval('
|
|
||||||
abstract class SimpleParentAbstractClassContainingAbstractMethods {
|
|
||||||
abstract function anAbstract();
|
|
||||||
abstract function anAbstractWithParameter($foo);
|
|
||||||
abstract function anAbstractWithMultipleParameters($foo, $bar);
|
|
||||||
}
|
|
||||||
|
|
||||||
class SimpleChildAbstractClassContainingAbstractMethods extends SimpleParentAbstractClassContainingAbstractMethods {
|
|
||||||
function anAbstract(){}
|
|
||||||
function anAbstractWithParameter($foo){}
|
|
||||||
function anAbstractWithMultipleParameters($foo, $bar){}
|
|
||||||
}
|
|
||||||
|
|
||||||
class EvenDeeperEmptyChildClass extends SimpleChildAbstractClassContainingAbstractMethods {}
|
|
||||||
');
|
|
||||||
Mock::generate('SimpleChildAbstractClassContainingAbstractMethods');
|
|
||||||
$this->assertTrue(
|
|
||||||
method_exists(
|
|
||||||
new MockSimpleChildAbstractClassContainingAbstractMethods,
|
|
||||||
'anAbstract'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$this->assertTrue(
|
|
||||||
method_exists(
|
|
||||||
new MockSimpleChildAbstractClassContainingAbstractMethods,
|
|
||||||
'anAbstractWithParameter'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$this->assertTrue(
|
|
||||||
method_exists(
|
|
||||||
new MockSimpleChildAbstractClassContainingAbstractMethods,
|
|
||||||
'anAbstractWithMultipleParameters'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
Mock::generate('EvenDeeperEmptyChildClass');
|
|
||||||
$this->assertTrue(
|
|
||||||
method_exists(
|
|
||||||
new MockEvenDeeperEmptyChildClass,
|
|
||||||
'anAbstract'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$this->assertTrue(
|
|
||||||
method_exists(
|
|
||||||
new MockEvenDeeperEmptyChildClass,
|
|
||||||
'anAbstractWithParameter'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$this->assertTrue(
|
|
||||||
method_exists(
|
|
||||||
new MockEvenDeeperEmptyChildClass,
|
|
||||||
'anAbstractWithMultipleParameters'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class DummyWithProtected
|
|
||||||
{
|
|
||||||
public function aMethodCallsProtected() { return $this->aProtectedMethod(); }
|
|
||||||
protected function aProtectedMethod() { return true; }
|
|
||||||
}
|
|
||||||
|
|
||||||
Mock::generatePartial('DummyWithProtected', 'TestDummyWithProtected', array('aProtectedMethod'));
|
|
||||||
class TestOfProtectedMethodPartialMocks extends UnitTestCase
|
|
||||||
{
|
|
||||||
function testProtectedMethodExists() {
|
|
||||||
$this->assertTrue(
|
|
||||||
method_exists(
|
|
||||||
new TestDummyWithProtected,
|
|
||||||
'aProtectedMethod'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testProtectedMethodIsCalled() {
|
|
||||||
$object = new DummyWithProtected();
|
|
||||||
$this->assertTrue($object->aMethodCallsProtected(), 'ensure original was called');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMockedMethodIsCalled() {
|
|
||||||
$object = new TestDummyWithProtected();
|
|
||||||
$object->returnsByValue('aProtectedMethod', false);
|
|
||||||
$this->assertFalse($object->aMethodCallsProtected());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
|
@ -1,166 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: page_test.php 1913 2009-07-29 16:50:56Z lastcraft $
|
|
||||||
require_once(dirname(__FILE__) . '/../autorun.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../expectation.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../http.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../page.php');
|
|
||||||
Mock::generate('SimpleHttpHeaders');
|
|
||||||
Mock::generate('SimpleHttpResponse');
|
|
||||||
|
|
||||||
class TestOfPageInterface extends UnitTestCase {
|
|
||||||
function testInterfaceOnEmptyPage() {
|
|
||||||
$page = new SimplePage();
|
|
||||||
$this->assertEqual($page->getTransportError(), 'No page fetched yet');
|
|
||||||
$this->assertIdentical($page->getRaw(), false);
|
|
||||||
$this->assertIdentical($page->getHeaders(), false);
|
|
||||||
$this->assertIdentical($page->getMimeType(), false);
|
|
||||||
$this->assertIdentical($page->getResponseCode(), false);
|
|
||||||
$this->assertIdentical($page->getAuthentication(), false);
|
|
||||||
$this->assertIdentical($page->getRealm(), false);
|
|
||||||
$this->assertFalse($page->hasFrames());
|
|
||||||
$this->assertIdentical($page->getUrls(), array());
|
|
||||||
$this->assertIdentical($page->getTitle(), false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfPageHeaders extends UnitTestCase {
|
|
||||||
|
|
||||||
function testUrlAccessor() {
|
|
||||||
$headers = new MockSimpleHttpHeaders();
|
|
||||||
|
|
||||||
$response = new MockSimpleHttpResponse();
|
|
||||||
$response->setReturnValue('getHeaders', $headers);
|
|
||||||
$response->setReturnValue('getMethod', 'POST');
|
|
||||||
$response->setReturnValue('getUrl', new SimpleUrl('here'));
|
|
||||||
$response->setReturnValue('getRequestData', array('a' => 'A'));
|
|
||||||
|
|
||||||
$page = new SimplePage($response);
|
|
||||||
$this->assertEqual($page->getMethod(), 'POST');
|
|
||||||
$this->assertEqual($page->getUrl(), new SimpleUrl('here'));
|
|
||||||
$this->assertEqual($page->getRequestData(), array('a' => 'A'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testTransportError() {
|
|
||||||
$response = new MockSimpleHttpResponse();
|
|
||||||
$response->setReturnValue('getError', 'Ouch');
|
|
||||||
|
|
||||||
$page = new SimplePage($response);
|
|
||||||
$this->assertEqual($page->getTransportError(), 'Ouch');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testHeadersAccessor() {
|
|
||||||
$headers = new MockSimpleHttpHeaders();
|
|
||||||
$headers->setReturnValue('getRaw', 'My: Headers');
|
|
||||||
|
|
||||||
$response = new MockSimpleHttpResponse();
|
|
||||||
$response->setReturnValue('getHeaders', $headers);
|
|
||||||
|
|
||||||
$page = new SimplePage($response);
|
|
||||||
$this->assertEqual($page->getHeaders(), 'My: Headers');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMimeAccessor() {
|
|
||||||
$headers = new MockSimpleHttpHeaders();
|
|
||||||
$headers->setReturnValue('getMimeType', 'text/html');
|
|
||||||
|
|
||||||
$response = new MockSimpleHttpResponse();
|
|
||||||
$response->setReturnValue('getHeaders', $headers);
|
|
||||||
|
|
||||||
$page = new SimplePage($response);
|
|
||||||
$this->assertEqual($page->getMimeType(), 'text/html');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testResponseAccessor() {
|
|
||||||
$headers = new MockSimpleHttpHeaders();
|
|
||||||
$headers->setReturnValue('getResponseCode', 301);
|
|
||||||
|
|
||||||
$response = new MockSimpleHttpResponse();
|
|
||||||
$response->setReturnValue('getHeaders', $headers);
|
|
||||||
|
|
||||||
$page = new SimplePage($response);
|
|
||||||
$this->assertIdentical($page->getResponseCode(), 301);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testAuthenticationAccessors() {
|
|
||||||
$headers = new MockSimpleHttpHeaders();
|
|
||||||
$headers->setReturnValue('getAuthentication', 'Basic');
|
|
||||||
$headers->setReturnValue('getRealm', 'Secret stuff');
|
|
||||||
|
|
||||||
$response = new MockSimpleHttpResponse();
|
|
||||||
$response->setReturnValue('getHeaders', $headers);
|
|
||||||
|
|
||||||
$page = new SimplePage($response);
|
|
||||||
$this->assertEqual($page->getAuthentication(), 'Basic');
|
|
||||||
$this->assertEqual($page->getRealm(), 'Secret stuff');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfHtmlStrippingAndNormalisation extends UnitTestCase {
|
|
||||||
|
|
||||||
function testImageSuppressionWhileKeepingParagraphsAndAltText() {
|
|
||||||
$this->assertEqual(
|
|
||||||
SimplePage::normalise('<img src="foo.png" /><p>some text</p><img src="bar.png" alt="bar" />'),
|
|
||||||
'some text bar');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSpaceNormalisation() {
|
|
||||||
$this->assertEqual(
|
|
||||||
SimplePage::normalise("\nOne\tTwo \nThree\t"),
|
|
||||||
'One Two Three');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMultilinesCommentSuppression() {
|
|
||||||
$this->assertEqual(
|
|
||||||
SimplePage::normalise('<!--\n Hello \n-->'),
|
|
||||||
'');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCommentSuppression() {
|
|
||||||
$this->assertEqual(
|
|
||||||
SimplePage::normalise('<!--Hello-->'),
|
|
||||||
'');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testJavascriptSuppression() {
|
|
||||||
$this->assertEqual(
|
|
||||||
SimplePage::normalise('<script attribute="test">\nHello\n</script>'),
|
|
||||||
'');
|
|
||||||
$this->assertEqual(
|
|
||||||
SimplePage::normalise('<script attribute="test">Hello</script>'),
|
|
||||||
'');
|
|
||||||
$this->assertEqual(
|
|
||||||
SimplePage::normalise('<script>Hello</script>'),
|
|
||||||
'');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testTagSuppression() {
|
|
||||||
$this->assertEqual(
|
|
||||||
SimplePage::normalise('<b>Hello</b>'),
|
|
||||||
'Hello');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testAdjoiningTagSuppression() {
|
|
||||||
$this->assertEqual(
|
|
||||||
SimplePage::normalise('<b>Hello</b><em>Goodbye</em>'),
|
|
||||||
'HelloGoodbye');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testExtractImageAltTextWithDifferentQuotes() {
|
|
||||||
$this->assertEqual(
|
|
||||||
SimplePage::normalise('<img alt="One"><img alt=\'Two\'><img alt=Three>'),
|
|
||||||
'One Two Three');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testExtractImageAltTextMultipleTimes() {
|
|
||||||
$this->assertEqual(
|
|
||||||
SimplePage::normalise('<img alt="One"><img alt="Two"><img alt="Three">'),
|
|
||||||
'One Two Three');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testHtmlEntityTranslation() {
|
|
||||||
$this->assertEqual(
|
|
||||||
SimplePage::normalise('<>"&''),
|
|
||||||
'<>"&\'');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,9 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: parse_error_test.php 1509 2007-05-08 22:11:49Z lastcraft $
|
|
||||||
require_once('../unit_tester.php');
|
|
||||||
require_once('../reporter.php');
|
|
||||||
|
|
||||||
$test = &new TestSuite('This should fail');
|
|
||||||
$test->addFile('test_with_parse_error.php');
|
|
||||||
$test->run(new HtmlReporter());
|
|
||||||
?>
|
|
|
@ -1,642 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: page_test.php 1912 2009-07-29 16:39:17Z lastcraft $
|
|
||||||
require_once(dirname(__FILE__) . '/../autorun.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../page.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../php_parser.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../tidy_parser.php');
|
|
||||||
Mock::generate('SimpleHttpResponse');
|
|
||||||
|
|
||||||
abstract class TestOfParsing extends UnitTestCase {
|
|
||||||
|
|
||||||
function testRawAccessor() {
|
|
||||||
$page = $this->whenVisiting('http://host/', 'Raw HTML');
|
|
||||||
$this->assertEqual($page->getRaw(), 'Raw HTML');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testTextAccessor() {
|
|
||||||
$page = $this->whenVisiting('http://host/', '<b>Some</b> "messy" HTML');
|
|
||||||
$this->assertEqual($page->getText(), 'Some "messy" HTML');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFramesetAbsence() {
|
|
||||||
$page = $this->whenVisiting('http://here/', '');
|
|
||||||
$this->assertFalse($page->hasFrames());
|
|
||||||
$this->assertIdentical($page->getFrameset(), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testPageWithNoUrlsGivesEmptyArrayOfLinks() {
|
|
||||||
$page = $this->whenVisiting('http://here/', '<html><body><p>Stuff</p></body></html>');
|
|
||||||
$this->assertIdentical($page->getUrls(), array());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testAddAbsoluteLink() {
|
|
||||||
$page = $this->whenVisiting('http://host',
|
|
||||||
'<html><a href="http://somewhere.com">Label</a></html>');
|
|
||||||
$this->assertEqual(
|
|
||||||
$page->getUrlsByLabel('Label'),
|
|
||||||
array(new SimpleUrl('http://somewhere.com')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testUrlLabelsHaveHtmlTagsStripped() {
|
|
||||||
$page = $this->whenVisiting('http://host',
|
|
||||||
'<html><a href="http://somewhere.com"><b>Label</b></a></html>');
|
|
||||||
$this->assertEqual(
|
|
||||||
$page->getUrlsByLabel('Label'),
|
|
||||||
array(new SimpleUrl('http://somewhere.com')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testAddStrictRelativeLink() {
|
|
||||||
$page = $this->whenVisiting('http://host',
|
|
||||||
'<html><a href="./somewhere.php">Label</a></html>');
|
|
||||||
$this->assertEqual(
|
|
||||||
$page->getUrlsByLabel('Label'),
|
|
||||||
array(new SimpleUrl('http://host/somewhere.php')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testAddBareRelativeLink() {
|
|
||||||
$page = $this->whenVisiting('http://host',
|
|
||||||
'<html><a href="somewhere.php">Label</a></html>');
|
|
||||||
$this->assertEqual(
|
|
||||||
$page->getUrlsByLabel('Label'),
|
|
||||||
array(new SimpleUrl('http://host/somewhere.php')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testAddRelativeLinkWithBaseTag() {
|
|
||||||
$raw = '<html><head><base href="http://www.lastcraft.com/stuff/"></head>' .
|
|
||||||
'<body><a href="somewhere.php">Label</a></body>' .
|
|
||||||
'</html>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertEqual(
|
|
||||||
$page->getUrlsByLabel('Label'),
|
|
||||||
array(new SimpleUrl('http://www.lastcraft.com/stuff/somewhere.php')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testAddAbsoluteLinkWithBaseTag() {
|
|
||||||
$raw = '<html><head><base href="http://www.lastcraft.com/stuff/"></head>' .
|
|
||||||
'<body><a href="http://here.com/somewhere.php">Label</a></body>' .
|
|
||||||
'</html>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertEqual(
|
|
||||||
$page->getUrlsByLabel('Label'),
|
|
||||||
array(new SimpleUrl('http://here.com/somewhere.php')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanFindLinkInsideForm() {
|
|
||||||
$raw = '<html><body><form><a href="./somewhere.php">Label</a></form></body></html>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertEqual(
|
|
||||||
$page->getUrlsByLabel('Label'),
|
|
||||||
array(new SimpleUrl('http://host/somewhere.php')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanGetLinksByIdOrLabel() {
|
|
||||||
$raw = '<html><body><a href="./somewhere.php" id="33">Label</a></body></html>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertEqual(
|
|
||||||
$page->getUrlsByLabel('Label'),
|
|
||||||
array(new SimpleUrl('http://host/somewhere.php')));
|
|
||||||
$this->assertFalse($page->getUrlById(0));
|
|
||||||
$this->assertEqual(
|
|
||||||
$page->getUrlById(33),
|
|
||||||
new SimpleUrl('http://host/somewhere.php'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanFindLinkByNormalisedLabel() {
|
|
||||||
$raw = '<html><body><a href="./somewhere.php" id="33"><em>Long & thin</em></a></body></html>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertEqual(
|
|
||||||
$page->getUrlsByLabel('Long & thin'),
|
|
||||||
array(new SimpleUrl('http://host/somewhere.php')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanFindLinkByImageAltText() {
|
|
||||||
$raw = '<a href="./somewhere.php" id="33"><img src="pic.jpg" alt="<A picture>"></a>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertEqual(
|
|
||||||
array_map(array($this, 'urlToString'), $page->getUrlsByLabel('<A picture>')),
|
|
||||||
array('http://host/somewhere.php'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testTitle() {
|
|
||||||
$page = $this->whenVisiting('http://host',
|
|
||||||
'<html><head><title>Me</title></head></html>');
|
|
||||||
$this->assertEqual($page->getTitle(), 'Me');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testTitleWithEntityReference() {
|
|
||||||
$page = $this->whenVisiting('http://host',
|
|
||||||
'<html><head><Title>Me&Me</TITLE></head></html>');
|
|
||||||
$this->assertEqual($page->getTitle(), "Me&Me");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testOnlyFramesInFramesetAreRecognised() {
|
|
||||||
$raw =
|
|
||||||
'<frameset>' .
|
|
||||||
' <frame src="2.html"></frame>' .
|
|
||||||
' <frame src="3.html"></frame>' .
|
|
||||||
'</frameset>' .
|
|
||||||
'<frame src="4.html"></frame>';
|
|
||||||
$page = $this->whenVisiting('http://here', $raw);
|
|
||||||
$this->assertTrue($page->hasFrames());
|
|
||||||
$this->assertSameFrameset($page->getFrameset(), array(
|
|
||||||
1 => new SimpleUrl('http://here/2.html'),
|
|
||||||
2 => new SimpleUrl('http://here/3.html')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testReadsNamesInFrames() {
|
|
||||||
$raw =
|
|
||||||
'<frameset>' .
|
|
||||||
' <frame src="1.html"></frame>' .
|
|
||||||
' <frame src="2.html" name="A"></frame>' .
|
|
||||||
' <frame src="3.html" name="B"></frame>' .
|
|
||||||
' <frame src="4.html"></frame>' .
|
|
||||||
'</frameset>';
|
|
||||||
$page = $this->whenVisiting('http://here', $raw);
|
|
||||||
$this->assertTrue($page->hasFrames());
|
|
||||||
$this->assertSameFrameset($page->getFrameset(), array(
|
|
||||||
1 => new SimpleUrl('http://here/1.html'),
|
|
||||||
'A' => new SimpleUrl('http://here/2.html'),
|
|
||||||
'B' => new SimpleUrl('http://here/3.html'),
|
|
||||||
4 => new SimpleUrl('http://here/4.html')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testRelativeFramesRespectBaseTag() {
|
|
||||||
$raw = '<base href="https://there.com/stuff/"><frameset><frame src="1.html"></frameset>';
|
|
||||||
$page = $this->whenVisiting('http://here', $raw);
|
|
||||||
$this->assertSameFrameset(
|
|
||||||
$page->getFrameset(),
|
|
||||||
array(1 => new SimpleUrl('https://there.com/stuff/1.html')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSingleFrameInNestedFrameset() {
|
|
||||||
$raw = '<html><frameset><frameset>' .
|
|
||||||
'<frame src="a.html">' .
|
|
||||||
'</frameset></frameset></html>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertTrue($page->hasFrames());
|
|
||||||
$this->assertIdentical(
|
|
||||||
$page->getFrameset(),
|
|
||||||
array(1 => new SimpleUrl('http://host/a.html')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFramesCollectedWithNestedFramesetTags() {
|
|
||||||
$raw = '<html><frameset>' .
|
|
||||||
'<frame src="a.html">' .
|
|
||||||
'<frameset><frame src="b.html"></frameset>' .
|
|
||||||
'<frame src="c.html">' .
|
|
||||||
'</frameset></html>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertTrue($page->hasFrames());
|
|
||||||
$this->assertIdentical($page->getFrameset(), array(
|
|
||||||
1 => new SimpleUrl('http://host/a.html'),
|
|
||||||
2 => new SimpleUrl('http://host/b.html'),
|
|
||||||
3 => new SimpleUrl('http://host/c.html')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testNamedFrames() {
|
|
||||||
$raw = '<html><frameset>' .
|
|
||||||
'<frame src="a.html">' .
|
|
||||||
'<frame name="_one" src="b.html">' .
|
|
||||||
'<frame src="c.html">' .
|
|
||||||
'<frame src="d.html" name="_two">' .
|
|
||||||
'</frameset></html>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertTrue($page->hasFrames());
|
|
||||||
$this->assertIdentical($page->getFrameset(), array(
|
|
||||||
1 => new SimpleUrl('http://host/a.html'),
|
|
||||||
'_one' => new SimpleUrl('http://host/b.html'),
|
|
||||||
3 => new SimpleUrl('http://host/c.html'),
|
|
||||||
'_two' => new SimpleUrl('http://host/d.html')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanReadElementOfCompleteForm() {
|
|
||||||
$raw = '<html><head><form>' .
|
|
||||||
'<input type="text" name="here" value="Hello">' .
|
|
||||||
'</form></head></html>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertEqual($page->getField(new SimpleByName('here')), "Hello");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanReadElementOfUnclosedForm() {
|
|
||||||
$raw = '<html><head><form>' .
|
|
||||||
'<input type="text" name="here" value="Hello">' .
|
|
||||||
'</head></html>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertEqual($page->getField(new SimpleByName('here')), "Hello");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanReadElementByLabel() {
|
|
||||||
$raw = '<html><head><form>' .
|
|
||||||
'<label>Where<input type="text" name="here" value="Hello"></label>' .
|
|
||||||
'</head></html>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertEqual($page->getField(new SimpleByLabel('Where')), "Hello");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanFindFormByLabel() {
|
|
||||||
$raw = '<html><head><form><input type="submit"></form></head></html>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertNull($page->getFormBySubmit(new SimpleByLabel('submit')));
|
|
||||||
$this->assertNull($page->getFormBySubmit(new SimpleByName('submit')));
|
|
||||||
$this->assertIsA(
|
|
||||||
$page->getFormBySubmit(new SimpleByLabel('Submit')),
|
|
||||||
'SimpleForm');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testConfirmSubmitAttributesAreCaseSensitive() {
|
|
||||||
$raw = '<html><head><FORM><INPUT TYPE="SUBMIT" NAME="S" VALUE="S"></FORM></head></html>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertIsA(
|
|
||||||
$page->getFormBySubmit(new SimpleByName('S')),
|
|
||||||
'SimpleForm');
|
|
||||||
$this->assertIsA(
|
|
||||||
$page->getFormBySubmit(new SimpleByLabel('S')),
|
|
||||||
'SimpleForm');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanFindFormByImage() {
|
|
||||||
$raw = '<html><head><form>' .
|
|
||||||
'<input type="image" id=100 alt="Label" name="me">' .
|
|
||||||
'</form></head></html>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertIsA(
|
|
||||||
$page->getFormByImage(new SimpleByLabel('Label')),
|
|
||||||
'SimpleForm');
|
|
||||||
$this->assertIsA(
|
|
||||||
$page->getFormByImage(new SimpleByName('me')),
|
|
||||||
'SimpleForm');
|
|
||||||
$this->assertIsA(
|
|
||||||
$page->getFormByImage(new SimpleById(100)),
|
|
||||||
'SimpleForm');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanFindFormByButtonTag() {
|
|
||||||
$raw = '<html><head><form>' .
|
|
||||||
'<button type="submit" name="b" value="B">BBB</button>' .
|
|
||||||
'</form></head></html>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertNull($page->getFormBySubmit(new SimpleByLabel('b')));
|
|
||||||
$this->assertNull($page->getFormBySubmit(new SimpleByLabel('B')));
|
|
||||||
$this->assertIsA(
|
|
||||||
$page->getFormBySubmit(new SimpleByName('b')),
|
|
||||||
'SimpleForm');
|
|
||||||
$this->assertIsA(
|
|
||||||
$page->getFormBySubmit(new SimpleByLabel('BBB')),
|
|
||||||
'SimpleForm');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanFindFormById() {
|
|
||||||
$raw = '<html><head><form id="55"><input type="submit"></form></head></html>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertNull($page->getFormById(54));
|
|
||||||
$this->assertIsA($page->getFormById(55), 'SimpleForm');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFormCanBeSubmitted() {
|
|
||||||
$raw = '<html><head><form method="GET" action="here.php">' .
|
|
||||||
'<input type="submit" name="s" value="Submit">' .
|
|
||||||
'</form></head></html>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$form = $page->getFormBySubmit(new SimpleByLabel('Submit'));
|
|
||||||
$this->assertEqual(
|
|
||||||
$form->submitButton(new SimpleByLabel('Submit')),
|
|
||||||
new SimpleGetEncoding(array('s' => 'Submit')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testUnparsedTagDoesNotCrash() {
|
|
||||||
$raw = '<form><input type="reset" name="Clear"></form>';
|
|
||||||
$this->whenVisiting('http://host', $raw);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testReadingTextField() {
|
|
||||||
$raw = '<html><head><form>' .
|
|
||||||
'<input type="text" name="a">' .
|
|
||||||
'<input type="text" name="b" value="bbb" id=3>' .
|
|
||||||
'</form></head></html>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertNull($page->getField(new SimpleByName('missing')));
|
|
||||||
$this->assertIdentical($page->getField(new SimpleByName('a')), '');
|
|
||||||
$this->assertIdentical($page->getField(new SimpleByName('b')), 'bbb');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testEntitiesAreDecodedInDefaultTextFieldValue() {
|
|
||||||
$raw = '<form><input type="text" name="a" value="&\'"<>"></form>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertEqual($page->getField(new SimpleByName('a')), '&\'"<>');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testReadingTextFieldIsCaseInsensitive() {
|
|
||||||
$raw = '<html><head><FORM>' .
|
|
||||||
'<INPUT TYPE="TEXT" NAME="a">' .
|
|
||||||
'<INPUT TYPE="TEXT" NAME="b" VALUE="bbb" id=3>' .
|
|
||||||
'</FORM></head></html>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertNull($page->getField(new SimpleByName('missing')));
|
|
||||||
$this->assertIdentical($page->getField(new SimpleByName('a')), '');
|
|
||||||
$this->assertIdentical($page->getField(new SimpleByName('b')), 'bbb');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSettingTextField() {
|
|
||||||
$raw = '<html><head><form>' .
|
|
||||||
'<input type="text" name="a">' .
|
|
||||||
'<input type="text" name="b" id=3>' .
|
|
||||||
'<input type="submit">' .
|
|
||||||
'</form></head></html>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertTrue($page->setField(new SimpleByName('a'), 'aaa'));
|
|
||||||
$this->assertEqual($page->getField(new SimpleByName('a')), 'aaa');
|
|
||||||
$this->assertTrue($page->setField(new SimpleById(3), 'bbb'));
|
|
||||||
$this->assertEqual($page->getField(new SimpleBYId(3)), 'bbb');
|
|
||||||
$this->assertFalse($page->setField(new SimpleByName('z'), 'zzz'));
|
|
||||||
$this->assertNull($page->getField(new SimpleByName('z')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSettingTextFieldByEnclosingLabel() {
|
|
||||||
$raw = '<html><head><form>' .
|
|
||||||
'<label>Stuff' .
|
|
||||||
'<input type="text" name="a" value="A">' .
|
|
||||||
'</label>' .
|
|
||||||
'</form></head></html>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertEqual($page->getField(new SimpleByName('a')), 'A');
|
|
||||||
$this->assertEqual($page->getField(new SimpleByLabel('Stuff')), 'A');
|
|
||||||
$this->assertTrue($page->setField(new SimpleByLabel('Stuff'), 'aaa'));
|
|
||||||
$this->assertEqual($page->getField(new SimpleByLabel('Stuff')), 'aaa');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testLabelsWithoutForDoNotAttachToInputsWithNoId() {
|
|
||||||
$raw = '<form action="network_confirm.php?x=X&y=Y" method="post">
|
|
||||||
<label>Text A <input type="text" name="a" value="one"></label>
|
|
||||||
<label>Text B <input type="text" name="b" value="two"></label>
|
|
||||||
</form>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertEqual($page->getField(new SimpleByLabelOrName('Text A')), 'one');
|
|
||||||
$this->assertEqual($page->getField(new SimpleByLabelOrName('Text B')), 'two');
|
|
||||||
$this->assertTrue($page->setField(new SimpleByLabelOrName('Text A'), '1'));
|
|
||||||
$this->assertTrue($page->setField(new SimpleByLabelOrName('Text B'), '2'));
|
|
||||||
$this->assertEqual($page->getField(new SimpleByLabelOrName('Text A')), '1');
|
|
||||||
$this->assertEqual($page->getField(new SimpleByLabelOrName('Text B')), '2');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testGettingTextFieldByEnclosingLabelWithConflictingOtherFields() {
|
|
||||||
$raw = '<html><head><form>' .
|
|
||||||
'<label>Stuff' .
|
|
||||||
'<input type="text" name="a" value="A">' .
|
|
||||||
'</label>' .
|
|
||||||
'<input type="text" name="b" value="B">' .
|
|
||||||
'</form></head></html>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertEqual($page->getField(new SimpleByName('a')), 'A');
|
|
||||||
$this->assertEqual($page->getField(new SimpleByName('b')), 'B');
|
|
||||||
$this->assertEqual($page->getField(new SimpleByLabel('Stuff')), 'A');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSettingTextFieldByExternalLabel() {
|
|
||||||
$raw = '<html><head><form>' .
|
|
||||||
'<label for="aaa">Stuff</label>' .
|
|
||||||
'<input id="aaa" type="text" name="a" value="A">' .
|
|
||||||
'</form></head></html>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertEqual($page->getField(new SimpleByLabel('Stuff')), 'A');
|
|
||||||
$this->assertTrue($page->setField(new SimpleByLabel('Stuff'), 'aaa'));
|
|
||||||
$this->assertEqual($page->getField(new SimpleByLabel('Stuff')), 'aaa');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testReadingTextArea() {
|
|
||||||
$raw = '<html><head><form>' .
|
|
||||||
'<textarea name="a">aaa</textarea>' .
|
|
||||||
'<input type="submit">' .
|
|
||||||
'</form></head></html>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertEqual($page->getField(new SimpleByName('a')), 'aaa');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testEntitiesAreDecodedInTextareaValue() {
|
|
||||||
$raw = '<form><textarea name="a">&\'"<></textarea></form>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertEqual($page->getField(new SimpleByName('a')), '&\'"<>');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testNewlinesPreservedInTextArea() {
|
|
||||||
$raw = "<form><textarea name=\"a\">hello\r\nworld</textarea></form>";
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertEqual($page->getField(new SimpleByName('a')), "hello\r\nworld");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testWhitespacePreservedInTextArea() {
|
|
||||||
$raw = '<form><textarea name="a"> </textarea></form>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertEqual($page->getField(new SimpleByName('a')), ' ');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testComplexWhitespaceInTextArea() {
|
|
||||||
$raw = "<html>\n" .
|
|
||||||
" <head><title></title></head>\n" .
|
|
||||||
" <body>\n" .
|
|
||||||
" <form>\n".
|
|
||||||
" <label>Text area C\n" .
|
|
||||||
" <textarea name='c'>\n" .
|
|
||||||
" </textarea>\n" .
|
|
||||||
" </label>\n" .
|
|
||||||
" </form>\n" .
|
|
||||||
" </body>\n" .
|
|
||||||
"</html>";
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertEqual($page->getField(new SimpleByName('c')), " ");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSettingTextArea() {
|
|
||||||
$raw = '<form>' .
|
|
||||||
'<textarea name="a">aaa</textarea>' .
|
|
||||||
'<input type="submit">' .
|
|
||||||
'</form>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertTrue($page->setField(new SimpleByName('a'), 'AAA'));
|
|
||||||
$this->assertEqual($page->getField(new SimpleByName('a')), 'AAA');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testDontIncludeTextAreaContentInLabel() {
|
|
||||||
$raw = '<form><label>Text area C<textarea id=3 name="c">mouse</textarea></label></form>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertEqual($page->getField(new SimpleByLabel('Text area C')), 'mouse');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSettingSelectionField() {
|
|
||||||
$raw = '<form>' .
|
|
||||||
'<select name="a">' .
|
|
||||||
'<option>aaa</option>' .
|
|
||||||
'<option selected>bbb</option>' .
|
|
||||||
'</select>' .
|
|
||||||
'<input type="submit">' .
|
|
||||||
'</form>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertEqual($page->getField(new SimpleByName('a')), 'bbb');
|
|
||||||
$this->assertFalse($page->setField(new SimpleByName('a'), 'ccc'));
|
|
||||||
$this->assertTrue($page->setField(new SimpleByName('a'), 'aaa'));
|
|
||||||
$this->assertEqual($page->getField(new SimpleByName('a')), 'aaa');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSelectionOptionsAreNormalised() {
|
|
||||||
$raw = '<form>' .
|
|
||||||
'<select name="a">' .
|
|
||||||
'<option selected><b>Big</b> bold</option>' .
|
|
||||||
'<option>small <em>italic</em></option>' .
|
|
||||||
'</select>' .
|
|
||||||
'</form>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertEqual($page->getField(new SimpleByName('a')), 'Big bold');
|
|
||||||
$this->assertTrue($page->setField(new SimpleByName('a'), 'small italic'));
|
|
||||||
$this->assertEqual($page->getField(new SimpleByName('a')), 'small italic');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanParseBlankOptions() {
|
|
||||||
$raw = '<form>
|
|
||||||
<select id=4 name="d">
|
|
||||||
<option value="d1">D1</option>
|
|
||||||
<option value="d2">D2</option>
|
|
||||||
<option></option>
|
|
||||||
</select>
|
|
||||||
</form>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertTrue($page->setField(new SimpleByName('d'), ''));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testTwoSelectionFieldsAreIndependent() {
|
|
||||||
$raw = '<form>
|
|
||||||
<select id=4 name="d">
|
|
||||||
<option value="d1" selected>D1</option>
|
|
||||||
<option value="d2">D2</option>
|
|
||||||
</select>
|
|
||||||
<select id=11 name="h">
|
|
||||||
<option value="h1">H1</option>
|
|
||||||
<option value="h2" selected>H2</option>
|
|
||||||
</select>
|
|
||||||
</form>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertTrue($page->setField(new SimpleByName('d'), 'd2'));
|
|
||||||
$this->assertTrue($page->setField(new SimpleByName('h'), 'h1'));
|
|
||||||
$this->assertEqual($page->getField(new SimpleByName('d')), 'd2');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testEmptyOptionDoesNotScrewUpTwoSelectionFields() {
|
|
||||||
$raw = '<form>
|
|
||||||
<select name="d">
|
|
||||||
<option value="d1" selected>D1</option>
|
|
||||||
<option value="d2">D2</option>
|
|
||||||
<option></option>
|
|
||||||
</select>
|
|
||||||
<select name="h">
|
|
||||||
<option value="h1">H1</option>
|
|
||||||
<option value="h2" selected>H2</option>
|
|
||||||
</select>
|
|
||||||
</form>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertTrue($page->setField(new SimpleByName('d'), 'd2'));
|
|
||||||
$this->assertTrue($page->setField(new SimpleByName('h'), 'h1'));
|
|
||||||
$this->assertEqual($page->getField(new SimpleByName('d')), 'd2');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSettingSelectionFieldByEnclosingLabel() {
|
|
||||||
$raw = '<form>' .
|
|
||||||
'<label>Stuff' .
|
|
||||||
'<select name="a"><option selected>A</option><option>B</option></select>' .
|
|
||||||
'</label>' .
|
|
||||||
'</form>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertEqual($page->getField(new SimpleByLabel('Stuff')), 'A');
|
|
||||||
$this->assertTrue($page->setField(new SimpleByLabel('Stuff'), 'B'));
|
|
||||||
$this->assertEqual($page->getField(new SimpleByLabel('Stuff')), 'B');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testTwoSelectionFieldsWithLabelsAreIndependent() {
|
|
||||||
$raw = '<form>
|
|
||||||
<label>Labelled D
|
|
||||||
<select id=4 name="d">
|
|
||||||
<option value="d1" selected>D1</option>
|
|
||||||
<option value="d2">D2</option>
|
|
||||||
</select>
|
|
||||||
</label>
|
|
||||||
<label>Labelled H
|
|
||||||
<select id=11 name="h">
|
|
||||||
<option value="h1">H1</option>
|
|
||||||
<option value="h2" selected>H2</option>
|
|
||||||
</select>
|
|
||||||
</label>
|
|
||||||
</form>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertTrue($page->setField(new SimpleByLabel('Labelled D'), 'd2'));
|
|
||||||
$this->assertTrue($page->setField(new SimpleByLabel('Labelled H'), 'h1'));
|
|
||||||
$this->assertEqual($page->getField(new SimpleByLabel('Labelled D')), 'd2');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSettingRadioButtonByEnclosingLabel() {
|
|
||||||
$raw = '<form>' .
|
|
||||||
'<label>A<input type="radio" name="r" value="a" checked></label>' .
|
|
||||||
'<label>B<input type="radio" name="r" value="b"></label>' .
|
|
||||||
'</form>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertEqual($page->getField(new SimpleByLabel('A')), 'a');
|
|
||||||
$this->assertTrue($page->setField(new SimpleBylabel('B'), 'b'));
|
|
||||||
$this->assertEqual($page->getField(new SimpleByLabel('B')), 'b');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanParseInputsWithAllKindsOfAttributeQuoting() {
|
|
||||||
$raw = '<form>' .
|
|
||||||
'<input type="checkbox" name=\'first\' value=one checked></input>' .
|
|
||||||
'<input type=checkbox name="second" value="two"></input>' .
|
|
||||||
'<input type=checkbox name="third" value=\'three\' checked="checked" />' .
|
|
||||||
'</form>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertEqual($page->getField(new SimpleByName('first')), 'one');
|
|
||||||
$this->assertEqual($page->getField(new SimpleByName('second')), false);
|
|
||||||
$this->assertEqual($page->getField(new SimpleByName('third')), 'three');
|
|
||||||
}
|
|
||||||
|
|
||||||
function urlToString($url) {
|
|
||||||
return $url->asString();
|
|
||||||
}
|
|
||||||
|
|
||||||
function assertSameFrameset($actual, $expected) {
|
|
||||||
$this->assertIdentical(array_map(array($this, 'urlToString'), $actual),
|
|
||||||
array_map(array($this, 'urlToString'), $expected));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfParsingUsingPhpParser extends TestOfParsing {
|
|
||||||
|
|
||||||
function whenVisiting($url, $content) {
|
|
||||||
$response = new MockSimpleHttpResponse();
|
|
||||||
$response->setReturnValue('getContent', $content);
|
|
||||||
$response->setReturnValue('getUrl', new SimpleUrl($url));
|
|
||||||
$builder = new SimplePhpPageBuilder();
|
|
||||||
return $builder->parse($response);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testNastyTitle() {
|
|
||||||
$page = $this->whenVisiting('http://host',
|
|
||||||
'<html><head><Title> <b>Me&Me </TITLE></b></head></html>');
|
|
||||||
$this->assertEqual($page->getTitle(), "Me&Me");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testLabelShouldStopAtClosingLabelTag() {
|
|
||||||
$raw = '<form><label>start<textarea id=3 name="c" wrap="hard">stuff</textarea>end</label>stuff</form>';
|
|
||||||
$page = $this->whenVisiting('http://host', $raw);
|
|
||||||
$this->assertEqual($page->getField(new SimpleByLabel('startend')), 'stuff');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfParsingUsingTidyParser extends TestOfParsing {
|
|
||||||
|
|
||||||
function skip() {
|
|
||||||
$this->skipUnless(extension_loaded('tidy'), 'Install \'tidy\' php extension to enable html tidy based parser');
|
|
||||||
}
|
|
||||||
|
|
||||||
function whenVisiting($url, $content) {
|
|
||||||
$response = new MockSimpleHttpResponse();
|
|
||||||
$response->setReturnValue('getContent', $content);
|
|
||||||
$response->setReturnValue('getUrl', new SimpleUrl($url));
|
|
||||||
$builder = new SimpleTidyPageBuilder();
|
|
||||||
return $builder->parse($response);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,489 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: php_parser_test.php 1911 2009-07-29 16:38:04Z lastcraft $
|
|
||||||
require_once(dirname(__FILE__) . '/../autorun.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../php_parser.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../tag.php');
|
|
||||||
Mock::generate('SimplePage');
|
|
||||||
Mock::generate('SimplePhpPageBuilder');
|
|
||||||
Mock::generate('SimpleHttpResponse');
|
|
||||||
Mock::generatePartial(
|
|
||||||
'SimplePhpPageBuilder',
|
|
||||||
'PartialSimplePhpPageBuilder',
|
|
||||||
array('createPage', 'createParser'));
|
|
||||||
Mock::generate('SimpleHtmlSaxParser');
|
|
||||||
Mock::generate('SimplePhpPageBuilder');
|
|
||||||
|
|
||||||
class TestOfParallelRegex extends UnitTestCase {
|
|
||||||
|
|
||||||
function testNoPatterns() {
|
|
||||||
$regex = new ParallelRegex(false);
|
|
||||||
$this->assertFalse($regex->match("Hello", $match));
|
|
||||||
$this->assertEqual($match, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testNoSubject() {
|
|
||||||
$regex = new ParallelRegex(false);
|
|
||||||
$regex->addPattern(".*");
|
|
||||||
$this->assertTrue($regex->match("", $match));
|
|
||||||
$this->assertEqual($match, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMatchAll() {
|
|
||||||
$regex = new ParallelRegex(false);
|
|
||||||
$regex->addPattern(".*");
|
|
||||||
$this->assertTrue($regex->match("Hello", $match));
|
|
||||||
$this->assertEqual($match, "Hello");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCaseSensitive() {
|
|
||||||
$regex = new ParallelRegex(true);
|
|
||||||
$regex->addPattern("abc");
|
|
||||||
$this->assertTrue($regex->match("abcdef", $match));
|
|
||||||
$this->assertEqual($match, "abc");
|
|
||||||
$this->assertTrue($regex->match("AAABCabcdef", $match));
|
|
||||||
$this->assertEqual($match, "abc");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCaseInsensitive() {
|
|
||||||
$regex = new ParallelRegex(false);
|
|
||||||
$regex->addPattern("abc");
|
|
||||||
$this->assertTrue($regex->match("abcdef", $match));
|
|
||||||
$this->assertEqual($match, "abc");
|
|
||||||
$this->assertTrue($regex->match("AAABCabcdef", $match));
|
|
||||||
$this->assertEqual($match, "ABC");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMatchMultiple() {
|
|
||||||
$regex = new ParallelRegex(true);
|
|
||||||
$regex->addPattern("abc");
|
|
||||||
$regex->addPattern("ABC");
|
|
||||||
$this->assertTrue($regex->match("abcdef", $match));
|
|
||||||
$this->assertEqual($match, "abc");
|
|
||||||
$this->assertTrue($regex->match("AAABCabcdef", $match));
|
|
||||||
$this->assertEqual($match, "ABC");
|
|
||||||
$this->assertFalse($regex->match("Hello", $match));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testPatternLabels() {
|
|
||||||
$regex = new ParallelRegex(false);
|
|
||||||
$regex->addPattern("abc", "letter");
|
|
||||||
$regex->addPattern("123", "number");
|
|
||||||
$this->assertIdentical($regex->match("abcdef", $match), "letter");
|
|
||||||
$this->assertEqual($match, "abc");
|
|
||||||
$this->assertIdentical($regex->match("0123456789", $match), "number");
|
|
||||||
$this->assertEqual($match, "123");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfStateStack extends UnitTestCase {
|
|
||||||
|
|
||||||
function testStartState() {
|
|
||||||
$stack = new SimpleStateStack("one");
|
|
||||||
$this->assertEqual($stack->getCurrent(), "one");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testExhaustion() {
|
|
||||||
$stack = new SimpleStateStack("one");
|
|
||||||
$this->assertFalse($stack->leave());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testStateMoves() {
|
|
||||||
$stack = new SimpleStateStack("one");
|
|
||||||
$stack->enter("two");
|
|
||||||
$this->assertEqual($stack->getCurrent(), "two");
|
|
||||||
$stack->enter("three");
|
|
||||||
$this->assertEqual($stack->getCurrent(), "three");
|
|
||||||
$this->assertTrue($stack->leave());
|
|
||||||
$this->assertEqual($stack->getCurrent(), "two");
|
|
||||||
$stack->enter("third");
|
|
||||||
$this->assertEqual($stack->getCurrent(), "third");
|
|
||||||
$this->assertTrue($stack->leave());
|
|
||||||
$this->assertTrue($stack->leave());
|
|
||||||
$this->assertEqual($stack->getCurrent(), "one");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestParser {
|
|
||||||
|
|
||||||
function accept() {
|
|
||||||
}
|
|
||||||
|
|
||||||
function a() {
|
|
||||||
}
|
|
||||||
|
|
||||||
function b() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Mock::generate('TestParser');
|
|
||||||
|
|
||||||
class TestOfLexer extends UnitTestCase {
|
|
||||||
|
|
||||||
function testEmptyPage() {
|
|
||||||
$handler = new MockTestParser();
|
|
||||||
$handler->expectNever("accept");
|
|
||||||
$handler->setReturnValue("accept", true);
|
|
||||||
$handler->expectNever("accept");
|
|
||||||
$handler->setReturnValue("accept", true);
|
|
||||||
$lexer = new SimpleLexer($handler);
|
|
||||||
$lexer->addPattern("a+");
|
|
||||||
$this->assertTrue($lexer->parse(""));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSinglePattern() {
|
|
||||||
$handler = new MockTestParser();
|
|
||||||
$handler->expectAt(0, "accept", array("aaa", LEXER_MATCHED));
|
|
||||||
$handler->expectAt(1, "accept", array("x", LEXER_UNMATCHED));
|
|
||||||
$handler->expectAt(2, "accept", array("a", LEXER_MATCHED));
|
|
||||||
$handler->expectAt(3, "accept", array("yyy", LEXER_UNMATCHED));
|
|
||||||
$handler->expectAt(4, "accept", array("a", LEXER_MATCHED));
|
|
||||||
$handler->expectAt(5, "accept", array("x", LEXER_UNMATCHED));
|
|
||||||
$handler->expectAt(6, "accept", array("aaa", LEXER_MATCHED));
|
|
||||||
$handler->expectAt(7, "accept", array("z", LEXER_UNMATCHED));
|
|
||||||
$handler->expectCallCount("accept", 8);
|
|
||||||
$handler->setReturnValue("accept", true);
|
|
||||||
$lexer = new SimpleLexer($handler);
|
|
||||||
$lexer->addPattern("a+");
|
|
||||||
$this->assertTrue($lexer->parse("aaaxayyyaxaaaz"));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMultiplePattern() {
|
|
||||||
$handler = new MockTestParser();
|
|
||||||
$target = array("a", "b", "a", "bb", "x", "b", "a", "xxxxxx", "a", "x");
|
|
||||||
for ($i = 0; $i < count($target); $i++) {
|
|
||||||
$handler->expectAt($i, "accept", array($target[$i], '*'));
|
|
||||||
}
|
|
||||||
$handler->expectCallCount("accept", count($target));
|
|
||||||
$handler->setReturnValue("accept", true);
|
|
||||||
$lexer = new SimpleLexer($handler);
|
|
||||||
$lexer->addPattern("a+");
|
|
||||||
$lexer->addPattern("b+");
|
|
||||||
$this->assertTrue($lexer->parse("ababbxbaxxxxxxax"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfLexerModes extends UnitTestCase {
|
|
||||||
|
|
||||||
function testIsolatedPattern() {
|
|
||||||
$handler = new MockTestParser();
|
|
||||||
$handler->expectAt(0, "a", array("a", LEXER_MATCHED));
|
|
||||||
$handler->expectAt(1, "a", array("b", LEXER_UNMATCHED));
|
|
||||||
$handler->expectAt(2, "a", array("aa", LEXER_MATCHED));
|
|
||||||
$handler->expectAt(3, "a", array("bxb", LEXER_UNMATCHED));
|
|
||||||
$handler->expectAt(4, "a", array("aaa", LEXER_MATCHED));
|
|
||||||
$handler->expectAt(5, "a", array("x", LEXER_UNMATCHED));
|
|
||||||
$handler->expectAt(6, "a", array("aaaa", LEXER_MATCHED));
|
|
||||||
$handler->expectAt(7, "a", array("x", LEXER_UNMATCHED));
|
|
||||||
$handler->expectCallCount("a", 8);
|
|
||||||
$handler->setReturnValue("a", true);
|
|
||||||
$lexer = new SimpleLexer($handler, "a");
|
|
||||||
$lexer->addPattern("a+", "a");
|
|
||||||
$lexer->addPattern("b+", "b");
|
|
||||||
$this->assertTrue($lexer->parse("abaabxbaaaxaaaax"));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testModeChange() {
|
|
||||||
$handler = new MockTestParser();
|
|
||||||
$handler->expectAt(0, "a", array("a", LEXER_MATCHED));
|
|
||||||
$handler->expectAt(1, "a", array("b", LEXER_UNMATCHED));
|
|
||||||
$handler->expectAt(2, "a", array("aa", LEXER_MATCHED));
|
|
||||||
$handler->expectAt(3, "a", array("b", LEXER_UNMATCHED));
|
|
||||||
$handler->expectAt(4, "a", array("aaa", LEXER_MATCHED));
|
|
||||||
$handler->expectAt(0, "b", array(":", LEXER_ENTER));
|
|
||||||
$handler->expectAt(1, "b", array("a", LEXER_UNMATCHED));
|
|
||||||
$handler->expectAt(2, "b", array("b", LEXER_MATCHED));
|
|
||||||
$handler->expectAt(3, "b", array("a", LEXER_UNMATCHED));
|
|
||||||
$handler->expectAt(4, "b", array("bb", LEXER_MATCHED));
|
|
||||||
$handler->expectAt(5, "b", array("a", LEXER_UNMATCHED));
|
|
||||||
$handler->expectAt(6, "b", array("bbb", LEXER_MATCHED));
|
|
||||||
$handler->expectAt(7, "b", array("a", LEXER_UNMATCHED));
|
|
||||||
$handler->expectCallCount("a", 5);
|
|
||||||
$handler->expectCallCount("b", 8);
|
|
||||||
$handler->setReturnValue("a", true);
|
|
||||||
$handler->setReturnValue("b", true);
|
|
||||||
$lexer = new SimpleLexer($handler, "a");
|
|
||||||
$lexer->addPattern("a+", "a");
|
|
||||||
$lexer->addEntryPattern(":", "a", "b");
|
|
||||||
$lexer->addPattern("b+", "b");
|
|
||||||
$this->assertTrue($lexer->parse("abaabaaa:ababbabbba"));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testNesting() {
|
|
||||||
$handler = new MockTestParser();
|
|
||||||
$handler->setReturnValue("a", true);
|
|
||||||
$handler->setReturnValue("b", true);
|
|
||||||
$handler->expectAt(0, "a", array("aa", LEXER_MATCHED));
|
|
||||||
$handler->expectAt(1, "a", array("b", LEXER_UNMATCHED));
|
|
||||||
$handler->expectAt(2, "a", array("aa", LEXER_MATCHED));
|
|
||||||
$handler->expectAt(3, "a", array("b", LEXER_UNMATCHED));
|
|
||||||
$handler->expectAt(0, "b", array("(", LEXER_ENTER));
|
|
||||||
$handler->expectAt(1, "b", array("bb", LEXER_MATCHED));
|
|
||||||
$handler->expectAt(2, "b", array("a", LEXER_UNMATCHED));
|
|
||||||
$handler->expectAt(3, "b", array("bb", LEXER_MATCHED));
|
|
||||||
$handler->expectAt(4, "b", array(")", LEXER_EXIT));
|
|
||||||
$handler->expectAt(4, "a", array("aa", LEXER_MATCHED));
|
|
||||||
$handler->expectAt(5, "a", array("b", LEXER_UNMATCHED));
|
|
||||||
$handler->expectCallCount("a", 6);
|
|
||||||
$handler->expectCallCount("b", 5);
|
|
||||||
$lexer = new SimpleLexer($handler, "a");
|
|
||||||
$lexer->addPattern("a+", "a");
|
|
||||||
$lexer->addEntryPattern("(", "a", "b");
|
|
||||||
$lexer->addPattern("b+", "b");
|
|
||||||
$lexer->addExitPattern(")", "b");
|
|
||||||
$this->assertTrue($lexer->parse("aabaab(bbabb)aab"));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSingular() {
|
|
||||||
$handler = new MockTestParser();
|
|
||||||
$handler->setReturnValue("a", true);
|
|
||||||
$handler->setReturnValue("b", true);
|
|
||||||
$handler->expectAt(0, "a", array("aa", LEXER_MATCHED));
|
|
||||||
$handler->expectAt(1, "a", array("aa", LEXER_MATCHED));
|
|
||||||
$handler->expectAt(2, "a", array("xx", LEXER_UNMATCHED));
|
|
||||||
$handler->expectAt(3, "a", array("xx", LEXER_UNMATCHED));
|
|
||||||
$handler->expectAt(0, "b", array("b", LEXER_SPECIAL));
|
|
||||||
$handler->expectAt(1, "b", array("bbb", LEXER_SPECIAL));
|
|
||||||
$handler->expectCallCount("a", 4);
|
|
||||||
$handler->expectCallCount("b", 2);
|
|
||||||
$lexer = new SimpleLexer($handler, "a");
|
|
||||||
$lexer->addPattern("a+", "a");
|
|
||||||
$lexer->addSpecialPattern("b+", "a", "b");
|
|
||||||
$this->assertTrue($lexer->parse("aabaaxxbbbxx"));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testUnwindTooFar() {
|
|
||||||
$handler = new MockTestParser();
|
|
||||||
$handler->setReturnValue("a", true);
|
|
||||||
$handler->expectAt(0, "a", array("aa", LEXER_MATCHED));
|
|
||||||
$handler->expectAt(1, "a", array(")", LEXER_EXIT));
|
|
||||||
$handler->expectCallCount("a", 2);
|
|
||||||
$lexer = new SimpleLexer($handler, "a");
|
|
||||||
$lexer->addPattern("a+", "a");
|
|
||||||
$lexer->addExitPattern(")", "a");
|
|
||||||
$this->assertFalse($lexer->parse("aa)aa"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfLexerHandlers extends UnitTestCase {
|
|
||||||
|
|
||||||
function testModeMapping() {
|
|
||||||
$handler = new MockTestParser();
|
|
||||||
$handler->setReturnValue("a", true);
|
|
||||||
$handler->expectAt(0, "a", array("aa", LEXER_MATCHED));
|
|
||||||
$handler->expectAt(1, "a", array("(", LEXER_ENTER));
|
|
||||||
$handler->expectAt(2, "a", array("bb", LEXER_MATCHED));
|
|
||||||
$handler->expectAt(3, "a", array("a", LEXER_UNMATCHED));
|
|
||||||
$handler->expectAt(4, "a", array("bb", LEXER_MATCHED));
|
|
||||||
$handler->expectAt(5, "a", array(")", LEXER_EXIT));
|
|
||||||
$handler->expectAt(6, "a", array("b", LEXER_UNMATCHED));
|
|
||||||
$handler->expectCallCount("a", 7);
|
|
||||||
$lexer = new SimpleLexer($handler, "mode_a");
|
|
||||||
$lexer->addPattern("a+", "mode_a");
|
|
||||||
$lexer->addEntryPattern("(", "mode_a", "mode_b");
|
|
||||||
$lexer->addPattern("b+", "mode_b");
|
|
||||||
$lexer->addExitPattern(")", "mode_b");
|
|
||||||
$lexer->mapHandler("mode_a", "a");
|
|
||||||
$lexer->mapHandler("mode_b", "a");
|
|
||||||
$this->assertTrue($lexer->parse("aa(bbabb)b"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfSimpleHtmlLexer extends UnitTestCase {
|
|
||||||
|
|
||||||
function &createParser() {
|
|
||||||
$parser = new MockSimpleHtmlSaxParser();
|
|
||||||
$parser->setReturnValue('acceptStartToken', true);
|
|
||||||
$parser->setReturnValue('acceptEndToken', true);
|
|
||||||
$parser->setReturnValue('acceptAttributeToken', true);
|
|
||||||
$parser->setReturnValue('acceptEntityToken', true);
|
|
||||||
$parser->setReturnValue('acceptTextToken', true);
|
|
||||||
$parser->setReturnValue('ignore', true);
|
|
||||||
return $parser;
|
|
||||||
}
|
|
||||||
|
|
||||||
function testNoContent() {
|
|
||||||
$parser = $this->createParser();
|
|
||||||
$parser->expectNever('acceptStartToken');
|
|
||||||
$parser->expectNever('acceptEndToken');
|
|
||||||
$parser->expectNever('acceptAttributeToken');
|
|
||||||
$parser->expectNever('acceptEntityToken');
|
|
||||||
$parser->expectNever('acceptTextToken');
|
|
||||||
$lexer = new SimpleHtmlLexer($parser);
|
|
||||||
$this->assertTrue($lexer->parse(''));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testUninteresting() {
|
|
||||||
$parser = $this->createParser();
|
|
||||||
$parser->expectOnce('acceptTextToken', array('<html></html>', '*'));
|
|
||||||
$lexer = new SimpleHtmlLexer($parser);
|
|
||||||
$this->assertTrue($lexer->parse('<html></html>'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSkipCss() {
|
|
||||||
$parser = $this->createParser();
|
|
||||||
$parser->expectNever('acceptTextToken');
|
|
||||||
$parser->expectAtLeastOnce('ignore');
|
|
||||||
$lexer = new SimpleHtmlLexer($parser);
|
|
||||||
$this->assertTrue($lexer->parse("<style>Lot's of styles</style>"));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSkipJavaScript() {
|
|
||||||
$parser = $this->createParser();
|
|
||||||
$parser->expectNever('acceptTextToken');
|
|
||||||
$parser->expectAtLeastOnce('ignore');
|
|
||||||
$lexer = new SimpleHtmlLexer($parser);
|
|
||||||
$this->assertTrue($lexer->parse("<SCRIPT>Javascript code {';:^%^%£$'@\"*(}</SCRIPT>"));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSkipHtmlComments() {
|
|
||||||
$parser = $this->createParser();
|
|
||||||
$parser->expectNever('acceptTextToken');
|
|
||||||
$parser->expectAtLeastOnce('ignore');
|
|
||||||
$lexer = new SimpleHtmlLexer($parser);
|
|
||||||
$this->assertTrue($lexer->parse("<!-- <title>title</title><style>styles</style> -->"));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testTagWithNoAttributes() {
|
|
||||||
$parser = $this->createParser();
|
|
||||||
$parser->expectAt(0, 'acceptStartToken', array('<title', '*'));
|
|
||||||
$parser->expectAt(1, 'acceptStartToken', array('>', '*'));
|
|
||||||
$parser->expectCallCount('acceptStartToken', 2);
|
|
||||||
$parser->expectOnce('acceptTextToken', array('Hello', '*'));
|
|
||||||
$parser->expectOnce('acceptEndToken', array('</title>', '*'));
|
|
||||||
$lexer = new SimpleHtmlLexer($parser);
|
|
||||||
$this->assertTrue($lexer->parse('<title>Hello</title>'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testTagWithAttributes() {
|
|
||||||
$parser = $this->createParser();
|
|
||||||
$parser->expectOnce('acceptTextToken', array('label', '*'));
|
|
||||||
$parser->expectAt(0, 'acceptStartToken', array('<a', '*'));
|
|
||||||
$parser->expectAt(1, 'acceptStartToken', array('href', '*'));
|
|
||||||
$parser->expectAt(2, 'acceptStartToken', array('>', '*'));
|
|
||||||
$parser->expectCallCount('acceptStartToken', 3);
|
|
||||||
$parser->expectAt(0, 'acceptAttributeToken', array('= "', '*'));
|
|
||||||
$parser->expectAt(1, 'acceptAttributeToken', array('here.html', '*'));
|
|
||||||
$parser->expectAt(2, 'acceptAttributeToken', array('"', '*'));
|
|
||||||
$parser->expectCallCount('acceptAttributeToken', 3);
|
|
||||||
$parser->expectOnce('acceptEndToken', array('</a>', '*'));
|
|
||||||
$lexer = new SimpleHtmlLexer($parser);
|
|
||||||
$this->assertTrue($lexer->parse('<a href = "here.html">label</a>'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfHtmlSaxParser extends UnitTestCase {
|
|
||||||
|
|
||||||
function createListener() {
|
|
||||||
$listener = new MockSimplePhpPageBuilder();
|
|
||||||
$listener->setReturnValue('startElement', true);
|
|
||||||
$listener->setReturnValue('addContent', true);
|
|
||||||
$listener->setReturnValue('endElement', true);
|
|
||||||
return $listener;
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFramesetTag() {
|
|
||||||
$listener = $this->createListener();
|
|
||||||
$listener->expectOnce('startElement', array('frameset', array()));
|
|
||||||
$listener->expectOnce('addContent', array('Frames'));
|
|
||||||
$listener->expectOnce('endElement', array('frameset'));
|
|
||||||
$parser = new SimpleHtmlSaxParser($listener);
|
|
||||||
$this->assertTrue($parser->parse('<frameset>Frames</frameset>'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testTagWithUnquotedAttributes() {
|
|
||||||
$listener = $this->createListener();
|
|
||||||
$listener->expectOnce(
|
|
||||||
'startElement',
|
|
||||||
array('input', array('name' => 'a.b.c', 'value' => 'd')));
|
|
||||||
$parser = new SimpleHtmlSaxParser($listener);
|
|
||||||
$this->assertTrue($parser->parse('<input name=a.b.c value = d>'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testTagInsideContent() {
|
|
||||||
$listener = $this->createListener();
|
|
||||||
$listener->expectOnce('startElement', array('a', array()));
|
|
||||||
$listener->expectAt(0, 'addContent', array('<html>'));
|
|
||||||
$listener->expectAt(1, 'addContent', array('</html>'));
|
|
||||||
$parser = new SimpleHtmlSaxParser($listener);
|
|
||||||
$this->assertTrue($parser->parse('<html><a></a></html>'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testTagWithInternalContent() {
|
|
||||||
$listener = $this->createListener();
|
|
||||||
$listener->expectOnce('startElement', array('a', array()));
|
|
||||||
$listener->expectOnce('addContent', array('label'));
|
|
||||||
$listener->expectOnce('endElement', array('a'));
|
|
||||||
$parser = new SimpleHtmlSaxParser($listener);
|
|
||||||
$this->assertTrue($parser->parse('<a>label</a>'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testLinkAddress() {
|
|
||||||
$listener = $this->createListener();
|
|
||||||
$listener->expectOnce('startElement', array('a', array('href' => 'here.html')));
|
|
||||||
$listener->expectOnce('addContent', array('label'));
|
|
||||||
$listener->expectOnce('endElement', array('a'));
|
|
||||||
$parser = new SimpleHtmlSaxParser($listener);
|
|
||||||
$this->assertTrue($parser->parse("<a href = 'here.html'>label</a>"));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testEncodedAttribute() {
|
|
||||||
$listener = $this->createListener();
|
|
||||||
$listener->expectOnce('startElement', array('a', array('href' => 'here&there.html')));
|
|
||||||
$listener->expectOnce('addContent', array('label'));
|
|
||||||
$listener->expectOnce('endElement', array('a'));
|
|
||||||
$parser = new SimpleHtmlSaxParser($listener);
|
|
||||||
$this->assertTrue($parser->parse("<a href = 'here&there.html'>label</a>"));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testTagWithId() {
|
|
||||||
$listener = $this->createListener();
|
|
||||||
$listener->expectOnce('startElement', array('a', array('id' => '0')));
|
|
||||||
$listener->expectOnce('addContent', array('label'));
|
|
||||||
$listener->expectOnce('endElement', array('a'));
|
|
||||||
$parser = new SimpleHtmlSaxParser($listener);
|
|
||||||
$this->assertTrue($parser->parse('<a id="0">label</a>'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testTagWithEmptyAttributes() {
|
|
||||||
$listener = $this->createListener();
|
|
||||||
$listener->expectOnce(
|
|
||||||
'startElement',
|
|
||||||
array('option', array('value' => '', 'selected' => '')));
|
|
||||||
$listener->expectOnce('addContent', array('label'));
|
|
||||||
$listener->expectOnce('endElement', array('option'));
|
|
||||||
$parser = new SimpleHtmlSaxParser($listener);
|
|
||||||
$this->assertTrue($parser->parse('<option value="" selected>label</option>'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testComplexTagWithLotsOfCaseVariations() {
|
|
||||||
$listener = $this->createListener();
|
|
||||||
$listener->expectOnce(
|
|
||||||
'startElement',
|
|
||||||
array('a', array('href' => 'here.html', 'style' => "'cool'")));
|
|
||||||
$listener->expectOnce('addContent', array('label'));
|
|
||||||
$listener->expectOnce('endElement', array('a'));
|
|
||||||
$parser = new SimpleHtmlSaxParser($listener);
|
|
||||||
$this->assertTrue($parser->parse('<A HREF = \'here.html\' Style="\'cool\'">label</A>'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testXhtmlSelfClosingTag() {
|
|
||||||
$listener = $this->createListener();
|
|
||||||
$listener->expectOnce(
|
|
||||||
'startElement',
|
|
||||||
array('input', array('type' => 'submit', 'name' => 'N', 'value' => 'V')));
|
|
||||||
$parser = new SimpleHtmlSaxParser($listener);
|
|
||||||
$this->assertTrue($parser->parse('<input type="submit" name="N" value="V" />'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testNestedFrameInFrameset() {
|
|
||||||
$listener = $this->createListener();
|
|
||||||
$listener->expectAt(0, 'startElement', array('frameset', array()));
|
|
||||||
$listener->expectAt(1, 'startElement', array('frame', array('src' => 'frame.html')));
|
|
||||||
$listener->expectCallCount('startElement', 2);
|
|
||||||
$listener->expectOnce('addContent', array('<noframes>Hello</noframes>'));
|
|
||||||
$listener->expectOnce('endElement', array('frameset'));
|
|
||||||
$parser = new SimpleHtmlSaxParser($listener);
|
|
||||||
$this->assertTrue($parser->parse(
|
|
||||||
'<frameset><frame src="frame.html"><noframes>Hello</noframes></frameset>'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,23 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: test.php 1500 2007-04-29 14:33:31Z pp11 $
|
|
||||||
require_once(dirname(__FILE__) . '/../autorun.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../recorder.php');
|
|
||||||
|
|
||||||
class TestOfRecorder extends UnitTestCase {
|
|
||||||
|
|
||||||
function testContentOfRecorderWithOnePassAndOneFailure() {
|
|
||||||
$test = new TestSuite();
|
|
||||||
$test->addFile(dirname(__FILE__) . '/support/recorder_sample.php');
|
|
||||||
$recorder = new Recorder(new SimpleReporter());
|
|
||||||
$test->run($recorder);
|
|
||||||
$this->assertEqual(count($recorder->results), 2);
|
|
||||||
$this->assertIsA($recorder->results[0], 'SimpleResultOfPass');
|
|
||||||
$this->assertEqual('testTrueIsTrue', array_pop($recorder->results[0]->breadcrumb));
|
|
||||||
$this->assertPattern('/ at \[.*\Wrecorder_sample\.php line 7\]/', $recorder->results[0]->message);
|
|
||||||
$this->assertIsA($recorder->results[1], 'SimpleResultOfFail');
|
|
||||||
$this->assertEqual('testFalseIsTrue', array_pop($recorder->results[1]->breadcrumb));
|
|
||||||
$this->assertPattern("/Expected false, got \[Boolean: true\] at \[.*\Wrecorder_sample\.php line 11\]/",
|
|
||||||
$recorder->results[1]->message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,263 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: reflection_php5_test.php 1778 2008-04-21 16:13:08Z edwardzyang $
|
|
||||||
require_once(dirname(__FILE__) . '/../autorun.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../reflection_php5.php');
|
|
||||||
|
|
||||||
class AnyOldLeafClass {
|
|
||||||
function aMethod() { }
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class AnyOldClass {
|
|
||||||
function aMethod() { }
|
|
||||||
}
|
|
||||||
|
|
||||||
class AnyOldLeafClassWithAFinal {
|
|
||||||
final function aMethod() { }
|
|
||||||
}
|
|
||||||
|
|
||||||
interface AnyOldInterface {
|
|
||||||
function aMethod();
|
|
||||||
}
|
|
||||||
|
|
||||||
interface AnyOldArgumentInterface {
|
|
||||||
function aMethod(AnyOldInterface $argument);
|
|
||||||
}
|
|
||||||
|
|
||||||
interface AnyDescendentInterface extends AnyOldInterface {
|
|
||||||
}
|
|
||||||
|
|
||||||
class AnyOldImplementation implements AnyOldInterface {
|
|
||||||
function aMethod() { }
|
|
||||||
function extraMethod() { }
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class AnyAbstractImplementation implements AnyOldInterface {
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class AnotherOldAbstractClass {
|
|
||||||
protected abstract function aMethod(AnyOldInterface $argument);
|
|
||||||
}
|
|
||||||
|
|
||||||
class AnyOldSubclass extends AnyOldImplementation { }
|
|
||||||
|
|
||||||
class AnyOldArgumentClass {
|
|
||||||
function aMethod($argument) { }
|
|
||||||
}
|
|
||||||
|
|
||||||
class AnyOldArgumentImplementation implements AnyOldArgumentInterface {
|
|
||||||
function aMethod(AnyOldInterface $argument) { }
|
|
||||||
}
|
|
||||||
|
|
||||||
class AnyOldTypeHintedClass implements AnyOldArgumentInterface {
|
|
||||||
function aMethod(AnyOldInterface $argument) { }
|
|
||||||
}
|
|
||||||
|
|
||||||
class AnyDescendentImplementation implements AnyDescendentInterface {
|
|
||||||
function aMethod() { }
|
|
||||||
}
|
|
||||||
|
|
||||||
class AnyOldOverloadedClass {
|
|
||||||
function __isset($key) { }
|
|
||||||
function __unset($key) { }
|
|
||||||
}
|
|
||||||
|
|
||||||
class AnyOldClassWithStaticMethods {
|
|
||||||
static function aStatic() { }
|
|
||||||
static function aStaticWithParameters($arg1, $arg2) { }
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class AnyOldAbstractClassWithAbstractMethods {
|
|
||||||
abstract function anAbstract();
|
|
||||||
abstract function anAbstractWithParameter($foo);
|
|
||||||
abstract function anAbstractWithMultipleParameters($foo, $bar);
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfReflection extends UnitTestCase {
|
|
||||||
|
|
||||||
function testClassExistence() {
|
|
||||||
$reflection = new SimpleReflection('AnyOldLeafClass');
|
|
||||||
$this->assertTrue($reflection->classOrInterfaceExists());
|
|
||||||
$this->assertTrue($reflection->classOrInterfaceExistsSansAutoload());
|
|
||||||
$this->assertFalse($reflection->isAbstract());
|
|
||||||
$this->assertFalse($reflection->isInterface());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testClassNonExistence() {
|
|
||||||
$reflection = new SimpleReflection('UnknownThing');
|
|
||||||
$this->assertFalse($reflection->classOrInterfaceExists());
|
|
||||||
$this->assertFalse($reflection->classOrInterfaceExistsSansAutoload());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testDetectionOfAbstractClass() {
|
|
||||||
$reflection = new SimpleReflection('AnyOldClass');
|
|
||||||
$this->assertTrue($reflection->isAbstract());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testDetectionOfFinalMethods() {
|
|
||||||
$reflection = new SimpleReflection('AnyOldClass');
|
|
||||||
$this->assertFalse($reflection->hasFinal());
|
|
||||||
$reflection = new SimpleReflection('AnyOldLeafClassWithAFinal');
|
|
||||||
$this->assertTrue($reflection->hasFinal());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFindingParentClass() {
|
|
||||||
$reflection = new SimpleReflection('AnyOldSubclass');
|
|
||||||
$this->assertEqual($reflection->getParent(), 'AnyOldImplementation');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testInterfaceExistence() {
|
|
||||||
$reflection = new SimpleReflection('AnyOldInterface');
|
|
||||||
$this->assertTrue($reflection->classOrInterfaceExists());
|
|
||||||
$this->assertTrue($reflection->classOrInterfaceExistsSansAutoload());
|
|
||||||
$this->assertTrue($reflection->isInterface());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMethodsListFromClass() {
|
|
||||||
$reflection = new SimpleReflection('AnyOldClass');
|
|
||||||
$this->assertIdentical($reflection->getMethods(), array('aMethod'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMethodsListFromInterface() {
|
|
||||||
$reflection = new SimpleReflection('AnyOldInterface');
|
|
||||||
$this->assertIdentical($reflection->getMethods(), array('aMethod'));
|
|
||||||
$this->assertIdentical($reflection->getInterfaceMethods(), array('aMethod'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMethodsComeFromDescendentInterfacesASWell() {
|
|
||||||
$reflection = new SimpleReflection('AnyDescendentInterface');
|
|
||||||
$this->assertIdentical($reflection->getMethods(), array('aMethod'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanSeparateInterfaceMethodsFromOthers() {
|
|
||||||
$reflection = new SimpleReflection('AnyOldImplementation');
|
|
||||||
$this->assertIdentical($reflection->getMethods(), array('aMethod', 'extraMethod'));
|
|
||||||
$this->assertIdentical($reflection->getInterfaceMethods(), array('aMethod'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMethodsComeFromDescendentInterfacesInAbstractClass() {
|
|
||||||
$reflection = new SimpleReflection('AnyAbstractImplementation');
|
|
||||||
$this->assertIdentical($reflection->getMethods(), array('aMethod'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testInterfaceHasOnlyItselfToImplement() {
|
|
||||||
$reflection = new SimpleReflection('AnyOldInterface');
|
|
||||||
$this->assertEqual(
|
|
||||||
$reflection->getInterfaces(),
|
|
||||||
array('AnyOldInterface'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testInterfacesListedForClass() {
|
|
||||||
$reflection = new SimpleReflection('AnyOldImplementation');
|
|
||||||
$this->assertEqual(
|
|
||||||
$reflection->getInterfaces(),
|
|
||||||
array('AnyOldInterface'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testInterfacesListedForSubclass() {
|
|
||||||
$reflection = new SimpleReflection('AnyOldSubclass');
|
|
||||||
$this->assertEqual(
|
|
||||||
$reflection->getInterfaces(),
|
|
||||||
array('AnyOldInterface'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testNoParameterCreationWhenNoInterface() {
|
|
||||||
$reflection = new SimpleReflection('AnyOldArgumentClass');
|
|
||||||
$function = $reflection->getSignature('aMethod');
|
|
||||||
if (version_compare(phpversion(), '5.0.2', '<=')) {
|
|
||||||
$this->assertEqual('function amethod($argument)', strtolower($function));
|
|
||||||
} else {
|
|
||||||
$this->assertEqual('function aMethod($argument)', $function);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function testParameterCreationWithoutTypeHinting() {
|
|
||||||
$reflection = new SimpleReflection('AnyOldArgumentImplementation');
|
|
||||||
$function = $reflection->getSignature('aMethod');
|
|
||||||
if (version_compare(phpversion(), '5.0.2', '<=')) {
|
|
||||||
$this->assertEqual('function amethod(AnyOldInterface $argument)', $function);
|
|
||||||
} else {
|
|
||||||
$this->assertEqual('function aMethod(AnyOldInterface $argument)', $function);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function testParameterCreationForTypeHinting() {
|
|
||||||
$reflection = new SimpleReflection('AnyOldTypeHintedClass');
|
|
||||||
$function = $reflection->getSignature('aMethod');
|
|
||||||
if (version_compare(phpversion(), '5.0.2', '<=')) {
|
|
||||||
$this->assertEqual('function amethod(AnyOldInterface $argument)', $function);
|
|
||||||
} else {
|
|
||||||
$this->assertEqual('function aMethod(AnyOldInterface $argument)', $function);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function testIssetFunctionSignature() {
|
|
||||||
$reflection = new SimpleReflection('AnyOldOverloadedClass');
|
|
||||||
$function = $reflection->getSignature('__isset');
|
|
||||||
$this->assertEqual('function __isset($key)', $function);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testUnsetFunctionSignature() {
|
|
||||||
$reflection = new SimpleReflection('AnyOldOverloadedClass');
|
|
||||||
$function = $reflection->getSignature('__unset');
|
|
||||||
$this->assertEqual('function __unset($key)', $function);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testProperlyReflectsTheFinalInterfaceWhenObjectImplementsAnExtendedInterface() {
|
|
||||||
$reflection = new SimpleReflection('AnyDescendentImplementation');
|
|
||||||
$interfaces = $reflection->getInterfaces();
|
|
||||||
$this->assertEqual(1, count($interfaces));
|
|
||||||
$this->assertEqual('AnyDescendentInterface', array_shift($interfaces));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCreatingSignatureForAbstractMethod() {
|
|
||||||
$reflection = new SimpleReflection('AnotherOldAbstractClass');
|
|
||||||
$this->assertEqual($reflection->getSignature('aMethod'), 'function aMethod(AnyOldInterface $argument)');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCanProperlyGenerateStaticMethodSignatures() {
|
|
||||||
$reflection = new SimpleReflection('AnyOldClassWithStaticMethods');
|
|
||||||
$this->assertEqual('static function aStatic()', $reflection->getSignature('aStatic'));
|
|
||||||
$this->assertEqual(
|
|
||||||
'static function aStaticWithParameters($arg1, $arg2)',
|
|
||||||
$reflection->getSignature('aStaticWithParameters')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfReflectionWithTypeHints extends UnitTestCase {
|
|
||||||
function skip() {
|
|
||||||
$this->skipIf(version_compare(phpversion(), '5.1.0', '<'), 'Reflection with type hints only tested for PHP 5.1.0 and above');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testParameterCreationForTypeHintingWithArray() {
|
|
||||||
eval('interface AnyOldArrayTypeHintedInterface {
|
|
||||||
function amethod(array $argument);
|
|
||||||
}
|
|
||||||
class AnyOldArrayTypeHintedClass implements AnyOldArrayTypeHintedInterface {
|
|
||||||
function amethod(array $argument) {}
|
|
||||||
}');
|
|
||||||
$reflection = new SimpleReflection('AnyOldArrayTypeHintedClass');
|
|
||||||
$function = $reflection->getSignature('amethod');
|
|
||||||
$this->assertEqual('function amethod(array $argument)', $function);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfAbstractsWithAbstractMethods extends UnitTestCase {
|
|
||||||
function testCanProperlyGenerateAbstractMethods() {
|
|
||||||
$reflection = new SimpleReflection('AnyOldAbstractClassWithAbstractMethods');
|
|
||||||
$this->assertEqual(
|
|
||||||
'function anAbstract()',
|
|
||||||
$reflection->getSignature('anAbstract')
|
|
||||||
);
|
|
||||||
$this->assertEqual(
|
|
||||||
'function anAbstractWithParameter($foo)',
|
|
||||||
$reflection->getSignature('anAbstractWithParameter')
|
|
||||||
);
|
|
||||||
$this->assertEqual(
|
|
||||||
'function anAbstractWithMultipleParameters($foo, $bar)',
|
|
||||||
$reflection->getSignature('anAbstractWithMultipleParameters')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
|
@ -1,19 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: remote_test.php 1759 2008-04-15 02:37:07Z edwardzyang $
|
|
||||||
require_once('../remote.php');
|
|
||||||
require_once('../reporter.php');
|
|
||||||
|
|
||||||
// The following URL will depend on your own installation.
|
|
||||||
if (isset($_SERVER['SCRIPT_URI'])) {
|
|
||||||
$base_uri = $_SERVER['SCRIPT_URI'];
|
|
||||||
} elseif (isset($_SERVER['HTTP_HOST']) && isset($_SERVER['PHP_SELF'])) {
|
|
||||||
$base_uri = 'http://'. $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
|
|
||||||
};
|
|
||||||
$test_url = str_replace('remote_test.php', 'visual_test.php', $base_uri);
|
|
||||||
|
|
||||||
$test = new TestSuite('Remote tests');
|
|
||||||
$test->add(new RemoteTestCase($test_url . '?xml=yes', $test_url . '?xml=yes&dry=yes'));
|
|
||||||
if (SimpleReporter::inCli()) {
|
|
||||||
exit ($test->run(new TextReporter()) ? 0 : 1);
|
|
||||||
}
|
|
||||||
$test->run(new HtmlReporter());
|
|
|
@ -1,38 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: shell_test.php 1748 2008-04-14 01:50:41Z lastcraft $
|
|
||||||
require_once(dirname(__FILE__) . '/../autorun.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../shell_tester.php');
|
|
||||||
|
|
||||||
class TestOfShell extends UnitTestCase {
|
|
||||||
|
|
||||||
function testEcho() {
|
|
||||||
$shell = new SimpleShell();
|
|
||||||
$this->assertIdentical($shell->execute('echo Hello'), 0);
|
|
||||||
$this->assertPattern('/Hello/', $shell->getOutput());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testBadCommand() {
|
|
||||||
$shell = new SimpleShell();
|
|
||||||
$this->assertNotEqual($ret = $shell->execute('blurgh! 2>&1'), 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfShellTesterAndShell extends ShellTestCase {
|
|
||||||
|
|
||||||
function testEcho() {
|
|
||||||
$this->assertTrue($this->execute('echo Hello'));
|
|
||||||
$this->assertExitCode(0);
|
|
||||||
$this->assertoutput('Hello');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFileExistence() {
|
|
||||||
$this->assertFileExists(dirname(__FILE__) . '/all_tests.php');
|
|
||||||
$this->assertFileNotExists('wibble');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFilePatterns() {
|
|
||||||
$this->assertFilePattern('/all[_ ]tests/i', dirname(__FILE__) . '/all_tests.php');
|
|
||||||
$this->assertNoFilePattern('/sputnik/i', dirname(__FILE__) . '/all_tests.php');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,42 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: shell_tester_test.php 1787 2008-04-26 20:35:39Z pp11 $
|
|
||||||
require_once(dirname(__FILE__) . '/../autorun.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../shell_tester.php');
|
|
||||||
Mock::generate('SimpleShell');
|
|
||||||
|
|
||||||
class TestOfShellTestCase extends ShellTestCase {
|
|
||||||
private $mock_shell = false;
|
|
||||||
|
|
||||||
function getShell() {
|
|
||||||
return $this->mock_shell;
|
|
||||||
}
|
|
||||||
|
|
||||||
function testGenericEquality() {
|
|
||||||
$this->assertEqual('a', 'a');
|
|
||||||
$this->assertNotEqual('a', 'A');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testExitCode() {
|
|
||||||
$this->mock_shell = new MockSimpleShell();
|
|
||||||
$this->mock_shell->setReturnValue('execute', 0);
|
|
||||||
$this->mock_shell->expectOnce('execute', array('ls'));
|
|
||||||
$this->assertTrue($this->execute('ls'));
|
|
||||||
$this->assertExitCode(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testOutput() {
|
|
||||||
$this->mock_shell = new MockSimpleShell();
|
|
||||||
$this->mock_shell->setReturnValue('execute', 0);
|
|
||||||
$this->mock_shell->setReturnValue('getOutput', "Line 1\nLine 2\n");
|
|
||||||
$this->assertOutput("Line 1\nLine 2\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testOutputPatterns() {
|
|
||||||
$this->mock_shell = new MockSimpleShell();
|
|
||||||
$this->mock_shell->setReturnValue('execute', 0);
|
|
||||||
$this->mock_shell->setReturnValue('getOutput', "Line 1\nLine 2\n");
|
|
||||||
$this->assertOutputPattern('/line/i');
|
|
||||||
$this->assertNoOutputPattern('/line 2/');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,58 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: simpletest_test.php 1748 2008-04-14 01:50:41Z lastcraft $
|
|
||||||
require_once(dirname(__FILE__) . '/../autorun.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../simpletest.php');
|
|
||||||
|
|
||||||
SimpleTest::ignore('ShouldNeverBeRunEither');
|
|
||||||
|
|
||||||
class ShouldNeverBeRun extends UnitTestCase {
|
|
||||||
function testWithNoChanceOfSuccess() {
|
|
||||||
$this->fail('Should be ignored');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ShouldNeverBeRunEither extends ShouldNeverBeRun { }
|
|
||||||
|
|
||||||
class TestOfStackTrace extends UnitTestCase {
|
|
||||||
|
|
||||||
function testCanFindAssertInTrace() {
|
|
||||||
$trace = new SimpleStackTrace(array('assert'));
|
|
||||||
$this->assertEqual(
|
|
||||||
$trace->traceMethod(array(array(
|
|
||||||
'file' => '/my_test.php',
|
|
||||||
'line' => 24,
|
|
||||||
'function' => 'assertSomething'))),
|
|
||||||
' at [/my_test.php line 24]');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class DummyResource { }
|
|
||||||
|
|
||||||
class TestOfContext extends UnitTestCase {
|
|
||||||
|
|
||||||
function testCurrentContextIsUnique() {
|
|
||||||
$this->assertSame(
|
|
||||||
SimpleTest::getContext(),
|
|
||||||
SimpleTest::getContext());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testContextHoldsCurrentTestCase() {
|
|
||||||
$context = SimpleTest::getContext();
|
|
||||||
$this->assertSame($this, $context->getTest());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testResourceIsSingleInstanceWithContext() {
|
|
||||||
$context = new SimpleTestContext();
|
|
||||||
$this->assertSame(
|
|
||||||
$context->get('DummyResource'),
|
|
||||||
$context->get('DummyResource'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testClearingContextResetsResources() {
|
|
||||||
$context = new SimpleTestContext();
|
|
||||||
$resource = $context->get('DummyResource');
|
|
||||||
$context->clear();
|
|
||||||
$this->assertClone($resource, $context->get('DummyResource'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,6 +0,0 @@
|
||||||
<html>
|
|
||||||
<head><title>Link to SimpleTest</title></head>
|
|
||||||
<body>
|
|
||||||
<a href="http://simpletest.org/">Link to SimpleTest</a>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -1,25 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: socket_test.php 1782 2008-04-25 17:09:06Z pp11 $
|
|
||||||
require_once(dirname(__FILE__) . '/../autorun.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../socket.php');
|
|
||||||
Mock::generate('SimpleSocket');
|
|
||||||
|
|
||||||
class TestOfSimpleStickyError extends UnitTestCase {
|
|
||||||
|
|
||||||
function testSettingError() {
|
|
||||||
$error = new SimpleStickyError();
|
|
||||||
$this->assertFalse($error->isError());
|
|
||||||
$error->setError('Ouch');
|
|
||||||
$this->assertTrue($error->isError());
|
|
||||||
$this->assertEqual($error->getError(), 'Ouch');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testClearingError() {
|
|
||||||
$error = new SimpleStickyError();
|
|
||||||
$error->setError('Ouch');
|
|
||||||
$this->assertTrue($error->isError());
|
|
||||||
$error->clearError();
|
|
||||||
$this->assertFalse($error->isError());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,3 +0,0 @@
|
||||||
<?php
|
|
||||||
require_once(dirname(__FILE__) . '/../../autorun.php');
|
|
||||||
?>
|
|
|
@ -1,9 +0,0 @@
|
||||||
<?php
|
|
||||||
require_once(dirname(__FILE__) . '/../../autorun.php');
|
|
||||||
|
|
||||||
class FailingTest extends UnitTestCase {
|
|
||||||
function test_fail() {
|
|
||||||
$this->assertEqual(1,2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1 +0,0 @@
|
||||||
ㄨ眾播輥奧禆蛺姣6
|
|
|
@ -1,9 +0,0 @@
|
||||||
<?php
|
|
||||||
require_once(dirname(__FILE__) . '/../../autorun.php');
|
|
||||||
|
|
||||||
class PassingTest extends UnitTestCase {
|
|
||||||
function test_pass() {
|
|
||||||
$this->assertEqual(2,2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,14 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: sample_test.php 1500 2007-04-29 14:33:31Z pp11 $
|
|
||||||
require_once dirname(__FILE__) . '/../../autorun.php';
|
|
||||||
|
|
||||||
class SampleTestForRecorder extends UnitTestCase {
|
|
||||||
function testTrueIsTrue() {
|
|
||||||
$this->assertTrue(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFalseIsTrue() {
|
|
||||||
$this->assertFalse(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,15 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: spl_examples.php 1262 2006-02-05 19:35:31Z lastcraft $
|
|
||||||
|
|
||||||
class IteratorImplementation implements Iterator {
|
|
||||||
function current() { }
|
|
||||||
function next() { }
|
|
||||||
function key() { }
|
|
||||||
function valid() { }
|
|
||||||
function rewind() { }
|
|
||||||
}
|
|
||||||
|
|
||||||
class IteratorAggregateImplementation implements IteratorAggregate {
|
|
||||||
function getIterator() { }
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1 +0,0 @@
|
||||||
Some more text content
|
|
|
@ -1,7 +0,0 @@
|
||||||
<?php
|
|
||||||
class test1 extends UnitTestCase {
|
|
||||||
function test_pass(){
|
|
||||||
$this->assertEqual(3,1+2, "pass1");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1 +0,0 @@
|
||||||
Sample for testing file upload
|
|
|
@ -1,554 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: tag_test.php 1748 2008-04-14 01:50:41Z lastcraft $
|
|
||||||
require_once(dirname(__FILE__) . '/../autorun.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../tag.php');
|
|
||||||
require_once(dirname(__FILE__) . '/../encoding.php');
|
|
||||||
Mock::generate('SimpleMultipartEncoding');
|
|
||||||
|
|
||||||
class TestOfTag extends UnitTestCase {
|
|
||||||
|
|
||||||
function testStartValuesWithoutAdditionalContent() {
|
|
||||||
$tag = new SimpleTitleTag(array('a' => '1', 'b' => ''));
|
|
||||||
$this->assertEqual($tag->getTagName(), 'title');
|
|
||||||
$this->assertIdentical($tag->getAttribute('a'), '1');
|
|
||||||
$this->assertIdentical($tag->getAttribute('b'), '');
|
|
||||||
$this->assertIdentical($tag->getAttribute('c'), false);
|
|
||||||
$this->assertIdentical($tag->getContent(), '');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testTitleContent() {
|
|
||||||
$tag = new SimpleTitleTag(array());
|
|
||||||
$this->assertTrue($tag->expectEndTag());
|
|
||||||
$tag->addContent('Hello');
|
|
||||||
$tag->addContent('World');
|
|
||||||
$this->assertEqual($tag->getText(), 'HelloWorld');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMessyTitleContent() {
|
|
||||||
$tag = new SimpleTitleTag(array());
|
|
||||||
$this->assertTrue($tag->expectEndTag());
|
|
||||||
$tag->addContent('<b>Hello</b>');
|
|
||||||
$tag->addContent('<em>World</em>');
|
|
||||||
$this->assertEqual($tag->getText(), 'HelloWorld');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testTagWithNoEnd() {
|
|
||||||
$tag = new SimpleTextTag(array());
|
|
||||||
$this->assertFalse($tag->expectEndTag());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testAnchorHref() {
|
|
||||||
$tag = new SimpleAnchorTag(array('href' => 'http://here/'));
|
|
||||||
$this->assertEqual($tag->getHref(), 'http://here/');
|
|
||||||
|
|
||||||
$tag = new SimpleAnchorTag(array('href' => ''));
|
|
||||||
$this->assertIdentical($tag->getAttribute('href'), '');
|
|
||||||
$this->assertIdentical($tag->getHref(), '');
|
|
||||||
|
|
||||||
$tag = new SimpleAnchorTag(array());
|
|
||||||
$this->assertIdentical($tag->getAttribute('href'), false);
|
|
||||||
$this->assertIdentical($tag->getHref(), '');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testIsIdMatchesIdAttribute() {
|
|
||||||
$tag = new SimpleAnchorTag(array('href' => 'http://here/', 'id' => 7));
|
|
||||||
$this->assertIdentical($tag->getAttribute('id'), '7');
|
|
||||||
$this->assertTrue($tag->isId(7));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfWidget extends UnitTestCase {
|
|
||||||
|
|
||||||
function testTextEmptyDefault() {
|
|
||||||
$tag = new SimpleTextTag(array('type' => 'text'));
|
|
||||||
$this->assertIdentical($tag->getDefault(), '');
|
|
||||||
$this->assertIdentical($tag->getValue(), '');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSettingOfExternalLabel() {
|
|
||||||
$tag = new SimpleTextTag(array('type' => 'text'));
|
|
||||||
$tag->setLabel('it');
|
|
||||||
$this->assertTrue($tag->isLabel('it'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testTextDefault() {
|
|
||||||
$tag = new SimpleTextTag(array('value' => 'aaa'));
|
|
||||||
$this->assertEqual($tag->getDefault(), 'aaa');
|
|
||||||
$this->assertEqual($tag->getValue(), 'aaa');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSettingTextValue() {
|
|
||||||
$tag = new SimpleTextTag(array('value' => 'aaa'));
|
|
||||||
$tag->setValue('bbb');
|
|
||||||
$this->assertEqual($tag->getValue(), 'bbb');
|
|
||||||
$tag->resetValue();
|
|
||||||
$this->assertEqual($tag->getValue(), 'aaa');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFailToSetHiddenValue() {
|
|
||||||
$tag = new SimpleTextTag(array('value' => 'aaa', 'type' => 'hidden'));
|
|
||||||
$this->assertFalse($tag->setValue('bbb'));
|
|
||||||
$this->assertEqual($tag->getValue(), 'aaa');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSubmitDefaults() {
|
|
||||||
$tag = new SimpleSubmitTag(array('type' => 'submit'));
|
|
||||||
$this->assertIdentical($tag->getName(), false);
|
|
||||||
$this->assertEqual($tag->getValue(), 'Submit');
|
|
||||||
$this->assertFalse($tag->setValue('Cannot set this'));
|
|
||||||
$this->assertEqual($tag->getValue(), 'Submit');
|
|
||||||
$this->assertEqual($tag->getLabel(), 'Submit');
|
|
||||||
|
|
||||||
$encoding = new MockSimpleMultipartEncoding();
|
|
||||||
$encoding->expectNever('add');
|
|
||||||
$tag->write($encoding);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testPopulatedSubmit() {
|
|
||||||
$tag = new SimpleSubmitTag(
|
|
||||||
array('type' => 'submit', 'name' => 's', 'value' => 'Ok!'));
|
|
||||||
$this->assertEqual($tag->getName(), 's');
|
|
||||||
$this->assertEqual($tag->getValue(), 'Ok!');
|
|
||||||
$this->assertEqual($tag->getLabel(), 'Ok!');
|
|
||||||
|
|
||||||
$encoding = new MockSimpleMultipartEncoding();
|
|
||||||
$encoding->expectOnce('add', array('s', 'Ok!'));
|
|
||||||
$tag->write($encoding);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testImageSubmit() {
|
|
||||||
$tag = new SimpleImageSubmitTag(
|
|
||||||
array('type' => 'image', 'name' => 's', 'alt' => 'Label'));
|
|
||||||
$this->assertEqual($tag->getName(), 's');
|
|
||||||
$this->assertEqual($tag->getLabel(), 'Label');
|
|
||||||
|
|
||||||
$encoding = new MockSimpleMultipartEncoding();
|
|
||||||
$encoding->expectAt(0, 'add', array('s.x', 20));
|
|
||||||
$encoding->expectAt(1, 'add', array('s.y', 30));
|
|
||||||
$tag->write($encoding, 20, 30);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testImageSubmitTitlePreferredOverAltForLabel() {
|
|
||||||
$tag = new SimpleImageSubmitTag(
|
|
||||||
array('type' => 'image', 'name' => 's', 'alt' => 'Label', 'title' => 'Title'));
|
|
||||||
$this->assertEqual($tag->getLabel(), 'Title');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testButton() {
|
|
||||||
$tag = new SimpleButtonTag(
|
|
||||||
array('type' => 'submit', 'name' => 's', 'value' => 'do'));
|
|
||||||
$tag->addContent('I am a button');
|
|
||||||
$this->assertEqual($tag->getName(), 's');
|
|
||||||
$this->assertEqual($tag->getValue(), 'do');
|
|
||||||
$this->assertEqual($tag->getLabel(), 'I am a button');
|
|
||||||
|
|
||||||
$encoding = new MockSimpleMultipartEncoding();
|
|
||||||
$encoding->expectOnce('add', array('s', 'do'));
|
|
||||||
$tag->write($encoding);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfTextArea extends UnitTestCase {
|
|
||||||
|
|
||||||
function testDefault() {
|
|
||||||
$tag = new SimpleTextAreaTag(array('name' => 'a'));
|
|
||||||
$tag->addContent('Some text');
|
|
||||||
$this->assertEqual($tag->getName(), 'a');
|
|
||||||
$this->assertEqual($tag->getDefault(), 'Some text');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testWrapping() {
|
|
||||||
$tag = new SimpleTextAreaTag(array('cols' => '10', 'wrap' => 'physical'));
|
|
||||||
$tag->addContent("Lot's of text that should be wrapped");
|
|
||||||
$this->assertEqual(
|
|
||||||
$tag->getDefault(),
|
|
||||||
"Lot's of\r\ntext that\r\nshould be\r\nwrapped");
|
|
||||||
$tag->setValue("New long text\r\nwith two lines");
|
|
||||||
$this->assertEqual(
|
|
||||||
$tag->getValue(),
|
|
||||||
"New long\r\ntext\r\nwith two\r\nlines");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testWrappingRemovesLeadingcariageReturn() {
|
|
||||||
$tag = new SimpleTextAreaTag(array('cols' => '20', 'wrap' => 'physical'));
|
|
||||||
$tag->addContent("\rStuff");
|
|
||||||
$this->assertEqual($tag->getDefault(), 'Stuff');
|
|
||||||
$tag->setValue("\nNew stuff\n");
|
|
||||||
$this->assertEqual($tag->getValue(), "New stuff\r\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testBreaksAreNewlineAndCarriageReturn() {
|
|
||||||
$tag = new SimpleTextAreaTag(array('cols' => '10'));
|
|
||||||
$tag->addContent("Some\nText\rwith\r\nbreaks");
|
|
||||||
$this->assertEqual($tag->getValue(), "Some\r\nText\r\nwith\r\nbreaks");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfCheckbox extends UnitTestCase {
|
|
||||||
|
|
||||||
function testCanSetCheckboxToNamedValueWithBooleanTrue() {
|
|
||||||
$tag = new SimpleCheckboxTag(array('name' => 'a', 'value' => 'A'));
|
|
||||||
$this->assertEqual($tag->getValue(), false);
|
|
||||||
$tag->setValue(true);
|
|
||||||
$this->assertIdentical($tag->getValue(), 'A');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfSelection extends UnitTestCase {
|
|
||||||
|
|
||||||
function testEmpty() {
|
|
||||||
$tag = new SimpleSelectionTag(array('name' => 'a'));
|
|
||||||
$this->assertIdentical($tag->getValue(), '');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSingle() {
|
|
||||||
$tag = new SimpleSelectionTag(array('name' => 'a'));
|
|
||||||
$option = new SimpleOptionTag(array());
|
|
||||||
$option->addContent('AAA');
|
|
||||||
$tag->addTag($option);
|
|
||||||
$this->assertEqual($tag->getValue(), 'AAA');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSingleDefault() {
|
|
||||||
$tag = new SimpleSelectionTag(array('name' => 'a'));
|
|
||||||
$option = new SimpleOptionTag(array('selected' => ''));
|
|
||||||
$option->addContent('AAA');
|
|
||||||
$tag->addTag($option);
|
|
||||||
$this->assertEqual($tag->getValue(), 'AAA');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSingleMappedDefault() {
|
|
||||||
$tag = new SimpleSelectionTag(array('name' => 'a'));
|
|
||||||
$option = new SimpleOptionTag(array('selected' => '', 'value' => 'aaa'));
|
|
||||||
$option->addContent('AAA');
|
|
||||||
$tag->addTag($option);
|
|
||||||
$this->assertEqual($tag->getValue(), 'aaa');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testStartsWithDefault() {
|
|
||||||
$tag = new SimpleSelectionTag(array('name' => 'a'));
|
|
||||||
$a = new SimpleOptionTag(array());
|
|
||||||
$a->addContent('AAA');
|
|
||||||
$tag->addTag($a);
|
|
||||||
$b = new SimpleOptionTag(array('selected' => ''));
|
|
||||||
$b->addContent('BBB');
|
|
||||||
$tag->addTag($b);
|
|
||||||
$c = new SimpleOptionTag(array());
|
|
||||||
$c->addContent('CCC');
|
|
||||||
$tag->addTag($c);
|
|
||||||
$this->assertEqual($tag->getValue(), 'BBB');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSettingOption() {
|
|
||||||
$tag = new SimpleSelectionTag(array('name' => 'a'));
|
|
||||||
$a = new SimpleOptionTag(array());
|
|
||||||
$a->addContent('AAA');
|
|
||||||
$tag->addTag($a);
|
|
||||||
$b = new SimpleOptionTag(array('selected' => ''));
|
|
||||||
$b->addContent('BBB');
|
|
||||||
$tag->addTag($b);
|
|
||||||
$c = new SimpleOptionTag(array());
|
|
||||||
$c->addContent('CCC');
|
|
||||||
$tag->setValue('AAA');
|
|
||||||
$this->assertEqual($tag->getValue(), 'AAA');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSettingMappedOption() {
|
|
||||||
$tag = new SimpleSelectionTag(array('name' => 'a'));
|
|
||||||
$a = new SimpleOptionTag(array('value' => 'aaa'));
|
|
||||||
$a->addContent('AAA');
|
|
||||||
$tag->addTag($a);
|
|
||||||
$b = new SimpleOptionTag(array('value' => 'bbb', 'selected' => ''));
|
|
||||||
$b->addContent('BBB');
|
|
||||||
$tag->addTag($b);
|
|
||||||
$c = new SimpleOptionTag(array('value' => 'ccc'));
|
|
||||||
$c->addContent('CCC');
|
|
||||||
$tag->addTag($c);
|
|
||||||
$tag->setValue('AAA');
|
|
||||||
$this->assertEqual($tag->getValue(), 'aaa');
|
|
||||||
$tag->setValue('ccc');
|
|
||||||
$this->assertEqual($tag->getValue(), 'ccc');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSelectionDespiteSpuriousWhitespace() {
|
|
||||||
$tag = new SimpleSelectionTag(array('name' => 'a'));
|
|
||||||
$a = new SimpleOptionTag(array());
|
|
||||||
$a->addContent(' AAA ');
|
|
||||||
$tag->addTag($a);
|
|
||||||
$b = new SimpleOptionTag(array('selected' => ''));
|
|
||||||
$b->addContent(' BBB ');
|
|
||||||
$tag->addTag($b);
|
|
||||||
$c = new SimpleOptionTag(array());
|
|
||||||
$c->addContent(' CCC ');
|
|
||||||
$tag->addTag($c);
|
|
||||||
$this->assertEqual($tag->getValue(), ' BBB ');
|
|
||||||
$tag->setValue('AAA');
|
|
||||||
$this->assertEqual($tag->getValue(), ' AAA ');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFailToSetIllegalOption() {
|
|
||||||
$tag = new SimpleSelectionTag(array('name' => 'a'));
|
|
||||||
$a = new SimpleOptionTag(array());
|
|
||||||
$a->addContent('AAA');
|
|
||||||
$tag->addTag($a);
|
|
||||||
$b = new SimpleOptionTag(array('selected' => ''));
|
|
||||||
$b->addContent('BBB');
|
|
||||||
$tag->addTag($b);
|
|
||||||
$c = new SimpleOptionTag(array());
|
|
||||||
$c->addContent('CCC');
|
|
||||||
$tag->addTag($c);
|
|
||||||
$this->assertFalse($tag->setValue('Not present'));
|
|
||||||
$this->assertEqual($tag->getValue(), 'BBB');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testNastyOptionValuesThatLookLikeFalse() {
|
|
||||||
$tag = new SimpleSelectionTag(array('name' => 'a'));
|
|
||||||
$a = new SimpleOptionTag(array('value' => '1'));
|
|
||||||
$a->addContent('One');
|
|
||||||
$tag->addTag($a);
|
|
||||||
$b = new SimpleOptionTag(array('value' => '0'));
|
|
||||||
$b->addContent('Zero');
|
|
||||||
$tag->addTag($b);
|
|
||||||
$this->assertIdentical($tag->getValue(), '1');
|
|
||||||
$tag->setValue('Zero');
|
|
||||||
$this->assertIdentical($tag->getValue(), '0');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testBlankOption() {
|
|
||||||
$tag = new SimpleSelectionTag(array('name' => 'A'));
|
|
||||||
$a = new SimpleOptionTag(array());
|
|
||||||
$tag->addTag($a);
|
|
||||||
$b = new SimpleOptionTag(array());
|
|
||||||
$b->addContent('b');
|
|
||||||
$tag->addTag($b);
|
|
||||||
$this->assertIdentical($tag->getValue(), '');
|
|
||||||
$tag->setValue('b');
|
|
||||||
$this->assertIdentical($tag->getValue(), 'b');
|
|
||||||
$tag->setValue('');
|
|
||||||
$this->assertIdentical($tag->getValue(), '');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMultipleDefaultWithNoSelections() {
|
|
||||||
$tag = new MultipleSelectionTag(array('name' => 'a', 'multiple' => ''));
|
|
||||||
$a = new SimpleOptionTag(array());
|
|
||||||
$a->addContent('AAA');
|
|
||||||
$tag->addTag($a);
|
|
||||||
$b = new SimpleOptionTag(array());
|
|
||||||
$b->addContent('BBB');
|
|
||||||
$tag->addTag($b);
|
|
||||||
$this->assertIdentical($tag->getDefault(), array());
|
|
||||||
$this->assertIdentical($tag->getValue(), array());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMultipleDefaultWithSelections() {
|
|
||||||
$tag = new MultipleSelectionTag(array('name' => 'a', 'multiple' => ''));
|
|
||||||
$a = new SimpleOptionTag(array('selected' => ''));
|
|
||||||
$a->addContent('AAA');
|
|
||||||
$tag->addTag($a);
|
|
||||||
$b = new SimpleOptionTag(array('selected' => ''));
|
|
||||||
$b->addContent('BBB');
|
|
||||||
$tag->addTag($b);
|
|
||||||
$this->assertIdentical($tag->getDefault(), array('AAA', 'BBB'));
|
|
||||||
$this->assertIdentical($tag->getValue(), array('AAA', 'BBB'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSettingMultiple() {
|
|
||||||
$tag = new MultipleSelectionTag(array('name' => 'a', 'multiple' => ''));
|
|
||||||
$a = new SimpleOptionTag(array('selected' => ''));
|
|
||||||
$a->addContent('AAA');
|
|
||||||
$tag->addTag($a);
|
|
||||||
$b = new SimpleOptionTag(array());
|
|
||||||
$b->addContent('BBB');
|
|
||||||
$tag->addTag($b);
|
|
||||||
$c = new SimpleOptionTag(array('selected' => '', 'value' => 'ccc'));
|
|
||||||
$c->addContent('CCC');
|
|
||||||
$tag->addTag($c);
|
|
||||||
$this->assertIdentical($tag->getDefault(), array('AAA', 'ccc'));
|
|
||||||
$this->assertTrue($tag->setValue(array('BBB', 'ccc')));
|
|
||||||
$this->assertIdentical($tag->getValue(), array('BBB', 'ccc'));
|
|
||||||
$this->assertTrue($tag->setValue(array()));
|
|
||||||
$this->assertIdentical($tag->getValue(), array());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFailToSetIllegalOptionsInMultiple() {
|
|
||||||
$tag = new MultipleSelectionTag(array('name' => 'a', 'multiple' => ''));
|
|
||||||
$a = new SimpleOptionTag(array('selected' => ''));
|
|
||||||
$a->addContent('AAA');
|
|
||||||
$tag->addTag($a);
|
|
||||||
$b = new SimpleOptionTag(array());
|
|
||||||
$b->addContent('BBB');
|
|
||||||
$tag->addTag($b);
|
|
||||||
$this->assertFalse($tag->setValue(array('CCC')));
|
|
||||||
$this->assertTrue($tag->setValue(array('AAA', 'BBB')));
|
|
||||||
$this->assertFalse($tag->setValue(array('AAA', 'CCC')));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfRadioGroup extends UnitTestCase {
|
|
||||||
|
|
||||||
function testEmptyGroup() {
|
|
||||||
$group = new SimpleRadioGroup();
|
|
||||||
$this->assertIdentical($group->getDefault(), false);
|
|
||||||
$this->assertIdentical($group->getValue(), false);
|
|
||||||
$this->assertFalse($group->setValue('a'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testReadingSingleButtonGroup() {
|
|
||||||
$group = new SimpleRadioGroup();
|
|
||||||
$group->addWidget(new SimpleRadioButtonTag(
|
|
||||||
array('value' => 'A', 'checked' => '')));
|
|
||||||
$this->assertIdentical($group->getDefault(), 'A');
|
|
||||||
$this->assertIdentical($group->getValue(), 'A');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testReadingMultipleButtonGroup() {
|
|
||||||
$group = new SimpleRadioGroup();
|
|
||||||
$group->addWidget(new SimpleRadioButtonTag(
|
|
||||||
array('value' => 'A')));
|
|
||||||
$group->addWidget(new SimpleRadioButtonTag(
|
|
||||||
array('value' => 'B', 'checked' => '')));
|
|
||||||
$this->assertIdentical($group->getDefault(), 'B');
|
|
||||||
$this->assertIdentical($group->getValue(), 'B');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFailToSetUnlistedValue() {
|
|
||||||
$group = new SimpleRadioGroup();
|
|
||||||
$group->addWidget(new SimpleRadioButtonTag(array('value' => 'z')));
|
|
||||||
$this->assertFalse($group->setValue('a'));
|
|
||||||
$this->assertIdentical($group->getValue(), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSettingNewValueClearsTheOldOne() {
|
|
||||||
$group = new SimpleRadioGroup();
|
|
||||||
$group->addWidget(new SimpleRadioButtonTag(
|
|
||||||
array('value' => 'A')));
|
|
||||||
$group->addWidget(new SimpleRadioButtonTag(
|
|
||||||
array('value' => 'B', 'checked' => '')));
|
|
||||||
$this->assertTrue($group->setValue('A'));
|
|
||||||
$this->assertIdentical($group->getValue(), 'A');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testIsIdMatchesAnyWidgetInSet() {
|
|
||||||
$group = new SimpleRadioGroup();
|
|
||||||
$group->addWidget(new SimpleRadioButtonTag(
|
|
||||||
array('value' => 'A', 'id' => 'i1')));
|
|
||||||
$group->addWidget(new SimpleRadioButtonTag(
|
|
||||||
array('value' => 'B', 'id' => 'i2')));
|
|
||||||
$this->assertFalse($group->isId('i0'));
|
|
||||||
$this->assertTrue($group->isId('i1'));
|
|
||||||
$this->assertTrue($group->isId('i2'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testIsLabelMatchesAnyWidgetInSet() {
|
|
||||||
$group = new SimpleRadioGroup();
|
|
||||||
$button1 = new SimpleRadioButtonTag(array('value' => 'A'));
|
|
||||||
$button1->setLabel('one');
|
|
||||||
$group->addWidget($button1);
|
|
||||||
$button2 = new SimpleRadioButtonTag(array('value' => 'B'));
|
|
||||||
$button2->setLabel('two');
|
|
||||||
$group->addWidget($button2);
|
|
||||||
$this->assertFalse($group->isLabel('three'));
|
|
||||||
$this->assertTrue($group->isLabel('one'));
|
|
||||||
$this->assertTrue($group->isLabel('two'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfTagGroup extends UnitTestCase {
|
|
||||||
|
|
||||||
function testReadingMultipleCheckboxGroup() {
|
|
||||||
$group = new SimpleCheckboxGroup();
|
|
||||||
$group->addWidget(new SimpleCheckboxTag(array('value' => 'A')));
|
|
||||||
$group->addWidget(new SimpleCheckboxTag(
|
|
||||||
array('value' => 'B', 'checked' => '')));
|
|
||||||
$this->assertIdentical($group->getDefault(), 'B');
|
|
||||||
$this->assertIdentical($group->getValue(), 'B');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testReadingMultipleUncheckedItems() {
|
|
||||||
$group = new SimpleCheckboxGroup();
|
|
||||||
$group->addWidget(new SimpleCheckboxTag(array('value' => 'A')));
|
|
||||||
$group->addWidget(new SimpleCheckboxTag(array('value' => 'B')));
|
|
||||||
$this->assertIdentical($group->getDefault(), false);
|
|
||||||
$this->assertIdentical($group->getValue(), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testReadingMultipleCheckedItems() {
|
|
||||||
$group = new SimpleCheckboxGroup();
|
|
||||||
$group->addWidget(new SimpleCheckboxTag(
|
|
||||||
array('value' => 'A', 'checked' => '')));
|
|
||||||
$group->addWidget(new SimpleCheckboxTag(
|
|
||||||
array('value' => 'B', 'checked' => '')));
|
|
||||||
$this->assertIdentical($group->getDefault(), array('A', 'B'));
|
|
||||||
$this->assertIdentical($group->getValue(), array('A', 'B'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSettingSingleValue() {
|
|
||||||
$group = new SimpleCheckboxGroup();
|
|
||||||
$group->addWidget(new SimpleCheckboxTag(array('value' => 'A')));
|
|
||||||
$group->addWidget(new SimpleCheckboxTag(array('value' => 'B')));
|
|
||||||
$this->assertTrue($group->setValue('A'));
|
|
||||||
$this->assertIdentical($group->getValue(), 'A');
|
|
||||||
$this->assertTrue($group->setValue('B'));
|
|
||||||
$this->assertIdentical($group->getValue(), 'B');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSettingMultipleValues() {
|
|
||||||
$group = new SimpleCheckboxGroup();
|
|
||||||
$group->addWidget(new SimpleCheckboxTag(array('value' => 'A')));
|
|
||||||
$group->addWidget(new SimpleCheckboxTag(array('value' => 'B')));
|
|
||||||
$this->assertTrue($group->setValue(array('A', 'B')));
|
|
||||||
$this->assertIdentical($group->getValue(), array('A', 'B'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSettingNoValue() {
|
|
||||||
$group = new SimpleCheckboxGroup();
|
|
||||||
$group->addWidget(new SimpleCheckboxTag(array('value' => 'A')));
|
|
||||||
$group->addWidget(new SimpleCheckboxTag(array('value' => 'B')));
|
|
||||||
$this->assertTrue($group->setValue(false));
|
|
||||||
$this->assertIdentical($group->getValue(), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testIsIdMatchesAnyIdInSet() {
|
|
||||||
$group = new SimpleCheckboxGroup();
|
|
||||||
$group->addWidget(new SimpleCheckboxTag(array('id' => 1, 'value' => 'A')));
|
|
||||||
$group->addWidget(new SimpleCheckboxTag(array('id' => 2, 'value' => 'B')));
|
|
||||||
$this->assertFalse($group->isId(0));
|
|
||||||
$this->assertTrue($group->isId(1));
|
|
||||||
$this->assertTrue($group->isId(2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfUploadWidget extends UnitTestCase {
|
|
||||||
|
|
||||||
function testValueIsFilePath() {
|
|
||||||
$upload = new SimpleUploadTag(array('name' => 'a'));
|
|
||||||
$upload->setValue(dirname(__FILE__) . '/support/upload_sample.txt');
|
|
||||||
$this->assertEqual($upload->getValue(), dirname(__FILE__) . '/support/upload_sample.txt');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSubmitsFileContents() {
|
|
||||||
$encoding = new MockSimpleMultipartEncoding();
|
|
||||||
$encoding->expectOnce('attach', array(
|
|
||||||
'a',
|
|
||||||
'Sample for testing file upload',
|
|
||||||
'upload_sample.txt'));
|
|
||||||
$upload = new SimpleUploadTag(array('name' => 'a'));
|
|
||||||
$upload->setValue(dirname(__FILE__) . '/support/upload_sample.txt');
|
|
||||||
$upload->write($encoding);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestOfLabelTag extends UnitTestCase {
|
|
||||||
|
|
||||||
function testLabelShouldHaveAnEndTag() {
|
|
||||||
$label = new SimpleLabelTag(array());
|
|
||||||
$this->assertTrue($label->expectEndTag());
|
|
||||||
}
|
|
||||||
|
|
||||||
function testContentIsTextOnly() {
|
|
||||||
$label = new SimpleLabelTag(array());
|
|
||||||
$label->addContent('Here <tag>are</tag> words');
|
|
||||||
$this->assertEqual($label->getText(), 'Here are words');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,8 +0,0 @@
|
||||||
<?php
|
|
||||||
// $Id: test_with_parse_error.php 901 2005-01-24 00:32:14Z lastcraft $
|
|
||||||
|
|
||||||
class TestCaseWithParseError extends UnitTestCase {
|
|
||||||
wibble
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue