Location: PHPKode > scripts > SPL and Iterators > spl-and-iterators/users/test.php
<?php
/**
 * TESTS
 */
DEFINE ('SQL_LOGIN', 	'root');
DEFINE ('SQL_PWD', 	'pwd');
DEFINE ('SQL_DB', 	'bdd_test');
DEFINE ('SQL_HOST',     'localhost');

require_once 'dbfactory.cls.php';
require_once 'mysql.cls.php';
require_once 'class.oUser.php';

$oDB = dbfactory::factory ('mysql', SQL_HOST, SQL_LOGIN, SQL_PWD, SQL_DB);

$fXml = 'config.xml';
try {
	$oUser = new oUser ($fXml, $oDB);
} catch (Exception $e) {
	echo $e -> getMessage ();
}

try {
	echo '<br /><strong>ALL NO VALUE</strong><br />';
	$aProps = $oUser -> getProps ();
	foreach ($aProps as $sK => $sV) {
		echo str_repeat ('---', $aProps -> getDepth ()), $sK, ' => ', $sV, '<br />';
	}

	$oUser -> EMAIL = 'hide@address.com';
	$oUser -> PASSWORD = 'mypass';
	$oUser -> ID = 666;

	echo '<br /><strong>EMAIL VALUE</strong><br />';
	echo $oUser -> EMAIL, '<br />';

	echo '<br /><strong>ALL with VALUES</strong><br />';
	$aProps = $oUser -> getProps ();
	foreach ($aProps as $sK => $sV) {
		echo str_repeat ('---', $aProps -> getDepth ()), $sK, ' => ', $sV, '<br />';
	}

	echo '<br /><strong>ONLY VALUES</strong><br />';
	$oUser -> FILTER = 'VALUE';
	$aProps = $oUser -> getProps ();
	foreach ($aProps as $sK => $sV) {
		echo $sK, ' => ', $sV, '<br />';
	}

	echo '<br /><strong>ONLY BDD_NAMES</strong><br />';
	$oUser -> FILTER = 'BDD_NAME';
	$aProps = $oUser -> getProps ();
	foreach ($aProps as $sK => $sV) {
		echo $sK, ' => ', $sV, '<br />';
	}

	echo '<br /><strong>ONLY EMAIL</strong><br />';
	$oUser -> FILTER = 'EMAIL';
	$aProps = $oUser -> getProps ();
	foreach ($aProps as $sK => $sV) {
		echo str_repeat ('---', $aProps -> getInnerIterator () -> getDepth ()), $sK, ' => ', $sV, '<br />';
	}

	echo '<br /><strong>ONLY EMAIL BDD_NAME</strong><br />';
	$oUser -> FILTER = 'BDD_NAME';
	echo $oUser -> EMAIL;

	$oUser -> FILTER = null;
	echo '<br /><br /><strong>BACK TO ALL NO FILTER</strong><br />';
	$aProps = $oUser -> getProps ();
	foreach ($aProps as $sK => $sV) {
		echo str_repeat ('---', $aProps -> getDepth ()), $sK, ' => ', $sV, '<br />';
	}

} catch (Exception $e) {
	echo $e -> getMessage ();
}

try {
	echo '<br /><strong>CHECK IDENT</strong><br />';
	$bExists = $oUser -> checkIdent ('users', array ('PASSWORD' => 'pwd', 'EMAIL' => 'hide@address.com'));
	if (false === $bExists) {
		echo '<br /><strong>NOT EXISTING : CREATING IT</strong><br />';
		$oUser -> createUser ('users', array ('PASSWORD' => 'pwd', 'EMAIL' => 'hide@address.com'));
	} else {
		echo '<br /><strong>EXISTING : getting ID</strong><br />';
		echo $oUser -> oSession -> ID;
	}
} catch (Exception $e) {
	echo $e -> getMessage ();
}

try {
	echo '<br /><strong>CHECK IDENT</strong><br />';
	$bExists = $oUser -> checkIdent ('users', array ('PASSWORD' => 'toto', 'EMAIL' => 'hide@address.com'));
	if (false === $bExists) {
		echo '<br /><strong>NOT EXISTING : CREATING IT</strong><br />';
		$oUser -> createUser ('users', array ('PASSWORD' => 'toto', 'EMAIL' => 'hide@address.com'));
	} else {
		echo '<br /><strong>EXISTING : getting ID</strong><br />';
		echo $oUser -> oSession -> ID;
	}
} catch (Exception $e) {
	echo $e -> getMessage ();
}

try {
	$oUser -> getUser (2, 'users');
	$oUser -> FILTER = null;
	echo '<br /><strong>GETTING USER 2</strong><br />';
	$aProps = $oUser -> getProps ();
	foreach ($aProps as $sK => $sV) {
		echo str_repeat ('---', $aProps -> getDepth ()), $sK, ' => ', $sV, '<br />';
	}
} catch (Exception $e) {
	echo $e -> getMessage ();
}
echo '<br /><strong>GETTING SESSION</strong><br />';
print_r ($_SESSION);
echo '<br /><br /><strong>GETTING EMAIL TYPE</strong></br>';
$oUser -> FILTER = 'TYPE';
echo $oUser -> EMAIL;

?>
Return current item: SPL and Iterators