From c779293fb79e6d2a16d474cd19dce866615f3b9c Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 24 Jan 2023 03:13:31 +0100 Subject: [PATCH] tests: uses new session api --- tests/Http/Session.handler.phpt | 4 +-- tests/Http/Session.id.phpt | 2 +- ...regenerate-empty-session-readAndClose.phpt | 2 +- .../Session.regenerate-empty-session.phpt | 2 +- .../Session.restart-after-regenerate.phpt | 4 +-- tests/Http/Session.sections.phpt | 4 +-- tests/Http/SessionSection.basic.phpt | 23 ++++++--------- tests/Http/SessionSection.remove.phpt | 28 ------------------- .../SessionSection.removeExpiration().phpt | 4 +-- tests/Http/SessionSection.separated.phpt | 28 ++++++++++--------- .../Http/SessionSection.setExpiration().phpt | 12 ++++---- tests/Http/SessionSection.undefined.phpt | 20 ------------- tests/Http/Url.httpScheme.phpt | 3 -- 13 files changed, 40 insertions(+), 96 deletions(-) delete mode 100644 tests/Http/SessionSection.remove.phpt delete mode 100644 tests/Http/SessionSection.undefined.phpt diff --git a/tests/Http/Session.handler.phpt b/tests/Http/Session.handler.phpt index 5f979703..2f78a6e6 100644 --- a/tests/Http/Session.handler.phpt +++ b/tests/Http/Session.handler.phpt @@ -73,10 +73,10 @@ $session->setHandler(new MySessionStorage); $session->start(); $namespace = $session->getSection('one'); -$namespace->a = 'apple'; +$namespace->set('a', 'apple'); $session->close(); unset($_SESSION); $session->start(); $namespace = $session->getSection('one'); -Assert::same('apple', $namespace->a); +Assert::same('apple', $namespace->get('a')); diff --git a/tests/Http/Session.id.phpt b/tests/Http/Session.id.phpt index 90faf27c..89cb2363 100644 --- a/tests/Http/Session.id.phpt +++ b/tests/Http/Session.id.phpt @@ -25,7 +25,7 @@ $session->start(); Assert::same($sessionId, $session->getId()); Assert::same([$sessionName => $leet], $_COOKIE); -Assert::same('yes', $session->getSection('temp')->value); +Assert::same('yes', $session->getSection('temp')->get('value')); $session->close(); // session was not regenerated diff --git a/tests/Http/Session.regenerate-empty-session-readAndClose.phpt b/tests/Http/Session.regenerate-empty-session-readAndClose.phpt index 3587b2ae..65365584 100644 --- a/tests/Http/Session.regenerate-empty-session-readAndClose.phpt +++ b/tests/Http/Session.regenerate-empty-session-readAndClose.phpt @@ -20,7 +20,7 @@ file_put_contents(getTempDir() . '/sess_' . $sessionId, '__NF|a:1:{s:4:"DATA";a: $session = new Session(new Http\Request(new Http\UrlScript('http://nette.org'), [], [], $cookies), new Http\Response); $session->setOptions(['readAndClose' => true]); $session->start(); -Assert::same('yes', $session->getSection('temp')->value); +Assert::same('yes', $session->getSection('temp')->get('value')); // session was not regenerated Assert::same($session->getId(), $sessionId); diff --git a/tests/Http/Session.regenerate-empty-session.phpt b/tests/Http/Session.regenerate-empty-session.phpt index b558216c..f46afe2f 100644 --- a/tests/Http/Session.regenerate-empty-session.phpt +++ b/tests/Http/Session.regenerate-empty-session.phpt @@ -19,7 +19,7 @@ file_put_contents(getTempDir() . '/sess_' . $sessionId, '__NF|a:1:{s:4:"DATA";a: $session = new Session(new Http\Request(new Http\UrlScript('http://nette.org'), [], [], $cookies), new Http\Response); $session->start(); -Assert::same('yes', $session->getSection('temp')->value); +Assert::same('yes', $session->getSection('temp')->get('value')); $newSessionId = $session->getId(); $session->close(); diff --git a/tests/Http/Session.restart-after-regenerate.phpt b/tests/Http/Session.restart-after-regenerate.phpt index 86a8122f..5164a587 100644 --- a/tests/Http/Session.restart-after-regenerate.phpt +++ b/tests/Http/Session.restart-after-regenerate.phpt @@ -18,7 +18,7 @@ $session = new Http\Session(new Http\Request(new Http\UrlScript, [], [], $cookie $session->start(); Assert::same($sessionId, $session->getId()); -Assert::same('yes', $session->getSection('temp')->value); +Assert::same('yes', $session->getSection('temp')->get('value')); $session->regenerateId(); Assert::notSame($sessionId, $session->getId()); @@ -26,7 +26,7 @@ Assert::same(session_id(), $session->getId()); $session->close(); $session->start(); -Assert::same('yes', $session->getSection('temp')->value); +Assert::same('yes', $session->getSection('temp')->get('value')); Assert::true(file_exists(getTempDir() . '/sess_' . $session->getId())); Assert::count(1, glob(getTempDir() . '/sess_*')); diff --git a/tests/Http/Session.sections.phpt b/tests/Http/Session.sections.phpt index 2e004c2f..45eab766 100644 --- a/tests/Http/Session.sections.phpt +++ b/tests/Http/Session.sections.phpt @@ -22,11 +22,11 @@ $section = $session->getSection('trees'); Assert::type(Nette\Http\SessionSection::class, $section); Assert::false($session->hasSection('trees')); // hasSection() should have returned false for a section with no keys set -$section->hello = 'world'; +$section->set('hello', 'world'); Assert::true($session->hasSection('trees')); // hasSection() should have returned true for a section with keys set $section = $session->getSection('default'); Assert::same(['trees'], $session->getSectionNames()); -$section->hello = 'world'; +$section->set('hello', 'world'); Assert::same(['trees', 'default'], $session->getSectionNames()); diff --git a/tests/Http/SessionSection.basic.phpt b/tests/Http/SessionSection.basic.phpt index 5f056fc0..c33afc3e 100644 --- a/tests/Http/SessionSection.basic.phpt +++ b/tests/Http/SessionSection.basic.phpt @@ -15,13 +15,11 @@ require __DIR__ . '/../bootstrap.php'; $session = new Session(new Nette\Http\Request(new Nette\Http\UrlScript), new Nette\Http\Response); $namespace = $session->getSection('one'); -$namespace->a = 'apple'; +$namespace->set('a', 'apple'); $namespace->set('p', 'pear'); -$namespace['o'] = 'orange'; - -Assert::same('apple', $namespace->a); +$namespace->set('o', 'orange'); Assert::same('pear', $namespace->get('p')); -Assert::same('orange', $namespace['o']); +Assert::null($namespace->get('undefined')); foreach ($namespace as $key => $val) { $tmp[] = "$key=$val"; @@ -33,16 +31,11 @@ Assert::same([ 'o=orange', ], $tmp); +$namespace->remove('a'); +Assert::same('p=pear&o=orange', http_build_query(iterator_to_array($namespace->getIterator()))); -Assert::true(isset($namespace['p'])); -Assert::true(isset($namespace->o)); -Assert::false(isset($namespace->undefined)); - -unset($namespace['a'], $namespace->o, $namespace->undef); -$namespace->remove('p'); -$namespace->remove(['x']); - - - +$namespace->remove(['x', 'p']); +Assert::same('o=orange', http_build_query(iterator_to_array($namespace->getIterator()))); +$namespace->remove(); Assert::same('', http_build_query(iterator_to_array($namespace->getIterator()))); diff --git a/tests/Http/SessionSection.remove.phpt b/tests/Http/SessionSection.remove.phpt deleted file mode 100644 index cf1349f6..00000000 --- a/tests/Http/SessionSection.remove.phpt +++ /dev/null @@ -1,28 +0,0 @@ -getSection('three'); -$namespace->a = 'apple'; -$namespace->p = 'papaya'; -$namespace['c'] = 'cherry'; - -$namespace = $session->getSection('three'); -Assert::same('a=apple&p=papaya&c=cherry', http_build_query(iterator_to_array($namespace->getIterator()))); - - -// removing -$namespace->remove(); -Assert::same('', http_build_query(iterator_to_array($namespace->getIterator()))); diff --git a/tests/Http/SessionSection.removeExpiration().phpt b/tests/Http/SessionSection.removeExpiration().phpt index af90c54f..630c348c 100644 --- a/tests/Http/SessionSection.removeExpiration().phpt +++ b/tests/Http/SessionSection.removeExpiration().phpt @@ -15,8 +15,8 @@ $session = new Session(new Nette\Http\Request(new Nette\Http\UrlScript), new Net $session->setExpiration('+10 seconds'); $section = $session->getSection('expireRemove'); -$section->a = 'apple'; -$section->b = 'banana'; +$section->set('a', 'apple'); +$section->set('b', 'banana'); $section->setExpiration('+2 seconds', 'a'); $section->removeExpiration('a'); diff --git a/tests/Http/SessionSection.separated.phpt b/tests/Http/SessionSection.separated.phpt index 26e43c8c..f2646962 100644 --- a/tests/Http/SessionSection.separated.phpt +++ b/tests/Http/SessionSection.separated.phpt @@ -14,16 +14,18 @@ require __DIR__ . '/../bootstrap.php'; $session = new Session(new Nette\Http\Request(new Nette\Http\UrlScript), new Nette\Http\Response); -$namespace1 = $session->getSection('namespace1'); -$namespace1b = $session->getSection('namespace1'); -$namespace2 = $session->getSection('namespace2'); -$namespace2b = $session->getSection('namespace2'); -$namespace3 = $session->getSection('default'); -$namespace3b = $session->getSection('default'); -$namespace1->a = 'apple'; -$namespace2->a = 'pear'; -$namespace3->a = 'orange'; -Assert::true($namespace1->a !== $namespace2->a && $namespace1->a !== $namespace3->a && $namespace2->a !== $namespace3->a); -Assert::same($namespace1->a, $namespace1b->a); -Assert::same($namespace2->a, $namespace2b->a); -Assert::same($namespace3->a, $namespace3b->a); +$section1 = $session->getSection('namespace1'); +$section1b = $session->getSection('namespace1'); +$section2 = $session->getSection('namespace2'); +$section2b = $session->getSection('namespace2'); +$section3 = $session->getSection('default'); +$section3b = $session->getSection('default'); +$section1->set('a', 'apple'); +$section2->set('a', 'pear'); +$section3->set('a', 'orange'); +Assert::same('apple', $section1->get('a')); +Assert::same('apple', $section1b->get('a')); +Assert::same('pear', $section2->get('a')); +Assert::same('pear', $section2b->get('a')); +Assert::same('orange', $section3->get('a')); +Assert::same('orange', $section3b->get('a')); diff --git a/tests/Http/SessionSection.setExpiration().phpt b/tests/Http/SessionSection.setExpiration().phpt index 44fa99e6..0328ad3b 100644 --- a/tests/Http/SessionSection.setExpiration().phpt +++ b/tests/Http/SessionSection.setExpiration().phpt @@ -18,9 +18,8 @@ $session->setExpiration('+10 seconds'); test('try to expire whole namespace', function () use ($session) { $namespace = $session->getSection('expire'); - $namespace->a = 'apple'; - $namespace->p = 'pear'; - $namespace['o'] = 'orange'; + $namespace->set('a', 'apple'); + $namespace->set('p', 'pear'); $namespace->setExpiration('+ 1 seconds'); $session->close(); @@ -35,8 +34,9 @@ test('try to expire whole namespace', function () use ($session) { test('try to expire only 1 of the keys', function () use ($session) { $namespace = $session->getSection('expireSingle'); $namespace->setExpiration('1 second', 'g'); - $namespace->g = 'guava'; - $namespace->p = 'plum'; + $namespace->set('g', 'guava'); + $namespace->set('p', 'plum'); + $namespace->setExpiration('1 second', 'p'); $namespace->set('a', 'apple', '1 second'); $session->close(); @@ -44,7 +44,7 @@ test('try to expire only 1 of the keys', function () use ($session) { $session->start(); $namespace = $session->getSection('expireSingle'); - Assert::same('p=plum', http_build_query(iterator_to_array($namespace->getIterator()))); + Assert::same('g=guava', http_build_query(iterator_to_array($namespace->getIterator()))); }); diff --git a/tests/Http/SessionSection.undefined.phpt b/tests/Http/SessionSection.undefined.phpt deleted file mode 100644 index 6eb5577c..00000000 --- a/tests/Http/SessionSection.undefined.phpt +++ /dev/null @@ -1,20 +0,0 @@ -getSection('one'); -Assert::false(isset($namespace->undefined)); -Assert::null($namespace->undefined); // Getting value of non-existent key -Assert::same('', http_build_query(iterator_to_array($namespace->getIterator()))); diff --git a/tests/Http/Url.httpScheme.phpt b/tests/Http/Url.httpScheme.phpt index aff3c01b..1ee32b68 100644 --- a/tests/Http/Url.httpScheme.phpt +++ b/tests/Http/Url.httpScheme.phpt @@ -23,14 +23,11 @@ Assert::same('hostname', $url->host); Assert::same(60, $url->port); Assert::same(80, $url->getDefaultPort()); Assert::same('/p%61th/script.php', $url->path); -Assert::same('/p%61th/', $url->basePath); Assert::same('arg=value', $url->query); Assert::same('anchor', $url->fragment); Assert::same('username%3A:password%3A@hostname:60', $url->authority); Assert::same('http://username%3A:password%3A@hostname:60', $url->hostUrl); Assert::same('http://username%3A:password%3A@hostname:60/p%61th/script.php?arg=value#anchor', $url->absoluteUrl); -Assert::same('http://username%3A:password%3A@hostname:60/p%61th/', $url->baseUrl); -Assert::same('script.php?arg=value#anchor', $url->relativeUrl); $url->setPath(''); Assert::same('/', $url->getPath());