assertEquals(20, strlen($str1)); $str2 = p3k\random_string(20); $this->assertEquals(20, strlen($str2)); $this->assertNotEquals($str1, $str2); } public function testEndsWith() { $this->assertFalse(p3k\str_ends_with('abcdefg', '')); $this->assertFalse(p3k\str_ends_with('', 'abcdefg')); $this->assertTrue(p3k\str_ends_with('abcdefg', 'efg')); $this->assertTrue(p3k\str_ends_with('abcdefg', 'abcdefg')); $this->assertTrue(p3k\str_ends_with('abcdefg', 'g')); $this->assertFalse(p3k\str_ends_with('abcdefg', 'abc')); } public function testSessionSetupNoCreate() { // no session already, so this should not create one p3k\session_setup(); $this->assertFalse(isset($_SESSION)); } public function testSessionSetupCreateFromCookie() { // there is a session cookie, so this should initialize the session $_COOKIE[session_name()] = '12345'; p3k\session_setup(); $this->assertTrue(isset($_SESSION)); } public function testSessionAccess() { $_SESSION = []; $this->assertNull(p3k\session('foo')); $_SESSION = []; $this->assertEquals('default', p3k\session('foo', 'default')); $_SESSION = ['foo'=>'bar']; $this->assertEquals('bar', p3k\session('foo')); } public function testFlash() { $_SESSION = []; $this->assertNull(p3k\flash('foo')); $_SESSION = ['foo'=>'bar']; $this->assertEquals('bar', p3k\flash('foo')); $this->assertNull(p3k\flash('foo')); } public function testE() { $html = p3k\e('test'); $this->assertEquals('<b>test</b>', $html); } public function testK() { $this->assertEquals('b', p3k\k(['a'=>'b'], 'a')); $this->assertEquals('default', p3k\k(['a'=>'b'], 'z', 'default')); $obj = new StdClass; $obj->a = 'b'; $this->assertEquals('b', p3k\k($obj, 'a')); $this->assertEquals('default', p3k\k($obj, 'z', 'default')); $keys = ['a','b','c']; $values = ['a'=>true, 'b'=>true, 'c'=>true]; $this->assertTrue(p3k\k($values, $keys)); $keys = ['a','b','c']; $values = ['a'=>true, 'c'=>true]; $this->assertFalse(p3k\k($values, $keys)); } public function testHTTPHeaderCase() { $name = p3k\http_header_case('header-name'); $this->assertEquals('Header-Name', $name); $name = p3k\http_header_case('HEADER-NAME'); $this->assertEquals('Header-Name', $name); $name = p3k\http_header_case('hEaDeR-nAmE'); $this->assertEquals('Header-Name', $name); $name = p3k\http_header_case('host'); $this->assertEquals('Host', $name); $name = p3k\http_header_case('x-header-name'); $this->assertEquals('X-Header-Name', $name); } public function testHTMLToDomDocument() { $doc = p3k\html_to_dom_document('