<?php

use Codeception\Util\Stub;

/**
 * Verifies that the Cii methods work as intended
 * @todo: Move to cii repository, and have codeception run tests from other paths as well
 */
class CiiUtilityTest extends \Codeception\TestCase\Test
{
   /** 
    * @var \CodeDev
    */
    protected $codeDev;


	public function testEncryptDecrypt()
	{
		$this->assertEquals(Cii::decrypt(Cii::encrypt(1)), 1);		// Integer
		$this->assertEquals(Cii::decrypt(Cii::encrypt("1")), "1"); // String integer
		$this->assertEquals(Cii::decrypt(Cii::encrypt(3.14)), 3.14);		// Float
		$this->assertEquals(Cii::decrypt(Cii::encrypt("3.14")), "3.14");		// String float
		$this->assertEquals(Cii::decrypt(Cii::encrypt("string")), "string"); // String
	
		// Test a variety of hashes of various sizes generated by Cii::generateSafeHash()
		$hash1 = Cii::generateSafeHash(4);
		$this->assertEquals(Cii::decrypt(Cii::encrypt($hash1)), $hash1);
		$hash2 = Cii::generateSafeHash(16);
		$this->assertEquals(Cii::decrypt(Cii::encrypt($hash2)), $hash2);
		$hash3 = Cii::generateSafeHash(32);
		$this->assertEquals(Cii::decrypt(Cii::encrypt($hash3)), $hash3);
		$hash4 = Cii::generateSafeHash(64);
		$this->assertEquals(Cii::decrypt(Cii::encrypt($hash4)), $hash4);
		$hash5 = Cii::generateSafeHash(128);
		$this->assertEquals(Cii::decrypt(Cii::encrypt($hash5)), $hash5);
		$hash6 = Cii::generateSafeHash(256);
		$this->assertEquals(Cii::decrypt(Cii::encrypt($hash6)), $hash6);
		$hash7 = Cii::generateSafeHash(512);
		$this->assertEquals(Cii::decrypt(Cii::encrypt($hash7)), $hash7);
	}
}
