PHP-NumberBaseCrypt/tests/test.class.NumberBaseCryptC...

79 lines
3.6 KiB
PHP

<?php
namespace Tests\AppBundle;
include_once __DIR__.'/../vendor/autoload.php';
require_once __DIR__.'/../src/class.NumberBaseCrypt.php';
require_once __DIR__.'/../src/class.NumberBaseCryptCollection.php';
use PHPUnit\Framework\TestCase;
class test extends TestCase {
// Full Circle simple data collection test
public function testFullCircleDataCollectionSimple() {
$data = [1337,1338,11111,141415,12,5];
$numberBaseCryptCollection = new \NAE\Crypt\NumberBaseCryptCollection([
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
'a', 'b', 'c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'
]);
foreach($data as $value) {
$numberBaseCryptCollection->addData($value);
}
$dataCollection = $numberBaseCryptCollection->render();
$digits = $numberBaseCryptCollection->getDigits();
$reverse = $numberBaseCryptCollection->decrypt($dataCollection, $digits);
$this->assertEquals($data, $reverse);
}
// test correct data is stored in the collection
public function testDataStorages() {
$data = [1337,1338,11111,141415,12,5];
$numberBaseCryptCollection = new \NAE\Crypt\NumberBaseCryptCollection([
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
'a', 'b', 'c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'
]);
foreach($data as $value) {
$numberBaseCryptCollection->addData($value);
}
$this->assertEquals($data, $numberBaseCryptCollection->getPlainData());
}
// Full Circle simple data collection test with a single element
public function testFullCircleDataCollectionComplexSingle() {
$data = [1337];
$numberBaseCryptCollection = new \NAE\Crypt\NumberBaseCryptCollection([
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
'a', 'b', 'c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'
]);
foreach($data as $value) {
$numberBaseCryptCollection->addData($value);
}
$dataCollection = $numberBaseCryptCollection->render();
$digits = $numberBaseCryptCollection->getDigitList();
$reverse = $numberBaseCryptCollection->decryptComplex($dataCollection, $digits);
$this->assertEquals($data, $reverse);
}
// Full Circle simple data collection test with multiple elements
public function testFullCircleDataCollectionComplexMulti() {
$data = [1337,1338,11111,141415,12,5];
$numberBaseCryptCollection = new \NAE\Crypt\NumberBaseCryptCollection([
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
'a', 'b', 'c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'
]);
foreach($data as $value) {
$numberBaseCryptCollection->addData($value);
}
$dataCollection = $numberBaseCryptCollection->render();
$digits = $numberBaseCryptCollection->getDigitList();
$reverse = $numberBaseCryptCollection->decryptComplex($dataCollection, $digits);
$this->assertEquals($data, $reverse);
}
}