Commit 0eb47a8b authored by Carsten  Rose's avatar Carsten Rose
Browse files

Evaluate, Sip, Store; new unittests

parent 3680f11f
...@@ -144,9 +144,10 @@ class EvaluateTest extends AbstractDatabaseTest { ...@@ -144,9 +144,10 @@ class EvaluateTest extends AbstractDatabaseTest {
protected function setUp() { protected function setUp() {
$this->store = Store::getInstance('form=TestFormName'); $this->store = Store::getInstance('form=TestFormName', true);
parent::setUp(); parent::setUp();
$this->store->setVar('form', 'TestFormName', STORE_TYPO3);
$this->executeSQLFile(__DIR__ . '/fixtures/Generic.sql', true); $this->executeSQLFile(__DIR__ . '/fixtures/Generic.sql', true);
} }
......
...@@ -21,41 +21,41 @@ class SipTest extends \PHPUnit_Framework_TestCase { ...@@ -21,41 +21,41 @@ class SipTest extends \PHPUnit_Framework_TestCase {
$sip = new Sip('fakesessionname', true); $sip = new Sip('fakesessionname', true);
$sip->sipUniqId('badcaffee1234'); $sip->sipUniqId('badcaffee1234');
$result = $sip->urlParamToSip("http://example.com/index.php?id=input&r=1&form=person", RETURN_URL); $result = $sip->queryStringToSip("http://example.com/index.php?id=input&r=1&form=person", RETURN_URL);
$this->assertEquals('http://example.com/index.php?id=input&s=badcaffee1234', $result); $this->assertEquals('http://example.com/index.php?id=input&s=badcaffee1234', $result);
$result = $sip->urlParamToSip("http://example.com/index.php?id=input&r=1&form=person"); $result = $sip->queryStringToSip("http://example.com/index.php?id=input&r=1&form=person");
$this->assertEquals('http://example.com/index.php?id=input&s=badcaffee1234', $result); $this->assertEquals('http://example.com/index.php?id=input&s=badcaffee1234', $result);
$result = $sip->urlParamToSip("index.php?id=input&r=1&form=person", RETURN_URL); $result = $sip->queryStringToSip("index.php?id=input&r=1&form=person", RETURN_URL);
$this->assertEquals('index.php?id=input&s=badcaffee1234', $result); $this->assertEquals('index.php?id=input&s=badcaffee1234', $result);
$result = $sip->urlParamToSip("?id=input&r=1&form=person", RETURN_URL); $result = $sip->queryStringToSip("?id=input&r=1&form=person", RETURN_URL);
$this->assertEquals('?id=input&s=badcaffee1234', $result); $this->assertEquals('?id=input&s=badcaffee1234', $result);
$result = $sip->urlParamToSip("id=input&r=1&form=person", RETURN_URL); $result = $sip->queryStringToSip("id=input&r=1&form=person", RETURN_URL);
$this->assertEquals('?id=input&s=badcaffee1234', $result); $this->assertEquals('?id=input&s=badcaffee1234', $result);
$result = $sip->urlParamToSip("input&r=1&form=person", RETURN_URL); $result = $sip->queryStringToSip("input&r=1&form=person", RETURN_URL);
$this->assertEquals('?id=input&s=badcaffee1234', $result); $this->assertEquals('?id=input&s=badcaffee1234', $result);
$result = $sip->urlParamToSip("id=input&r=1&form=person&keySemId=23", RETURN_URL); $result = $sip->queryStringToSip("id=input&r=1&form=person&keySemId=23", RETURN_URL);
$this->assertEquals('?id=input&s=badcaffee1234', $result); $this->assertEquals('?id=input&s=badcaffee1234', $result);
$result = $sip->urlParamToSip("id=input&r=1&form=person&type=99", RETURN_URL); $result = $sip->queryStringToSip("id=input&r=1&form=person&type=99", RETURN_URL);
$this->assertEquals('?id=input&type=99&s=badcaffee1234', $result); $this->assertEquals('?id=input&type=99&s=badcaffee1234', $result);
$result = $sip->urlParamToSip("id=input&r=1&form=person&L=1", RETURN_URL); $result = $sip->queryStringToSip("id=input&r=1&form=person&L=1", RETURN_URL);
$this->assertEquals('?id=input&L=1&s=badcaffee1234', $result); $this->assertEquals('?id=input&L=1&s=badcaffee1234', $result);
$result = $sip->urlParamToSip("id=input&r=1&L=2&form=person&type=99", RETURN_URL); $result = $sip->queryStringToSip("id=input&r=1&L=2&form=person&type=99", RETURN_URL);
$this->assertEquals('?id=input&L=2&type=99&s=badcaffee1234', $result); $this->assertEquals('?id=input&L=2&type=99&s=badcaffee1234', $result);
$result = $sip->urlParamToSip("id=input&r=1&L=2&form=person&type=99", RETURN_SIP); $result = $sip->queryStringToSip("id=input&r=1&L=2&form=person&type=99", RETURN_SIP);
$this->assertEquals('badcaffee1234', $result); $this->assertEquals('badcaffee1234', $result);
$sip->sipUniqId('badcaffee0000'); $sip->sipUniqId('badcaffee0000');
$result = $sip->urlParamToSip("id=input&r=10&L=2&form=person&type=99", RETURN_SIP); $result = $sip->queryStringToSip("id=input&r=10&L=2&form=person&type=99", RETURN_SIP);
$this->assertEquals('badcaffee0000', $result); $this->assertEquals('badcaffee0000', $result);
} }
...@@ -64,12 +64,12 @@ class SipTest extends \PHPUnit_Framework_TestCase { ...@@ -64,12 +64,12 @@ class SipTest extends \PHPUnit_Framework_TestCase {
$sip = new Sip('fakesessionname', true); $sip = new Sip('fakesessionname', true);
$sip->sipUniqId('badcaffee1234'); $sip->sipUniqId('badcaffee1234');
$sip2 = $sip->urlParamToSip("http://example.com/index.php?a=1&b=2&c=3", RETURN_SIP); $sip2 = $sip->queryStringToSip("http://example.com/index.php?a=1&b=2&c=3", RETURN_SIP);
$arr = $sip->getVarsFromSip($sip2); $arr = $sip->getVarsFromSip($sip2);
$this->assertEquals(['a' => 1, 'b' => 2, 'c' => 3], $arr); $this->assertEquals(['a' => 1, 'b' => 2, 'c' => 3], $arr);
$this->assertEquals('badcaffee1234', $sip2); $this->assertEquals('badcaffee1234', $sip2);
$sip2 = $sip->urlParamToSip("http://example.com/index.php?e=1&f=2&g=3", RETURN_SIP); $sip2 = $sip->queryStringToSip("http://example.com/index.php?e=1&f=2&g=3", RETURN_SIP);
$arr = $sip->getVarsFromSip($sip2); $arr = $sip->getVarsFromSip($sip2);
$this->assertEquals(['e' => 1, 'f' => 2, 'g' => 3], $arr); $this->assertEquals(['e' => 1, 'f' => 2, 'g' => 3], $arr);
$this->assertEquals('badcaffee1234', $sip2); $this->assertEquals('badcaffee1234', $sip2);
...@@ -78,12 +78,12 @@ class SipTest extends \PHPUnit_Framework_TestCase { ...@@ -78,12 +78,12 @@ class SipTest extends \PHPUnit_Framework_TestCase {
$sip2 = $sip->sipUniqId(); $sip2 = $sip->sipUniqId();
$this->assertEquals('badcaffee0000', $sip2); $this->assertEquals('badcaffee0000', $sip2);
$sip2 = $sip->urlParamToSip("http://example.com/index.php?aa=hello&bb=world", RETURN_SIP); $sip2 = $sip->queryStringToSip("http://example.com/index.php?aa=hello&bb=world", RETURN_SIP);
$arr = $sip->getVarsFromSip($sip2); $arr = $sip->getVarsFromSip($sip2);
$this->assertEquals(['aa' => 'hello', 'bb' => 'world'], $arr); $this->assertEquals(['aa' => 'hello', 'bb' => 'world'], $arr);
$this->assertEquals('badcaffee0000', $sip2); $this->assertEquals('badcaffee0000', $sip2);
$sip2 = $sip->urlParamToSip("aaa=Don&bbb=John", RETURN_SIP); $sip2 = $sip->queryStringToSip("aaa=Don&bbb=John", RETURN_SIP);
$arr = $sip->getVarsFromSip($sip2); $arr = $sip->getVarsFromSip($sip2);
$this->assertEquals(['aaa' => 'Don', 'bbb' => 'John'], $arr); $this->assertEquals(['aaa' => 'Don', 'bbb' => 'John'], $arr);
...@@ -94,16 +94,16 @@ class SipTest extends \PHPUnit_Framework_TestCase { ...@@ -94,16 +94,16 @@ class SipTest extends \PHPUnit_Framework_TestCase {
$sip = new Sip('fakesessionname', true); $sip = new Sip('fakesessionname', true);
$sip->sipUniqId('badcaffee1234'); $sip->sipUniqId('badcaffee1234');
$result = $sip->urlParamToSip("http://example.com/index.php?id=input&r=1&form=person", RETURN_URL); $result = $sip->queryStringToSip("http://example.com/index.php?id=input&r=1&form=person", RETURN_URL);
$s = $sip->getSipFromUrlParam('form=person&r=1'); $s = $sip->getSipFromQueryString('form=person&r=1');
$this->assertEquals('badcaffee1234', $s); $this->assertEquals('badcaffee1234', $s);
$s = $sip->getSipFromUrlParam('UnknwonParameter=1234'); $s = $sip->getSipFromQueryString('UnknwonParameter=1234');
$this->assertFalse($s); $this->assertFalse($s);
$sip->sipUniqId('badcaffee1111'); $sip->sipUniqId('badcaffee1111');
$url = $sip->urlParamToSip("a=1&b=2&c=3", RETURN_SIP); $url = $sip->queryStringToSip("a=1&b=2&c=3", RETURN_SIP);
$s = $sip->getSipFromUrlParam('a=1&b=2&c=3'); $s = $sip->getSipFromQueryString('a=1&b=2&c=3');
$this->assertEquals('badcaffee1111', $s); $this->assertEquals('badcaffee1111', $s);
} }
...@@ -114,7 +114,15 @@ class SipTest extends \PHPUnit_Framework_TestCase { ...@@ -114,7 +114,15 @@ class SipTest extends \PHPUnit_Framework_TestCase {
$s = $sip->sipUniqId('badcaffee1234'); $s = $sip->sipUniqId('badcaffee1234');
$this->assertEquals('badcaffee1234', $s); $this->assertEquals('badcaffee1234', $s);
} }
public function testGetQueryStringFromSip() {
$sip = new Sip('fakesessionname', true);
$sip->sipUniqId('badcaffee1234');
$s = $sip->queryStringToSip("http://example.com/index.php?id=input&r=1&form=person", RETURN_SIP);
$result = $sip->getQueryStringFromSip($s);
$this->assertEquals('form=person&r=1', $result);
}
} }
...@@ -88,7 +88,7 @@ class StoreTest extends \PHPUnit_Framework_TestCase { ...@@ -88,7 +88,7 @@ class StoreTest extends \PHPUnit_Framework_TestCase {
public function testGetVarStoreClient() { public function testGetVarStoreClient() {
//TODO: CR: phpunit running _all_ tests, fails with this tests always. Found no way to debug the situation. //TODO: CR: phpunit running _all_ tests, fails with this tests always. Found no way to debug the situation.
return; return;
# Violates SANATIZE class: sanatized string is always an empty string. # Violates SANATIZE class: sanatized string is always an empty string.
# Access are cached: # Access are cached:
...@@ -156,7 +156,33 @@ return; ...@@ -156,7 +156,33 @@ return;
//default prio FSRD //default prio FSRD
$this->assertEquals(0, $this->store->getVar('fakename', '', STORE_ZERO), "Retrieve anything from STORE_ZERO"); $this->assertEquals(0, $this->store->getVar('fakename', '', STORE_ZERO), "Retrieve anything from STORE_ZERO");
}
public function testUnsetStore() {
$this->store->unsetStore(STORE_RECORD);
$this->store->setVarArray(array(), STORE_RECORD);
$this->assertEquals(false, $this->store->getVar('apple', STORE_RECORD), "Retrieve a value from store.");
}
public function testSetVarArray() {
$this->store->unsetStore(STORE_RECORD);
$arr = ['a' => '1', 'apple' => 'green'];
$this->store->setVarArray($arr, STORE_RECORD);
$this->assertEquals('1', $this->store->getVar('a', STORE_RECORD), "Retrieve a value from store 'fake'");
$this->assertEquals('green', $this->store->getVar('apple', STORE_RECORD), "Retrieve a value from store.");
}
public function testSetVarArrayEmpty() {
$this->store->unsetStore(STORE_RECORD);
$arr = array();
$this->store->setVarArray($arr, STORE_RECORD);
$this->assertEquals(false, $this->store->getVar('apple', STORE_RECORD), "Retrieve a value from store.");
}
public function testGetStore() {
$this->assertEquals(array(), $this->store->getStore('unknownstore'));
} }
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment