Skip to content

Commit 164fdb6

Browse files
committed
tests: uses new session api
1 parent 10ec1bd commit 164fdb6

13 files changed

Lines changed: 40 additions & 96 deletions

tests/Http/Session.handler.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ $session->setHandler(new MySessionStorage);
7373
$session->start();
7474

7575
$namespace = $session->getSection('one');
76-
$namespace->a = 'apple';
76+
$namespace->set('a', 'apple');
7777
$session->close();
7878
unset($_SESSION);
7979

8080
$session->start();
8181
$namespace = $session->getSection('one');
82-
Assert::same('apple', $namespace->a);
82+
Assert::same('apple', $namespace->get('a'));

tests/Http/Session.id.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ $session->start();
2525
Assert::same($sessionId, $session->getId());
2626
Assert::same([$sessionName => $leet], $_COOKIE);
2727

28-
Assert::same('yes', $session->getSection('temp')->value);
28+
Assert::same('yes', $session->getSection('temp')->get('value'));
2929
$session->close();
3030

3131
// session was not regenerated

tests/Http/Session.regenerate-empty-session-readAndClose.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ file_put_contents(getTempDir() . '/sess_' . $sessionId, '__NF|a:1:{s:4:"DATA";a:
2020
$session = new Session(new Http\Request(new Http\UrlScript('http://nette.org'), [], [], $cookies), new Http\Response);
2121
$session->setOptions(['readAndClose' => true]);
2222
$session->start();
23-
Assert::same('yes', $session->getSection('temp')->value);
23+
Assert::same('yes', $session->getSection('temp')->get('value'));
2424

2525
// session was not regenerated
2626
Assert::same($session->getId(), $sessionId);

tests/Http/Session.regenerate-empty-session.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ file_put_contents(getTempDir() . '/sess_' . $sessionId, '__NF|a:1:{s:4:"DATA";a:
1919

2020
$session = new Session(new Http\Request(new Http\UrlScript('http://nette.org'), [], [], $cookies), new Http\Response);
2121
$session->start();
22-
Assert::same('yes', $session->getSection('temp')->value);
22+
Assert::same('yes', $session->getSection('temp')->get('value'));
2323

2424
$newSessionId = $session->getId();
2525
$session->close();

tests/Http/Session.restart-after-regenerate.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ $session = new Http\Session(new Http\Request(new Http\UrlScript, [], [], $cookie
1818

1919
$session->start();
2020
Assert::same($sessionId, $session->getId());
21-
Assert::same('yes', $session->getSection('temp')->value);
21+
Assert::same('yes', $session->getSection('temp')->get('value'));
2222

2323
$session->regenerateId();
2424
Assert::notSame($sessionId, $session->getId());
2525
Assert::same(session_id(), $session->getId());
2626
$session->close();
2727

2828
$session->start();
29-
Assert::same('yes', $session->getSection('temp')->value);
29+
Assert::same('yes', $session->getSection('temp')->get('value'));
3030

3131
Assert::true(file_exists(getTempDir() . '/sess_' . $session->getId()));
3232
Assert::count(1, glob(getTempDir() . '/sess_*'));

tests/Http/Session.sections.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ $section = $session->getSection('trees');
2222
Assert::type(Nette\Http\SessionSection::class, $section);
2323
Assert::false($session->hasSection('trees')); // hasSection() should have returned false for a section with no keys set
2424

25-
$section->hello = 'world';
25+
$section->set('hello', 'world');
2626
Assert::true($session->hasSection('trees')); // hasSection() should have returned true for a section with keys set
2727

2828
$section = $session->getSection('default');
2929
Assert::same(['trees'], $session->getSectionNames());
3030

31-
$section->hello = 'world';
31+
$section->set('hello', 'world');
3232
Assert::same(['trees', 'default'], $session->getSectionNames());

tests/Http/SessionSection.basic.phpt

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@ require __DIR__ . '/../bootstrap.php';
1515
$session = new Session(new Nette\Http\Request(new Nette\Http\UrlScript), new Nette\Http\Response);
1616

1717
$namespace = $session->getSection('one');
18-
$namespace->a = 'apple';
18+
$namespace->set('a', 'apple');
1919
$namespace->set('p', 'pear');
20-
$namespace['o'] = 'orange';
21-
22-
Assert::same('apple', $namespace->a);
20+
$namespace->set('o', 'orange');
2321
Assert::same('pear', $namespace->get('p'));
24-
Assert::same('orange', $namespace['o']);
22+
Assert::null($namespace->get('undefined'));
2523

2624
foreach ($namespace as $key => $val) {
2725
$tmp[] = "$key=$val";
@@ -33,16 +31,11 @@ Assert::same([
3331
'o=orange',
3432
], $tmp);
3533

34+
$namespace->remove('a');
35+
Assert::same('p=pear&o=orange', http_build_query(iterator_to_array($namespace->getIterator())));
3636

37-
Assert::true(isset($namespace['p']));
38-
Assert::true(isset($namespace->o));
39-
Assert::false(isset($namespace->undefined));
40-
41-
unset($namespace['a'], $namespace->o, $namespace->undef);
42-
$namespace->remove('p');
43-
$namespace->remove(['x']);
44-
45-
46-
37+
$namespace->remove(['x', 'p']);
38+
Assert::same('o=orange', http_build_query(iterator_to_array($namespace->getIterator())));
4739

40+
$namespace->remove();
4841
Assert::same('', http_build_query(iterator_to_array($namespace->getIterator())));

tests/Http/SessionSection.remove.phpt

Lines changed: 0 additions & 28 deletions
This file was deleted.

tests/Http/SessionSection.removeExpiration().phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ $session = new Session(new Nette\Http\Request(new Nette\Http\UrlScript), new Net
1515
$session->setExpiration('+10 seconds');
1616

1717
$section = $session->getSection('expireRemove');
18-
$section->a = 'apple';
19-
$section->b = 'banana';
18+
$section->set('a', 'apple');
19+
$section->set('b', 'banana');
2020

2121
$section->setExpiration('+2 seconds', 'a');
2222
$section->removeExpiration('a');

tests/Http/SessionSection.separated.phpt

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@ require __DIR__ . '/../bootstrap.php';
1414

1515
$session = new Session(new Nette\Http\Request(new Nette\Http\UrlScript), new Nette\Http\Response);
1616

17-
$namespace1 = $session->getSection('namespace1');
18-
$namespace1b = $session->getSection('namespace1');
19-
$namespace2 = $session->getSection('namespace2');
20-
$namespace2b = $session->getSection('namespace2');
21-
$namespace3 = $session->getSection('default');
22-
$namespace3b = $session->getSection('default');
23-
$namespace1->a = 'apple';
24-
$namespace2->a = 'pear';
25-
$namespace3->a = 'orange';
26-
Assert::true($namespace1->a !== $namespace2->a && $namespace1->a !== $namespace3->a && $namespace2->a !== $namespace3->a);
27-
Assert::same($namespace1->a, $namespace1b->a);
28-
Assert::same($namespace2->a, $namespace2b->a);
29-
Assert::same($namespace3->a, $namespace3b->a);
17+
$section1 = $session->getSection('namespace1');
18+
$section1b = $session->getSection('namespace1');
19+
$section2 = $session->getSection('namespace2');
20+
$section2b = $session->getSection('namespace2');
21+
$section3 = $session->getSection('default');
22+
$section3b = $session->getSection('default');
23+
$section1->set('a', 'apple');
24+
$section2->set('a', 'pear');
25+
$section3->set('a', 'orange');
26+
Assert::same('apple', $section1->get('a'));
27+
Assert::same('apple', $section1b->get('a'));
28+
Assert::same('pear', $section2->get('a'));
29+
Assert::same('pear', $section2b->get('a'));
30+
Assert::same('orange', $section3->get('a'));
31+
Assert::same('orange', $section3b->get('a'));

0 commit comments

Comments
 (0)