<commit_before><?php
require_once("trail-quail.php");
require_once(dirname(__DIR__) . "/php/classes/autoload.php");


/**
 *
 * Full PHPUnit test for the User class
 *
 * This is a complete PHPUnit test of the User class. It is complete because *ALL* mySQL/PDO enabled methods are tested for both invalid and valid inputs.
 *
 * @see user.php in the classes directory
 * @author <NAME> <<EMAIL>> and Trail Quail <<EMAIL>>
 **/
class UserTest extends TrailQuailTest {
	/**
	 * valid user Id to use
	 * @var int $VALID_USERID
	 */
	protected $VALID_USERID = "27";

		/**
		 * valid user Browser type to use
		 * @var string $VALID_BROWSER
		 */
	protected $VALID_BROWSER = "Firefox";

	/**
	 * valid user account creation date to use
	 * @var datetime $VALID_CREATEDATE
	 */
	protected $VALID_CREATEDATE = "2015-11-15 09:45:30";

	/**
	 * valid user IP address to use
	 * @var string $VALID_IPADDRESS
	 */
	protected $VALID_IPADDRESS = "192.168.1.168";

	/**
	 * valid user account type to use
	 * @var string $VALID_USERACCOUNTTYPE
	 */
	protected $VALID_USERACCOUNTTYPE = "S";

	/**
	 * valid user email to use
	 * @var string $VALID_EMAIL
	 */
	protected $VALID_USEREMAIL = "<EMAIL>";

	/**
	 * valid user hash to use
	 * @var string $VALID_USERHASH
	 */
	protected $VALID_USERHASH = null;

	/**
	 * valid username to use
	 * @var string $VALID_USERNAME
	 */
	protected $VALID_USERNAME = "Yourname.tomorrow";

	/**
	 * valid user salt
	 * @var string $VALID_USERSALT
	 */
	protected $VALID_USERSALT= null;

	/**
	 * This setUp function creates user salt and user hash values for unit testing
	 * @var string $VALID_USERSALT
	 * @var string $VALID_USERHASH
	 */
	public function setUp() {
		parent::setUp();

		$this->VALID_USERSALT = bin2hex(openssl_random_pseudo_bytes(32));
		$this->VALID_USERHASH = hash_pbkdf2("sha512", "iLoveIllinois", $this->VALID_USERSALT, 262144, 128);
	}

	/**
	 * Test inserting a valid user ID information entry and verify that the actual mySQL data matches
	 */
	public function testInsertValidUser() {
		// count the number of rows and save it for later
		$numRows = $this->getConnection()->getRowCount("user");

		// create a new user information profile and insert it in the database
		$user = new User(null, $this->VALID_BROWSER, $this->VALID_CREATEDATE, $this->VALID_IPADDRESS, $this->VALID_USERACCOUNTTYPE, $this->VALID_USEREMAIL, $this->VALID_USERHASH, $this->VALID_USERNAME, $this->VALID_USERSALT);
		$user->insert($this->getPDO());

		// grab the data from mySQL and verify the fields match our expectation
		$pdoUser = User::getUserByUserId($this->getPDO(), $user->getUserId());
		$this->assertSame($numRows + 1, $this->getConnection()->getRowCount("user"));
		$this->assertSame($pdoUser->getBrowser(), $this->VALID_BROWSER);
		$this->assertSame($pdoUser->getCreateDate(), $this->VALID_CREATEDATE);
		$this->assertSame($pdoUser->getIpAddress(), $this->VALID_IPADDRESS);
		$this->assertSame($pdoUser->getUserAccountType(), $this->VALID_USERACCOUNTTYPE);
		$this->assertSame($pdoUser->getUserEmail(), $this->VALID_USEREMAIL);
		$this->assertSame($pdoUser->getUserHash(), $this->VALID_USERHASH);
		$this->assertSame($pdoUser->getUserName(), $this->VALID_USERNAME);
		$this->assertSame($pdoUser->getUserSalt(), $this->VALID_USERSALT);
	}

	/**
	 * Test inserting a user ID profile that already exists<commit_msg>https://app.asana.com/0/61036105436352/63522445646889 working on UNIT TEST for class user - trying to debug datetime-string error<commit_after><?php
require_once("trail-quail.php");
require_once(dirname(__DIR__) . "/php/classes/autoload.php");


/**
 *
 * Full PHPUnit test for the User class
 *
 * This is a complete PHPUnit test of the User class. It is complete because *ALL* mySQL/PDO enabled methods are tested for both invalid and valid inputs.
 *
 * @see user.php in the classes directory
 * @author <NAME> <<EMAIL>> and Trail Quail <<EMAIL>>
 **/
class UserTest extends TrailQuailTest {
	/**
	 * valid user Id to use
	 * @var int $VALID_USERID
	 */
	protected $VALID_USERID = "27";

		/**
		 * valid user Browser type to use
		 * @var string $VALID_BROWSER
		 */
	protected $VALID_BROWSER = "Firefox";

	/**
	 * valid user account creation date to use
	 * @var string $VALID_CREATEDATE
	 */
	protected $VALID_CREATEDATE = "2015-11-20 09:28:05";

	/**
	 * valid user IP address to use
	 * @var string $VALID_IPADDRESS
	 */
	protected $VALID_IPADDRESS = "192.168.1.168";

	/**
	 * valid user account type to use
	 * @var string $VALID_USERACCOUNTTYPE
	 */
	protected $VALID_USERACCOUNTTYPE = "S";

	/**
	 * valid user email to use
	 * @var string $VALID_EMAIL
	 */
	protected $VALID_USEREMAIL = "<EMAIL>";

	/**
	 * valid user hash to use
	 * @var string $VALID_USERHASH
	 */
	protected $VALID_USERHASH = null;

	/**
	 * valid username to use
	 * @var string $VALID_USERNAME
	 */
	protected $VALID_USERNAME = "Yourname.tomorrow";

	/**
	 * valid user salt
	 * @var string $VALID_USERSALT
	 */
	protected $VALID_USERSALT= null;

	/**
	 * This setUp function creates user salt and user hash values for unit testing
	 * @var string $VALID_USERSALT
	 * @var string $VALID_USERHASH
	 */
	public function setUp() {
		parent::setUp();

		$this->VALID_USERSALT = bin2hex(openssl_random_pseudo_bytes(32));
		$this->VALID_USERHASH = hash_pbkdf2("sha512", "iLoveIllinois", $this->VALID_USERSALT, 262144, 128);
		$this->VALID_CREATEDATE = DateTime::createFromFormat("Y-m-d H:i:s", $this->VALID_CREATEDATE);
	}

	/**
	 * Test inserting a valid user ID information entry and verify that the actual mySQL data matches
	 */
	public function testInsertValidUser() {
		// count the number of rows and save it for later
		$numRows = $this->getConnection()->getRowCount("user");
		// create a new user information profile and insert it in the database
		$user = new User(null, $this->VALID_BROWSER, $this->VALID_CREATEDATE, $this->VALID_IPADDRESS, $this->VALID_USERACCOUNTTYPE, $this->VALID_USEREMAIL, $this->VALID_USERHASH, $this->VALID_USERNAME, $this->VALID_USERSALT);
		$user->insert($this->getPDO());

		// grab the data from mySQL and verify the fields match our expectation
		$pdoUser = User::getUserByUserId($this->getPDO(), $user->getUserId());
		$this->assertSame($numRows + 1, $this->getConnection()->getRowCount("user"));
		$this->assertSame($pdoUser->getBrowser(), $this->VALID_BROWSER);
		$this->assertSame($pdoUser->getCreateDate(), $this->VALID_CREATEDATE);
		$this->assertSame($pdoUser->getIpAddress(), $this->VALID_IPADDRESS);
		$this->assertSame($pdoUser->getUserAccountType(), $this->VALID_USERACCOUNTTYPE);
		$this->assertSame($pdoUser->getUserEmail(), $this->VALID_USEREMAIL);
		$this->assertSame($pdoUser->getUserHash(), $this->VALID_USERHASH);
		$this->assertSame($pdoUser->getUserName(), $this->VALID_USERNAME);
		$this->assertSame($pdoUser->getUserSalt(), $this->VALID_USERSALT);
	}

	/**
	 * Test inserting a user ID profile that already exists
{'fraction_non_alphanumeric': 0.14207096307023895, 'fraction_numerical': 0.0166545981173063, 'mean_word_length': 4.485305798252582, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 105, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2989174', 'n_tokens_mistral': 2459, 'n_tokens_neox': 2223, 'n_words': 585}