/** Returns a table of a given name in the schema. @param $sName The name of the table. @return weePgSQLDbMetaTable The table. @throw UnexpectedValueException The table does not exist in the schema. */ public function table($sName) { $oQuery = $this->meta()->db()->query("\n\t\t\tSELECT\t\tn.nspname AS schema, c.relname AS name, r.rolname AS owner,\n\t\t\t\t\t\tpg_catalog.obj_description(c.oid, 'pg_class') AS comment,\n\t\t\t\t\t\tpg_catalog.pg_has_role(r.rolname, 'USAGE') AS alterable\n\t\t\t FROM\tpg_catalog.pg_class c\n\t\t\t\t\t\tJOIN pg_catalog.pg_namespace\tn ON n.oid = c.relnamespace\n\t\t\t\t\t\tJOIN pg_catalog.pg_roles\t\tr ON r.oid = c.relowner\n\t\t\t\tWHERE\t\tc.relname = :table\n\t\t\t\t\t\tAND\tc.relkind = 'r'\n\t\t\t\t\t\tAND\tn.nspname = :name\n\t\t\t\tLIMIT\t1\n\t\t", array('table' => $sName) + $this->aData); count($oQuery) == 1 or burn('UnexpectedValueException', sprintf(_WT('Table "%s" does not exist in the schema.'), $sName)); $sClass = $this->meta()->getTableClass(); return new $sClass($this->meta(), $oQuery->fetch()); }
/** Return the default value of the column. @return string The default value of the column. @throw IllegalStateException The column does not have a default value. */ public function defaultValue() { $this->hasDefault() or burn('IllegalStateException', _WT('The column does not have a default value.')); // Strip wrapping parenthesis. $i = strspn($this->aData['default'], '('); return substr($this->aData['default'], $i, -$i); }
/** Sets the widget and complete data passed to the weeForm object. Usually either $_POST or $_GET. @param $oWidget The widget to validate. @param $aData The data to check, if applicable. @throw IllegalStateException The validator has already been attached to a form widget. */ public function setFormData(SimpleXMLElement $oWidget, array $aData) { $this->oWidget === null or burn('IllegalStateException', _WT('The validator has already been attached to a form widget.')); $oWidget->getName() === 'widget' or burn('InvalidArgumentException', _WT('The $oWidget argument must be a widget element.')); $this->aData = $aData; $this->oWidget = $oWidget; }
/** Returns a table of a given name in the database. @param $sName The name of the table. @return weeMySQLDbMetaTable The table. @throw UnexpectedValueException The tables does not exist. */ public function table($sName) { $oQuery = $this->db()->query("\n\t\t\tSELECT TABLE_NAME AS name, TABLE_COMMENT AS comment\n\t\t\t\tFROM\tinformation_schema.tables\n\t\t\t\tWHERE\tTABLE_NAME\t\t= ?\n\t\t\t\t\tAND\tTABLE_SCHEMA\t= DATABASE()\n\t\t\t\t\tAND\tTABLE_TYPE\t\t= 'BASE TABLE'\n\t\t\t\tLIMIT\t1\n\t\t", $sName); count($oQuery) == 1 or burn('UnexpectedValueException', sprintf(_WT('Table "%s" does not exist.'), $sName)); $sClass = $this->getTableClass(); return new $sClass($this, $oQuery->fetch()); }
/** Configure the filename and the data for this template. @param $sTemplate The template name. @param $aData Data to be used in the template. */ public function __construct($sTemplate, array $aData = array()) { $this->sFilename = TPL_PATH . $sTemplate . TPL_EXT; file_exists($this->sFilename) or burn('FileNotFoundException', sprintf(_WT('The file "%s" does not exist.'), $this->sFilename)); parent::__construct($aData); $this->setMIMEType('text/html'); }
/** Define an additional header for this email. This method can be called directly from the template itself. @param $sName The header name. @param $sValue New value for that header. */ public function header($sName, $sValue) { empty($sName) and burn('UnexpectedValueException', _WT('The argument $sName must not be empty.')); empty($sValue) and burn('UnexpectedValueException', _WT('The argument $sValue must not be empty.')); strpos($sName, "\r") !== false || strpos($sName, "\n") !== false || strpos($sValue, "\r") !== false || strpos($sValue, "\n") !== false and burn('UnexpectedValueException', _WT('Line breaks are not allowed in headers to prevent HTTP Response Splitting.')); strpos($sName, "") !== false || strpos($sValue, "") !== false and burn('UnexpectedValueException', _WT('NUL characters are not allowed in headers.')); $this->aHeaders[$sName] = $sValue; }
/** Executes the prepared statement. @return mixed An instance of weeDatabaseDummyResult if the query returned rows or null. */ public function execute() { $this->oStatement->execute(); $a = $this->oStatement->errorInfo(); $a[0] == '0000' or burn('DatabaseException', sprintf(_WT("Failed to execute the query with the following error:\n%s"), $a[2])); $this->iNumAffectedRows = $this->oDb->doRowCount($this->oStatement, true); if ($this->oStatement->columnCount()) { return new weeDatabaseDummyResult($this->oStatement->fetchAll(PDO::FETCH_ASSOC)); } }
/** Returns the default value of the column. @return string The default value of the column. @throw IllegalStateException The column does not have a default value. */ public function defaultValue() { $this->hasDefault() or burn('IllegalStateException', _WT('The column does not have a default value.')); return $this->db()->queryValue(' SELECT pg_catalog.pg_get_expr(adbin, adrelid) FROM pg_catalog.pg_attrdef WHERE adrelid = ?::regclass AND adnum = ? ', $this->oTable->quotedName(), $this->num()); }
/** Binds parameters to the statement. If the query is not using interrogation marks placeholders, you can call this method with a parameter name and its value. @overload bind($sName, $mValue) Example of query call with one argument instead of an array. @param $aParameters The parameters to bind to the statement. @return $this Used to chain methods. @throw InvalidArgumentException The bind method has been called with one argument but it's not an array. @throw InvalidArgumentException The bind method has been called with two arguments but its first is not a string. @throw BadMethodCallException The bind method has been called with more than 2 arguments. */ public function bind($aParameters) { if (func_num_args() > 1) { is_string($aParameters) or burn('InvalidArgumentException', _WT('The first argument of the bind method should be a string when called with two parameters.')); $aParameters = array($aParameters => func_get_arg(1)); } else { is_array($aParameters) or burn('InvalidArgumentException', _WT('The given argument of the bind method is not an array.')); } $this->doBind($aParameters); return $this; }
/** Initialize a new BadXMLException instance. @param $sMessage The message of the exception. @param $oError The libxml error associated to the exception. */ public function __construct($sMessage, LibXmlError $oError = null) { $iCode = 0; if ($oError) { $sMessage .= "\n"; $sMessage .= sprintf(_WT('libxml returned the following error (line %d, column %d):'), $oError->line, $oError->column); $sMessage .= "\n" . $oError->message; $iCode = $oError->code; } parent::__construct($sMessage, $iCode); }
/** Executes the prepared statement. @return mixed An instance of weeDatabaseDummyResult if the query returned rows or null. */ public function execute() { // oci_execute triggers a warning when the statement could not be executed. @oci_execute($this->rStatement, OCI_DEFAULT) or burn('DatabaseException', sprintf(_WT("Failed to execute the query with the following error:\n%s"), array_value(oci_error($this->rStatement), 'message'))); $this->iNumAffectedRows = oci_num_rows($this->rStatement); if (oci_num_fields($this->rStatement) > 0) { // TODO: Check whether the silence operator is really required here. @oci_fetch_all($this->rStatement, $aRows, 0, -1, OCI_ASSOC | OCI_FETCHSTATEMENT_BY_ROW); return new weeDatabaseDummyResult($aRows); } }
/** Does the mssql-dependent work of the execute method. @param $sQuery The query to execute. @return weeSQLiteResult A result set for SELECT queries. */ protected function doQuery($sQuery) { // mssql_query triggers a warning when the query could not be executed. $m = @mssql_query($sQuery, $this->rLink); $m === false and burn('DatabaseException', sprintf(_WT("Failed to execute the query with the following error:\n%s"), mssql_get_last_message())); // Get it now since it can be wrong if numAffectedRows is called after getPKId $this->iNumAffectedRows = mssql_rows_affected($this->rLink); if ($m !== true) { return new weeMSSQLResult($m); } }
/** Attachs a value to the validator. $mValue must be either a string, an integer, a float, an instance of Printable or an object castable to string. @param $mValue The value to attach. @return $this Used to chain methods. @throw DomainException $mValue is not of a correct type. */ public function setValue($mValue) { if (is_object($mValue)) { if ($mValue instanceof Printable) { $mValue = $mValue->toString(); } elseif (method_exists($mValue, '__toString')) { $mValue = (string) $mValue; } } is_null($mValue) || is_string($mValue) || is_int($mValue) || is_float($mValue) or burn('DomainException', _WT('$mValue is not of a correct type.')); return parent::setValue($mValue); }
/** Return a table of a given name in the schema. @param $sName The name of the table. @return weeOracleDbMetaTable The table. @throw UnexpectedValueException The table does not exist in the schema. */ public function table($sName) { $oQuery = $this->meta()->db()->query(' SELECT OWNER AS "schema", TABLE_NAME AS "name", t.NUM_ROWS, c.COMMENTS AS "comment" FROM SYS.ALL_TABLES t LEFT JOIN SYS.ALL_TAB_COMMENTS c USING (OWNER, TABLE_NAME) WHERE TABLE_NAME = :table AND OWNER = :name AND t.DURATION IS NULL ', array('table' => $sName) + $this->aData); count($oQuery) == 1 or burn('UnexpectedValueException', sprintf(_WT('Table "%s" does not exist in the schema.'), $sName)); $sClass = $this->meta()->getTableClass(); return new $sClass($this->meta(), $oQuery->fetch()); }
/** Does the sqlite-dependent work of the execute method. @param $sQuery The query to execute. @return weeSQLiteResult A result set for SELECT queries. */ protected function doQuery($sQuery) { // SQLiteDatabase::query triggers a warning when the query could not be executed. $m = @$this->oSQLiteDb->query($sQuery, SQLITE_ASSOC, $sLastError); if ($m === false) { if ($sLastError === null) { $sLastError = sqlite_error_string($this->oSQLiteDb->lastError()); } burn('DatabaseException', sprintf(_WT("Failed to execute the query with the following error:\n%s"), $sLastError)); } $this->iNumAffectedRows = $this->oSQLiteDb->changes(); if ($m->numFields()) { return new weeSQLiteResult($m); } }
/** Encode an array. @param $a The array to encode. @return array The encoded array. @throw IllegalStateException This source does not have an encoder. */ protected function encodeArray($a) { $this->getEncoder() !== null or burn('IllegalStateException', _WT('This data source does not have an encoder.')); foreach ($a as $mName => $mValue) { if ($mValue instanceof weeDataSource) { $mValue->setEncoder($this->oEncoder); } elseif (is_object($mValue)) { continue; } elseif (is_array($mValue)) { $a[$mName] = $this->encodeArray($mValue); } else { $a[$mName] = $this->getEncoder()->encode($mValue); } } return $a; }
/** Process the pipe. This method should be called after the input of the pipe has been sent into the output buffer. */ public function process() { // Store LaTeX output in a temporary file $sTmpFilename = tempnam(null, null); file_put_contents($sTmpFilename, ob_get_clean()); // Convert it to PDF $sTmpDir = sys_get_temp_dir(); $sPdfLatex = 'cd ' . $sTmpDir . ' && pdflatex ' . array_value($this->aParams, 'options') . ' ' . $sTmpFilename; exec($sPdfLatex . ' > ' . $sTmpDir . '/pdflatex1.log'); exec($sPdfLatex . ' > ' . $sTmpDir . '/pdflatex2.log'); // filesize will trigger a warning if the file couldn't be stat'd (usually because it doesn't exist). $iSize = @filesize($sTmpFilename . '.pdf'); $iSize === false and burn('UnexpectedValueException', _WT(sprintf('The conversion of file "%s" from LaTeX to PDF failed.', $sTmpFilename))); // Send the PDF to the browser safe_header('Content-Length: ' . $iSize); readfile($sTmpFilename . '.pdf'); // Cleanup the temporary directory exec('rm ' . $sTmpFilename . '*'); }
/** Initialize the mailbox connection. The mailbox connection parameters are as follow: * host: Host name of the server hosting the mailbox. Default: localhost. * port: Port of the imap service. Default: 143. * mailbox: Mailbox name. Default: INBOX. * flags: Connection flags. Optionnal. * user: User name. * password: User password. For a detailed list of available flags, please see the PHP documentation for imap_open. The connection to the mailbox is read-only until tested enough. @param $aParams Mailbox connection parameters. @see http://php.net/imap_open */ public function __construct($aParams) { function_exists('imap_open') or burn('ConfigurationException', _WT('The IMAP PHP extension is required by the weeFetchMail class.')); empty($aParams['user']) and burn('InvalidParameterException', _WT('The user name was not provided in the connection parameters.')); empty($aParams['password']) and burn('InvalidParameterException', _WT('The user password was not provided in the connection parameters.')); // Fill in the default values $aParams = $aParams + array('host' => 'localhost', 'port' => 143, 'mailbox' => 'INBOX'); $sConnection = '{' . $aParams['host'] . ':' . $aParams['port']; if (!empty($aParams['flags'])) { $sConnection .= $aParams['flags']; } $sConnection .= '}' . $aParams['mailbox']; $this->rLink = @imap_open($sConnection, $aParams['user'], $aParams['password'], OP_READONLY, 1); // We must clear the errors and alerts or they'll be thrown separately, possibly multiple times. // Despite their names, those functions also clear the errors buffer. imap_alerts(); $a = imap_errors(); // Then we only output the first error from the array we retrieved (usually good enough). $this->rLink === false and burn('UnexpectedValueException', _WT("Couldn't open stream \"%s\" with the following error:\n%s", $sConnection, $a[0])); }
/** Saves the data stored in this model to the database. @throw IllegalStateException The data was empty or the table has no primary key. */ public function update() { empty($this->aData) and burn('IllegalStateException', _WT('The model does not contain any data.')); $oDb = $this->getDb(); if (empty($this->aMeta)) { $oSet = new $this->sSet(); $oSet->setDb($oDb); $this->aMeta = $oSet->getMeta(); } empty($this->aMeta['primary']) and burn('IllegalStateException', _WT('The table has no primary key defined.')); $sQuery = 'UPDATE ' . $this->aMeta['table'] . ' SET '; foreach ($this->aData as $sName => $mValue) { if (in_array($sName, $this->aMeta['columns']) && !in_array($sName, $this->aMeta['primary'])) { $sQuery .= $oDb->escapeIdent($sName) . '=' . $oDb->escape($this->aData[$sName]) . ', '; } } $sQuery = substr($sQuery, 0, -2) . ' WHERE'; $sAnd = ''; foreach ($this->aMeta['primary'] as $sName) { $sQuery .= $sAnd . $oDb->escapeIdent($sName) . '=' . $oDb->escape($this->aData[$sName]); $sAnd = ' AND '; } $this->query($sQuery); }
/** Returns the names of the columns of the primary key of the table. As the columns taking part in the primary key are known by the table instance, we provide a shortcut method to access these informations without creating a new weeSQLiteDbMetaPrimaryKey instance. This shortcut is used by the weeSQLiteDbMetaColumn::getValidator to check if the column is "INTEGER PRIMARY KEY". @return array(string) The names of the columns of the primary key of the table. @throw IllegalStateException The table does not have a primary key. */ public function primaryKeyColumnsNames() { $this->queryColumns(); !empty($this->aPrimaryKey) or burn('IllegalStateException', _WT('The table does not have a primary key.')); return $this->aPrimaryKey; }
<?php function_exists('ldap_connect') or $this->skip(); try { require ROOT_PATH . 'tools/tests/ldap/init.php.inc'; $sDN = 'dc=example,dc=com'; $oResult = $o->search($sDN, 'ou=*', false); $oEntry = $oResult->fetch(); $this->isEqual($oEntry->getDN(), 'ou=customers,dc=example,dc=com', _WT('Failed to get the expected entry.')); $this->isEqual(2, count($oResult), _WT('Bad number of entries.')); $aEntries = $oResult->fetchAll(); $this->isEqual(2, count($aEntries), _WT('Bad number of entries.')); $oResult->sort('ou'); $aSorted = array(0 => 'ou=countries,dc=example,dc=com', 1 => 'ou=customers,dc=example,dc=com'); foreach ($oResult as $key => $entry) { $aResult[$key] = $entry->getDN(); } $this->isEqual($aSorted, $aResult, _WT('The entries were not sorted.')); } catch (LDAPException $e) { $this->fail(_WT('weeLDAP should not throw an LDAPException.')); }
<?php require_once 'init.php.inc'; if (function_exists('ctype_graph')) { $this->isTrue(ctype_graph('fjsdiopfhsiofnuios'), _WT('Original ctype_graph fails to validate random letters.')); $this->isTrue(ctype_graph('FELMNFKLFDSNFSKLFNSDL'), _WT('Original ctype_graph fails to validate random uppercase letters.')); $this->isTrue(ctype_graph('0123456789azertyuiopqsdfghjklmwxcvbn'), _WT('Original ctype_graph fails to validate [0-9a-z].')); $this->isTrue(ctype_graph('5686541641'), _WT('Original ctype_graph fails to validate random numbers.')); $this->isTrue(ctype_graph('5A1C9B3F'), _WT('Original ctype_graph fails to validate random hexadecimal numbers.')); $this->isTrue(ctype_graph('0123456789azertyuiopqsdfghjklmwxcvbn?'), _WT('Original ctype_graph fails to validate [0-9a-z?].')); $this->isTrue(ctype_graph('1.5'), _WT('Original ctype_graph fails to validate a float number.')); $this->isTrue(ctype_graph('?*#'), _WT('Original ctype_graph fails to validate punctuation.')); $this->isFalse(ctype_graph("\r\n\t"), _WT('Original ctype_graph returns true for control characters.')); $this->isFalse(ctype_graph(' '), _WT('Original ctype_graph returns true for a space.')); $this->isFalse(ctype_graph(''), _WT('Original ctype_graph returns true for the empty string.')); $this->isFalse(ctype_graph(null), _WT('Original ctype_graph returns true for a null value.')); } $this->isTrue(emul_ctype_graph('fjsdiopfhsiofnuios'), _WT('Emulated ctype_graph fails to validate random letters.')); $this->isTrue(emul_ctype_graph('FELMNFKLFDSNFSKLFNSDL'), _WT('Emulated ctype_graph fails to validate random uppercase letters.')); $this->isTrue(emul_ctype_graph('0123456789azertyuiopqsdfghjklmwxcvbn'), _WT('Emulated ctype_graph fails to validate [0-9a-z].')); $this->isTrue(emul_ctype_graph('5686541641'), _WT('Emulated ctype_graph fails to validate random numbers.')); $this->isTrue(emul_ctype_graph('5A1C9B3F'), _WT('Emulated ctype_graph fails to validate random hexadecimal numbers.')); $this->isTrue(emul_ctype_graph('0123456789azertyuiopqsdfghjklmwxcvbn?'), _WT('Emulated ctype_graph fails to validate [0-9a-z?].')); $this->isTrue(emul_ctype_graph('1.5'), _WT('Emulated ctype_graph fails to validate a float number.')); $this->isTrue(emul_ctype_graph('?*#'), _WT('Emulated ctype_graph fails to validate punctuation.')); $this->isFalse(emul_ctype_graph("\r\n\t"), _WT('Emulated ctype_graph returns true for control characters.')); $this->isFalse(emul_ctype_graph(' '), _WT('Emulated ctype_graph returns true for a space.')); $this->isFalse(emul_ctype_graph(''), _WT('Emulated ctype_graph returns true for the empty string.')); $this->isFalse(emul_ctype_graph(null), _WT('Emulated ctype_graph returns true for a null value.'));
<?php // Initialization if (!defined('FORM_PATH')) { define('FORM_PATH', dirname(__FILE__) . '/form/'); } // Test $oForm = new weeForm('mini'); $oForm->fillErrors(array('textbox' => 'Bad')); $oForm->fillErrors(array('textbox' => 'Good')); $this->isMatching('/Good/', $oForm->toString(), _WT("The value given to textbox isn't in the generated form."));
<?php try { new weePgSQLResult(fopen('php://memory', 'r')); $this->fail(_WT('weePgSQLResult should throw an InvalidArgumentException when the given resource is not a pgsql result.')); } catch (InvalidArgumentException $e) { }
<?php class basic_c { } class basic_c_bad_bad_bad { } $o = new basic_c(); $this->isNotInstanceOf($o, 'basic_c_bad_bad_bad', _WT('$o instanceof basic_c_bad_bad_bad?'));
<?php // encoding: utf-8 $o = new weeXHTMLEncoder(); // weeXHTMLEncoder::encode $this->isEqual('win', $o->encode('win'), _WT('weeXHTMLEncoder::encode should return its argument untouched if it does not contain any special character.')); $this->isEqual("Time to say 'night.", $o->encode("Time to say 'night."), _WT("weeXHTMLEncoder::encode should return any single quote character untouched.")); $this->isEqual('">_>" & "<_<" & "è_é"', $o->encode('">_>" & "<_<" & "è_é"'), _WT('weeXHTMLEncoder::encode should return the expected encoded value.')); $this->isEqual('東方妖々夢', $o->encode('東方妖々夢'), _WT('weeXHTMLEncoder::encode should not encode Unicode characters.')); // weeXHTMLEncoder::decode $this->isEqual('win', $o->decode('win'), _WT('weeXHTMLEncoder::decode should return its argument untouched if it does not contain any XHTML entity.')); $this->isEqual('">_>" & "<_<" & "è_é"', $o->decode('">_>" & "<_<" & "è_é"'), _WT('weeXHTMLEncoder::decode should return the expected decoded value.'));
$this->isTrue(weeNumberValidator::test('0', array('format' => 'float')), _WT('weeNumberValidator fails to validate the string "0" when it should validate both integer and float.')); $this->isTrue(weeNumberValidator::test('0.0', array('format' => 'float')), _WT('weeNumberValidator fails to validate the string "0.0" when it should validate both integer and float.')); $this->isTrue(weeNumberValidator::test('1', array('format' => 'float')), _WT('weeNumberValidator fails to validate the string "1" when it should validate both integer and float.')); $this->isTrue(weeNumberValidator::test('1.1', array('format' => 'float')), _WT('weeNumberValidator fails to validate the string "1.1" when it should validate both integer and float.')); $this->isFalse(weeNumberValidator::test('1.1.1', array('format' => 'float')), _WT('weeNumberValidator returns true for the string "1.1.1".')); // Bad values $this->isFalse(weeNumberValidator::test(''), _WT('weeNumberValidator returns true for the empty string.')); $this->isFalse(weeNumberValidator::test('32f'), _WT('weeNumberValidator returns true for the string "32f".')); $this->isFalse(weeNumberValidator::test('xxx'), _WT('weeNumberValidator returns true for the string "xxx".')); // Integer min/max $this->isTrue(weeNumberValidator::test(0, array('min' => -10)), _WT('weeNumberValidator fails to validate 0 >= -10.')); $this->isFalse(weeNumberValidator::test(0, array('min' => 10)), _WT('weeNumberValidator returns true for 0 >= 10.')); $this->isTrue(weeNumberValidator::test(0, array('max' => 10)), _WT('weeNumberValidator fails to validate 0 <= 10.')); $this->isFalse(weeNumberValidator::test(0, array('max' => -10)), _WT('weeNumberValidator returns true for 0 <= -10.')); // Float min/max $this->isTrue(weeNumberValidator::test(1.1, array('format' => 'float', 'min' => 0)), _WT('weeNumberValidator fails to validate 1.1 >= 0.')); $this->isFalse(weeNumberValidator::test(1.1, array('format' => 'float', 'min' => 2)), _WT('weeNumberValidator returns true for 1.1 >= 2.')); $this->isFalse(weeNumberValidator::test(1.1, array('format' => 'float', 'max' => 0)), _WT('weeNumberValidator returns true for 1.1 <= 0.')); $this->isTrue(weeNumberValidator::test(1.1, array('format' => 'float', 'max' => 2)), _WT('weeNumberValidator fails to validate 1.1 <= 2.')); $this->isTrue(weeNumberValidator::test(1.1, array('format' => 'float', 'min' => 1.0)), _WT('weeNumberValidator fails to validate 1.1 >= 1.0.')); $this->isFalse(weeNumberValidator::test(1.1, array('format' => 'float', 'min' => 1.2)), _WT('weeNumberValidator returns true for 1.1 >= 1.2.')); $this->isFalse(weeNumberValidator::test(1.1, array('format' => 'float', 'max' => 1.0)), _WT('weeNumberValidator returns true for 1.1 <= 1.0.')); $this->isTrue(weeNumberValidator::test(1.1, array('format' => 'float', 'max' => 1.2)), _WT('weeNumberValidator fails to validate 1.1 <= 1.2.')); // The value is outside the range. $this->isFalse(weeNumberValidator::test(42, array('min' => 43, 'max' => 44)), _WT('weeNumberValidator should return false if the value is under the range of the `min` and `max` arguments.')); $this->isFalse(weeNumberValidator::test(42, array('min' => 40, 'max' => 41)), _WT('weeNumberValidator should return false if the value is over the range of the `min` and `max` arguments.')); $this->isTrue(weeNumberValidator::test(42, array('min' => 41, 'max' => 43)), _WT('weeNumberValidator should return true if the value is in the range of the `min` and `max` arguments.')); // Objects $this->isTrue(weeNumberValidator::test(new weeDummyPrintable('42')), _WT('weeNumberValidator::test should return true when the value is an instance of Printable which returns a valid number.')); $this->isTrue(weeNumberValidator::test(new CastableInput_testNumberValidator()), _WT('weeNumberValidator::test should return true when the value is an object castable to string which casts to a valid number.'));
<?php require_once 'init.php.inc'; if (function_exists('ctype_alpha')) { $this->isTrue(ctype_alpha('fjsdiopfhsiofnuios'), _WT('Original ctype_alpha fails to validate random letters.')); $this->isTrue(ctype_alpha('FELMNFKLFDSNFSKLFNSDL'), _WT('Original ctype_alpha fails to validate random uppercase letters.')); $this->isFalse(ctype_alpha('0123456789azertyuiopqsdfghjklmwxcvbn'), _WT('Original ctype_alpha returns true for [0-9a-z].')); $this->isFalse(ctype_alpha('5686541641'), _WT('Original ctype_alpha returns true for random numbers.')); $this->isFalse(ctype_alpha('5A1C9B3F'), _WT('Original ctype_alpha returns true for random hexadecimal numbers.')); $this->isFalse(ctype_alpha('0123456789azertyuiopqsdfghjklmwxcvbn?'), _WT('Original ctype_alpha returns true for [0-9a-z?].')); $this->isFalse(ctype_alpha('1.5'), _WT('Original ctype_alpha returns true for a float number.')); $this->isFalse(ctype_alpha('?*#'), _WT('Original ctype_alpha returns true for punctuation.')); $this->isFalse(ctype_alpha("\r\n\t"), _WT('Original ctype_alpha returns true for control characters.')); $this->isFalse(ctype_alpha(' '), _WT('Original ctype_alpha returns true for a space.')); $this->isFalse(ctype_alpha(''), _WT('Original ctype_alpha returns true for the empty string.')); $this->isFalse(ctype_alpha(null), _WT('Original ctype_alpha returns true for a null value.')); } $this->isTrue(emul_ctype_alpha('fjsdiopfhsiofnuios'), _WT('Emulated ctype_alpha fails to validate random letters.')); $this->isTrue(emul_ctype_alpha('FELMNFKLFDSNFSKLFNSDL'), _WT('Emulated ctype_alpha fails to validate random uppercase letters.')); $this->isFalse(emul_ctype_alpha('0123456789azertyuiopqsdfghjklmwxcvbn'), _WT('Emulated ctype_alpha returns true for [0-9a-z].')); $this->isFalse(emul_ctype_alpha('5686541641'), _WT('Emulated ctype_alpha returns true for random numbers.')); $this->isFalse(emul_ctype_alpha('5A1C9B3F'), _WT('Emulated ctype_alpha returns true for random hexadecimal numbers.')); $this->isFalse(emul_ctype_alpha('0123456789azertyuiopqsdfghjklmwxcvbn?'), _WT('Emulated ctype_alpha returns true for [0-9a-z?].')); $this->isFalse(emul_ctype_alpha('1.5'), _WT('Emulated ctype_alpha returns true for a float number.')); $this->isFalse(emul_ctype_alpha('?*#'), _WT('Emulated ctype_alpha returns true for punctuation.')); $this->isFalse(emul_ctype_alpha("\r\n\t"), _WT('Emulated ctype_alpha returns true for control characters.')); $this->isFalse(emul_ctype_alpha(' '), _WT('Emulated ctype_alpha returns true for a space.')); $this->isFalse(emul_ctype_alpha(''), _WT('Emulated ctype_alpha returns true for the empty string.')); $this->isFalse(emul_ctype_alpha(null), _WT('Emulated ctype_alpha returns true for a null value.'));
} setlocale(LC_NUMERIC, $sFormerLocale); if (isset($oException)) { throw $oException; } $this->isEqual("'that''s all folks!'", $oDb->escape("that's all folks!"), _WT('Escaping of the string "that\'s all folks" is wrong.')); $this->isEqual('null', $oDb->escape(null), _WT('null is not properly escaped.')); try { $this->isEqual("'1'", $oDb->escape(true), _WT('weePgSQLDatabase::escape does not correctly escape true values.')); $this->isEqual("'0'", $oDb->escape(false), _WT('weePgSQLDatabase::escape does not correctly escape false values.')); } catch (ErrorException $e) { $this->fail(_WT('weePgSQLDatabase::escape should not trigger an error when trying to escape boolean values.')); } // Test the method weePgSQLDatabase::escapeIdent $this->isEqual('"egg"', $oDb->escapeIdent('egg'), _WT('escapeIdent does not properly escape the identifier "egg".')); $this->isEqual('"that""s all folks!"', $oDb->escapeIdent('that"s all folks!'), _WT('escapeIdent does not properly escape the identifier \'that"s all folks!\'.')); try { $oDb->escapeIdent(''); $this->fail(_WT('escapeIdent does not throw an InvalidArgumentException when the identifier is empty.')); } catch (InvalidArgumentException $e) { } try { $oDb->escapeIdent(""); $this->fail(_WT('escapeIdent does not throw an InvalidArgumentException when the identifier contains a NUL character.')); } catch (InvalidArgumentException $e) { } try { $oDb->escapeIdent(str_repeat('w', 64)); $this->fail(_WT('escapeIdent does not throw an InvalidArgumentException when the identifier is longer than 63 characters.')); } catch (InvalidArgumentException $e) { }
/** Hash a password in order to store it client-side. @param $sPassword Password to be hashed. @return string Hashed password. */ public function hash($sPassword) { defined('MAGIC_STRING') or burn('IllegalStateException', _WT('You cannot hash a password without defining the MAGIC_STRING constant first.')); $sFunc = $this->aParams['hash_treatment']; return $sFunc($sFunc($sPassword) . MAGIC_STRING); }