'/^([a-zA-Z0-9_@.-]{4,})$/', ]); Config::set($testconfig); } /** * @covers Request::offsetGet */ public function testArrayAccess () { $request = Request::getInstance(); $this->assertNull($request['null']); $this->assertSame($request['a'], 'test'); $this->assertSame($request['b'], '\\h1"'); $this->assertSame($request['c'], '-23'); } /** * @covers Request::set */ public function testSetParam () { Request::set('yyy', 'xyzzy'); Request::set('zzz', [1, 2]); $this->assertSame(Request::get('yyy'), 'xyzzy'); $this->assertSame(Request::getArray('zzz'), [1, 2]); } /** * @covers Request::get */ public function testStringParam () { $this->assertNull(Request::get('null')); $this->assertSame(Request::get('null', 'foo'), 'foo'); $this->assertSame(Request::get('a'), 'test'); $this->assertSame(Request::get('b'), '\\h1"'); $this->assertSame(Request::get('c'), '-23'); $this->assertSame(Request::get('d'), '12.7'); $this->assertNull(Request::get('v2')); } /** * @covers Request::option */ public function testOptionParam () { $this->assertNull(Request::option('null')); $this->assertSame(Request::option('a'), 'test'); $this->assertNull(Request::option('b')); $this->assertNull(Request::option('v1')); } /** * @covers Request::int */ public function testIntParam () { $this->assertNull(Request::int('null')); $this->assertSame(Request::int('a'), 0); $this->assertSame(Request::int('c'), -23); $this->assertSame(Request::int('d'), 12); $this->assertSame(Request::int('e'), 3); $this->assertNull(Request::int('v1')); } /** * @covers Request::float */ public function testFloatParam () { $this->assertNull(Request::float('null')); $this->assertSame(Request::float('a'), 0.0); $this->assertSame(Request::float('c'), -23.0); $this->assertSame(Request::float('d'), 12.7); $this->assertSame(Request::float('e'), 3.14); $this->assertNull(Request::float('v1')); } /** * @covers Request::bool */ public function testBoolParam () { $this->assertNull(Request::bool('null')); $this->assertTrue(Request::bool('a')); $this->assertTrue(Request::bool('c')); $this->assertTrue(Request::bool('d')); $this->assertTrue(Request::bool('e')); $this->assertTrue(Request::bool('g')); $this->assertFalse(Request::bool('h')); $this->assertFalse(Request::bool('s_x')); $this->assertNull(Request::bool('v1')); } /** * @covers Request::username */ public function testUsernameParam () { $this->assertNull(Request::username('null')); $this->assertSame(Request::username('a'), 'test'); $this->assertSame(Request::username('f'), 'root@studip'); $this->assertNull(Request::username('b')); $this->assertNull(Request::username('v1')); } /** * @covers Request::getArray */ public function testStringArrayParam () { $this->assertSame(Request::getArray('null'), []); $this->assertSame(Request::getArray('b'), []); $this->assertSame(Request::getArray('v1'), ['1', '2.4', '3,7']); $this->assertSame(Request::getArray('v2'), ['on\'e', 'two', 'thr33']); } /** * @covers Request::optionArray */ public function testOptionArrayParam () { $this->assertSame(Request::optionArray('null'), []); $this->assertSame(Request::optionArray('a'), []); $this->assertSame(Request::optionArray('v1'), ['1']); $this->assertSame(Request::optionArray('v2'), [1 => 'two', 2 => 'thr33']); } /** * @covers Request::intArray */ public function testIntArrayParam () { $this->assertSame(Request::intArray('null'), []); $this->assertSame(Request::intArray('c'), []); $this->assertSame(Request::intArray('v1'), [1, 2, 3]); $this->assertSame(Request::intArray('v2'), [0, 0, 0]); } /** * @covers Request::floatArray */ public function testFloatArrayParam () { $this->assertSame(Request::floatArray('null'), []); $this->assertSame(Request::floatArray('c'), []); $this->assertSame(Request::floatArray('v1'), [1.0, 2.4, 3.7]); $this->assertSame(Request::floatArray('v2'), [0.0, 0.0, 0.0]); } /** * @covers Request::boolArray */ public function testBoolArrayParam () { $this->assertSame(Request::boolArray('null'), []); $this->assertSame(Request::boolArray('c'), []); $this->assertSame(Request::boolArray('v4'), [false, true, false, true]); } /** * @covers Request::usernameArray */ public function testUsernameArrayParam () { $this->assertSame(Request::usernameArray('null'), []); $this->assertSame(Request::usernameArray('a'), []); $this->assertSame(Request::usernameArray('v1'), []); $this->assertSame(Request::usernameArray('v2'), [2 => 'thr33']); $this->assertSame(Request::usernameArray('v3'), ['root@studip', 'hotte.testfreund']); } /** * @covers Request::submitted */ public function testSubmitted () { $this->assertFalse(Request::submitted('null')); $this->assertTrue(Request::submitted('s')); $this->assertTrue(Request::submitted('v1')); } /** * @covers Request::submittedSome */ public function testSubmittedSome () { $this->assertFalse(Request::submittedSome('null', 'null')); $this->assertTrue(Request::submittedSome('null', 's', 'v')); } /** * @covers Request::getDateTime */ public function testGetDatetimeWithDate() { $date = Request::getDateTime(); $this->assertNotFalse($date); $this->assertEquals('2025-03-25 00:00:00', $date->format('Y-m-d H:i:s')); } /** * @covers Request::getDateTime */ public function testGetDatetimeWithDateAndTime() { $datetime = Request::getDateTime('datetime', 'Y-m-d H:i:s'); $this->assertNotFalse($datetime); $this->assertEquals('2025-03-25 17:39:04', $datetime->format('Y-m-d H:i:s')); } /** * @covers Request::getDateTime */ public function testGetDatetimeWithDateAndTimeInTwoParameters() { $date = Request::getDateTime('date', 'Y-m-d', 'time', 'H:i:s'); $this->assertNotFalse($date); $this->assertEquals('2025-03-25 17:39:04', $date->format('Y-m-d H:i:s')); } /** * @covers Request::getDateTime */ public function testGetDatetimeWithInvalidDate() { $invalid_date = Request::getDateTime('invalid_date'); $this->assertFalse($invalid_date); } /** * @covers Request::i18n */ public function testRequestI18n() { $i18n = Request::i18n('localized'); $this->assertEquals('abc', $i18n->original()); $this->assertEquals('def', $i18n->localized('en_GB')); $this->assertNull($i18n->localized('no_LANG')); } /** * @covers Request::i18n */ public function testRequestI18nWithDefault() { $default = new I18NString('foo', ['en_GB' => 'bar']); $i18n = Request::i18n('unknown', $default); $this->assertEquals('foo', $i18n->original()); $this->assertEquals('bar', $i18n->localized('en_GB')); } public function tearDown(): void { Config::set(null); } }