From dc6b29d81ec6d72c550a6acb14a7abd3895c947e Mon Sep 17 00:00:00 2001 From: Andrei Furnica Date: Wed, 1 Aug 2018 13:08:12 +0300 Subject: [PATCH 01/10] run session tests on separate processes --- tests/system/Session/SessionTest.php | 87 +++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 3 deletions(-) diff --git a/tests/system/Session/SessionTest.php b/tests/system/Session/SessionTest.php index 1817b82bb3c6..7f0a319c592d 100644 --- a/tests/system/Session/SessionTest.php +++ b/tests/system/Session/SessionTest.php @@ -45,6 +45,9 @@ protected function getInstance($options=[]) return $session; } + /** + * @runInSeparateProcess + */ public function testSessionSetsRegenerateTime() { $session = $this->getInstance(); @@ -53,6 +56,9 @@ public function testSessionSetsRegenerateTime() $this->assertTrue(isset($_SESSION['__ci_last_regenerate']) && ! empty($_SESSION['__ci_last_regenerate'])); } + /** + * @runInSeparateProcess + */ public function testWillRegenerateSessionAutomatically() { $session = $this->getInstance(); @@ -65,6 +71,9 @@ public function testWillRegenerateSessionAutomatically() $this->assertGreaterThan($time + 90 ,$_SESSION['__ci_last_regenerate']); } + /** + * @runInSeparateProcess + */ public function testCanSetSingleValue() { $session = $this->getInstance(); @@ -75,6 +84,9 @@ public function testCanSetSingleValue() $this->assertEquals('bar', $_SESSION['foo']); } + /** + * @runInSeparateProcess + */ public function testCanSetArray() { $session = $this->getInstance(); @@ -90,6 +102,9 @@ public function testCanSetArray() $this->assertArrayNotHasKey('__ci_vars', $_SESSION); } + /** + * @runInSeparateProcess + */ public function testGetSimpleKey() { $session = $this->getInstance(); @@ -100,6 +115,9 @@ public function testGetSimpleKey() $this->assertEquals('bar', $session->get('foo')); } + /** + * @runInSeparateProcess + */ public function testGetReturnsNullWhenNotFound() { $_SESSION = []; @@ -110,7 +128,10 @@ public function testGetReturnsNullWhenNotFound() $this->assertNull($session->get('foo')); } - public function testGetReturnsAllWithNoKeys() + /** + * @runInSeparateProcess + */ + public function testGetReturnsAllWithNoKeys() { $_SESSION = [ 'foo' => 'bar', @@ -126,8 +147,10 @@ public function testGetReturnsAllWithNoKeys() $this->assertTrue(array_key_exists('bar', $result)); } - - public function testGetAsProperty() + /** + * @runInSeparateProcess + */ + public function testGetAsProperty() { $session = $this->getInstance(); $session->start(); @@ -137,6 +160,9 @@ public function testGetAsProperty() $this->assertEquals('bar', $session->foo); } + /** + * @runInSeparateProcess + */ public function testGetAsNormal() { $session = $this->getInstance(); @@ -147,6 +173,9 @@ public function testGetAsNormal() $this->assertEquals('bar', $_SESSION['foo']); } + /** + * @runInSeparateProcess + */ public function testHasReturnsTrueOnSuccess() { $session = $this->getInstance(); @@ -157,6 +186,9 @@ public function testHasReturnsTrueOnSuccess() $this->assertTrue($session->has('foo')); } + /** + * @runInSeparateProcess + */ public function testHasReturnsFalseOnNotFound() { $session = $this->getInstance(); @@ -167,6 +199,9 @@ public function testHasReturnsFalseOnNotFound() $this->assertFalse($session->has('bar')); } + /** + * @runInSeparateProcess + */ public function testRemoveActuallyRemoves() { $session = $this->getInstance(); @@ -179,6 +214,9 @@ public function testRemoveActuallyRemoves() $this->assertFalse($session->has('foo')); } + /** + * @runInSeparateProcess + */ public function testHasReturnsCanRemoveArray() { $session = $this->getInstance(); @@ -197,6 +235,9 @@ public function testHasReturnsCanRemoveArray() $this->assertArrayNotHasKey('bar', $_SESSION); } + /** + * @runInSeparateProcess + */ public function testSetMagicMethod() { $session = $this->getInstance(); @@ -208,6 +249,9 @@ public function testSetMagicMethod() $this->assertEquals('bar', $_SESSION['foo']); } + /** + * @runInSeparateProcess + */ public function testCanFlashData() { $session = $this->getInstance(); @@ -230,6 +274,9 @@ public function testCanFlashData() $this->assertFalse($session->has('foo')); } + /** + * @runInSeparateProcess + */ public function testCanFlashArray() { $session = $this->getInstance(); @@ -246,6 +293,9 @@ public function testCanFlashArray() $this->assertEquals('new', $_SESSION['__ci_vars']['bar']); } + /** + * @runInSeparateProcess + */ public function testKeepFlashData() { $session = $this->getInstance(); @@ -273,6 +323,9 @@ public function testKeepFlashData() $this->assertEquals('old', $_SESSION['__ci_vars']['foo']); } + /** + * @runInSeparateProcess + */ public function testUnmarkFlashDataRemovesData() { $session = $this->getInstance(); @@ -292,6 +345,9 @@ public function testUnmarkFlashDataRemovesData() $this->assertFalse(isset($_SESSION['__ci_vars']['foo'])); } + /** + * @runInSeparateProcess + */ public function testGetFlashKeysOnlyReturnsFlashKeys() { $session = $this->getInstance(); @@ -306,6 +362,9 @@ public function testGetFlashKeysOnlyReturnsFlashKeys() $this->assertNotContains('bar', $keys); } + /** + * @runInSeparateProcess + */ public function testSetTempDataWorks() { $session = $this->getInstance(); @@ -315,6 +374,9 @@ public function testSetTempDataWorks() $this->assertGreaterThanOrEqual($_SESSION['__ci_vars']['foo'], time() + 300); } + /** + * @runInSeparateProcess + */ public function testSetTempDataArrayMultiTTL() { $session = $this->getInstance(); @@ -333,6 +395,9 @@ public function testSetTempDataArrayMultiTTL() $this->assertLessThanOrEqual($_SESSION['__ci_vars']['baz'], $time + 100); } + /** + * @runInSeparateProcess + */ public function testSetTempDataArraySingleTTL() { $session = $this->getInstance(); @@ -349,6 +414,7 @@ public function testSetTempDataArraySingleTTL() /** * @group single + * @runInSeparateProcess */ public function testGetTestDataReturnsAll() { @@ -366,6 +432,9 @@ public function testGetTestDataReturnsAll() $this->assertEquals($data, $session->getTempdata()); } + /** + * @runInSeparateProcess + */ public function testGetTestDataReturnsSingle() { $session = $this->getInstance(); @@ -381,6 +450,9 @@ public function testGetTestDataReturnsSingle() $this->assertEquals('bar', $session->getTempdata('foo')); } + /** + * @runInSeparateProcess + */ public function testRemoveTempDataActuallyDeletes() { $session = $this->getInstance(); @@ -397,6 +469,9 @@ public function testRemoveTempDataActuallyDeletes() $this->assertEquals(['bar' => 'baz'], $session->getTempdata()); } + /** + * @runInSeparateProcess + */ public function testUnMarkTempDataSingle() { $session = $this->getInstance(); @@ -413,6 +488,9 @@ public function testUnMarkTempDataSingle() $this->assertEquals(['bar' => 'baz'], $session->getTempdata()); } + /** + * @runInSeparateProcess + */ public function testUnMarkTempDataArray() { $session = $this->getInstance(); @@ -429,6 +507,9 @@ public function testUnMarkTempDataArray() $this->assertEquals([], $session->getTempdata()); } + /** + * @runInSeparateProcess + */ public function testGetTempdataKeys() { $session = $this->getInstance(); From 9a317e852e2bf90d307cb582c9fe8c2b3081a36b Mon Sep 17 00:00:00 2001 From: Andrei Furnica Date: Wed, 1 Aug 2018 13:08:47 +0300 Subject: [PATCH 02/10] tabs, not spaces --- tests/system/Session/SessionTest.php | 1010 +++++++++++++------------- 1 file changed, 505 insertions(+), 505 deletions(-) diff --git a/tests/system/Session/SessionTest.php b/tests/system/Session/SessionTest.php index 7f0a319c592d..a216b82f3786 100644 --- a/tests/system/Session/SessionTest.php +++ b/tests/system/Session/SessionTest.php @@ -7,131 +7,131 @@ class SessionTest extends \CIUnitTestCase { - public function setUp() - { - parent::setUp(); - - $_COOKIE = []; - $_SESSION = []; - } - - public function tearDown() - { - - } - - protected function getInstance($options=[]) - { - $defaults = [ - 'sessionDriver' => 'CodeIgniter\Session\Handlers\FileHandler', - 'sessionCookieName' => 'ci_session', - 'sessionExpiration' => 7200, - 'sessionSavePath' => null, - 'sessionMatchIP' => false, - 'sessionTimeToUpdate' => 300, - 'sessionRegenerateDestroy' => false, - 'cookieDomain' => '', - 'cookiePrefix' => '', - 'cookiePath' => '/', - 'cookieSecure' => false, - ]; - - $config = array_merge($defaults, $options); - $config = (object)$config; - - $session = new MockSession(new FileHandler($config), $config); - $session->setLogger(new TestLogger(new Logger())); - - return $session; - } - - /** - * @runInSeparateProcess - */ - public function testSessionSetsRegenerateTime() - { - $session = $this->getInstance(); - $session->start(); - - $this->assertTrue(isset($_SESSION['__ci_last_regenerate']) && ! empty($_SESSION['__ci_last_regenerate'])); - } - - /** - * @runInSeparateProcess - */ - public function testWillRegenerateSessionAutomatically() - { - $session = $this->getInstance(); - - $time = time()-400; - $_SESSION['__ci_last_regenerate'] = $time; - $session->start(); - - $this->assertTrue($session->didRegenerate); - $this->assertGreaterThan($time + 90 ,$_SESSION['__ci_last_regenerate']); - } - - /** - * @runInSeparateProcess - */ - public function testCanSetSingleValue() - { - $session = $this->getInstance(); - $session->start(); - - $session->set('foo', 'bar'); - - $this->assertEquals('bar', $_SESSION['foo']); - } - - /** - * @runInSeparateProcess - */ - public function testCanSetArray() - { - $session = $this->getInstance(); - $session->start(); - - $session->set([ - 'foo' => 'bar', - 'bar' => 'baz' - ]); - - $this->assertEquals('bar', $_SESSION['foo']); - $this->assertEquals('baz', $_SESSION['bar']); - $this->assertArrayNotHasKey('__ci_vars', $_SESSION); - } - - /** - * @runInSeparateProcess - */ - public function testGetSimpleKey() - { - $session = $this->getInstance(); - $session->start(); - - $session->set('foo', 'bar'); - - $this->assertEquals('bar', $session->get('foo')); - } - - /** - * @runInSeparateProcess - */ - public function testGetReturnsNullWhenNotFound() - { - $_SESSION = []; - - $session = $this->getInstance(); - $session->start(); - - $this->assertNull($session->get('foo')); - } - - /** - * @runInSeparateProcess - */ - public function testGetReturnsAllWithNoKeys() + public function setUp() + { + parent::setUp(); + + $_COOKIE = []; + $_SESSION = []; + } + + public function tearDown() + { + + } + + protected function getInstance($options = []) + { + $defaults = [ + 'sessionDriver' => 'CodeIgniter\Session\Handlers\FileHandler', + 'sessionCookieName' => 'ci_session', + 'sessionExpiration' => 7200, + 'sessionSavePath' => null, + 'sessionMatchIP' => false, + 'sessionTimeToUpdate' => 300, + 'sessionRegenerateDestroy' => false, + 'cookieDomain' => '', + 'cookiePrefix' => '', + 'cookiePath' => '/', + 'cookieSecure' => false, + ]; + + $config = array_merge($defaults, $options); + $config = (object)$config; + + $session = new MockSession(new FileHandler($config), $config); + $session->setLogger(new TestLogger(new Logger())); + + return $session; + } + + /** + * @runInSeparateProcess + */ + public function testSessionSetsRegenerateTime() + { + $session = $this->getInstance(); + $session->start(); + + $this->assertTrue(isset($_SESSION['__ci_last_regenerate']) && !empty($_SESSION['__ci_last_regenerate'])); + } + + /** + * @runInSeparateProcess + */ + public function testWillRegenerateSessionAutomatically() + { + $session = $this->getInstance(); + + $time = time() - 400; + $_SESSION['__ci_last_regenerate'] = $time; + $session->start(); + + $this->assertTrue($session->didRegenerate); + $this->assertGreaterThan($time + 90, $_SESSION['__ci_last_regenerate']); + } + + /** + * @runInSeparateProcess + */ + public function testCanSetSingleValue() + { + $session = $this->getInstance(); + $session->start(); + + $session->set('foo', 'bar'); + + $this->assertEquals('bar', $_SESSION['foo']); + } + + /** + * @runInSeparateProcess + */ + public function testCanSetArray() + { + $session = $this->getInstance(); + $session->start(); + + $session->set([ + 'foo' => 'bar', + 'bar' => 'baz' + ]); + + $this->assertEquals('bar', $_SESSION['foo']); + $this->assertEquals('baz', $_SESSION['bar']); + $this->assertArrayNotHasKey('__ci_vars', $_SESSION); + } + + /** + * @runInSeparateProcess + */ + public function testGetSimpleKey() + { + $session = $this->getInstance(); + $session->start(); + + $session->set('foo', 'bar'); + + $this->assertEquals('bar', $session->get('foo')); + } + + /** + * @runInSeparateProcess + */ + public function testGetReturnsNullWhenNotFound() + { + $_SESSION = []; + + $session = $this->getInstance(); + $session->start(); + + $this->assertNull($session->get('foo')); + } + + /** + * @runInSeparateProcess + */ + public function testGetReturnsAllWithNoKeys() { $_SESSION = [ 'foo' => 'bar', @@ -145,384 +145,384 @@ public function testGetReturnsAllWithNoKeys() $this->assertTrue(array_key_exists('foo', $result)); $this->assertTrue(array_key_exists('bar', $result)); - } - - /** - * @runInSeparateProcess - */ - public function testGetAsProperty() - { - $session = $this->getInstance(); - $session->start(); - - $session->set('foo', 'bar'); - - $this->assertEquals('bar', $session->foo); - } - - /** - * @runInSeparateProcess - */ - public function testGetAsNormal() - { - $session = $this->getInstance(); - $session->start(); - - $session->set('foo', 'bar'); - - $this->assertEquals('bar', $_SESSION['foo']); - } - - /** - * @runInSeparateProcess - */ - public function testHasReturnsTrueOnSuccess() - { - $session = $this->getInstance(); - $session->start(); - - $_SESSION['foo'] = 'bar'; - - $this->assertTrue($session->has('foo')); - } - - /** - * @runInSeparateProcess - */ - public function testHasReturnsFalseOnNotFound() - { - $session = $this->getInstance(); - $session->start(); - - $_SESSION['foo'] = 'bar'; - - $this->assertFalse($session->has('bar')); - } - - /** - * @runInSeparateProcess - */ - public function testRemoveActuallyRemoves() - { - $session = $this->getInstance(); - $session->start(); - - $_SESSION['foo'] = 'bar'; - $session->remove('foo'); - - $this->assertArrayNotHasKey('foo', $_SESSION); - $this->assertFalse($session->has('foo')); - } - - /** - * @runInSeparateProcess - */ - public function testHasReturnsCanRemoveArray() - { - $session = $this->getInstance(); - $session->start(); - - $_SESSION = [ - 'foo' => 'bar', - 'bar' => 'baz' - ]; - - $this->assertTrue($session->has('foo')); - - $session->remove(['foo', 'bar']); - - $this->assertArrayNotHasKey('foo', $_SESSION); - $this->assertArrayNotHasKey('bar', $_SESSION); - } - - /** - * @runInSeparateProcess - */ - public function testSetMagicMethod() - { - $session = $this->getInstance(); - $session->start(); - - $session->foo = 'bar'; - - $this->assertArrayHasKey('foo', $_SESSION); - $this->assertEquals('bar', $_SESSION['foo']); - } - - /** - * @runInSeparateProcess - */ - public function testCanFlashData() - { - $session = $this->getInstance(); - $session->start(); - - $session->setFlashdata('foo', 'bar'); - - $this->assertTrue($session->has('foo')); - $this->assertEquals('new', $_SESSION['__ci_vars']['foo']); - - // Should reset the 'new' to 'old' - $session->start(); - - $this->assertTrue($session->has('foo')); - $this->assertEquals('old', $_SESSION['__ci_vars']['foo']); - - // Should no longer be available - $session->start(); - - $this->assertFalse($session->has('foo')); - } - - /** - * @runInSeparateProcess - */ - public function testCanFlashArray() - { - $session = $this->getInstance(); - $session->start(); - - $session->setFlashdata([ - 'foo' => 'bar', - 'bar' => 'baz' - ]); - - $this->assertTrue($session->has('foo')); - $this->assertEquals('new', $_SESSION['__ci_vars']['foo']); - $this->assertTrue($session->has('bar')); - $this->assertEquals('new', $_SESSION['__ci_vars']['bar']); - } - - /** - * @runInSeparateProcess - */ - public function testKeepFlashData() - { - $session = $this->getInstance(); - $session->start(); - - $session->setFlashdata('foo', 'bar'); - - $this->assertTrue($session->has('foo')); - $this->assertEquals('new', $_SESSION['__ci_vars']['foo']); - - // Should reset the 'new' to 'old' - $session->start(); - - $this->assertTrue($session->has('foo')); - $this->assertEquals('old', $_SESSION['__ci_vars']['foo']); - - $session->keepFlashdata('foo'); - - $this->assertEquals('new', $_SESSION['__ci_vars']['foo']); - - // Should no longer be available - $session->start(); - - $this->assertTrue($session->has('foo')); - $this->assertEquals('old', $_SESSION['__ci_vars']['foo']); - } - - /** - * @runInSeparateProcess - */ - public function testUnmarkFlashDataRemovesData() - { - $session = $this->getInstance(); - $session->start(); - - $session->setFlashdata('foo', 'bar'); - $session->set('bar', 'baz'); - - $this->assertTrue($session->has('foo')); - $this->assertArrayHasKey('foo', $_SESSION['__ci_vars']); - - $session->unmarkFlashdata('foo'); - - // Should still be here - $this->assertTrue($session->has('foo')); - // but no longer marked as flash - $this->assertFalse(isset($_SESSION['__ci_vars']['foo'])); - } - - /** - * @runInSeparateProcess - */ - public function testGetFlashKeysOnlyReturnsFlashKeys() - { - $session = $this->getInstance(); - $session->start(); - - $session->setFlashdata('foo', 'bar'); - $session->set('bar', 'baz'); - - $keys = $session->getFlashKeys(); - - $this->assertContains('foo', $keys); - $this->assertNotContains('bar', $keys); - } - - /** - * @runInSeparateProcess - */ - public function testSetTempDataWorks() - { - $session = $this->getInstance(); - $session->start(); - - $session->setTempdata('foo', 'bar', 300); - $this->assertGreaterThanOrEqual($_SESSION['__ci_vars']['foo'], time() + 300); - } - - /** - * @runInSeparateProcess - */ - public function testSetTempDataArrayMultiTTL() - { - $session = $this->getInstance(); - $session->start(); - - $time = time(); - - $session->setTempdata([ - 'foo' => 300, - 'bar' => 400, - 'baz' => 100 - ]); - - $this->assertLessThanOrEqual($_SESSION['__ci_vars']['foo'], $time + 300); - $this->assertLessThanOrEqual($_SESSION['__ci_vars']['bar'], $time + 400); - $this->assertLessThanOrEqual($_SESSION['__ci_vars']['baz'], $time + 100); - } - - /** - * @runInSeparateProcess - */ - public function testSetTempDataArraySingleTTL() - { - $session = $this->getInstance(); - $session->start(); - - $time = time(); - - $session->setTempdata(['foo', 'bar', 'baz'], null, 200); - - $this->assertLessThanOrEqual($_SESSION['__ci_vars']['foo'], $time + 200); - $this->assertLessThanOrEqual($_SESSION['__ci_vars']['bar'], $time + 200); - $this->assertLessThanOrEqual($_SESSION['__ci_vars']['baz'], $time + 200); - } - - /** - * @group single - * @runInSeparateProcess - */ - public function testGetTestDataReturnsAll() - { - $session = $this->getInstance(); - $session->start(); - - $data = [ - 'foo' => 'bar', - 'bar' => 'baz' - ]; - - $session->setTempdata($data); - $session->set('baz', 'ballywhoo'); - - $this->assertEquals($data, $session->getTempdata()); - } - - /** - * @runInSeparateProcess - */ - public function testGetTestDataReturnsSingle() - { - $session = $this->getInstance(); - $session->start(); - - $data = [ - 'foo' => 'bar', - 'bar' => 'baz' - ]; - - $session->setTempdata($data); - - $this->assertEquals('bar', $session->getTempdata('foo')); - } - - /** - * @runInSeparateProcess - */ - public function testRemoveTempDataActuallyDeletes() - { - $session = $this->getInstance(); - $session->start(); - - $data = [ - 'foo' => 'bar', - 'bar' => 'baz' - ]; - - $session->setTempdata($data); - $session->removeTempdata('foo'); - - $this->assertEquals(['bar' => 'baz'], $session->getTempdata()); - } - - /** - * @runInSeparateProcess - */ - public function testUnMarkTempDataSingle() - { - $session = $this->getInstance(); - $session->start(); - - $data = [ - 'foo' => 'bar', - 'bar' => 'baz' - ]; - - $session->setTempdata($data); - $session->unmarkTempdata('foo'); - - $this->assertEquals(['bar' => 'baz'], $session->getTempdata()); - } - - /** - * @runInSeparateProcess - */ - public function testUnMarkTempDataArray() - { - $session = $this->getInstance(); - $session->start(); - - $data = [ - 'foo' => 'bar', - 'bar' => 'baz' - ]; - - $session->setTempdata($data); - $session->unmarkTempdata(['foo', 'bar']); - - $this->assertEquals([], $session->getTempdata()); - } - - /** - * @runInSeparateProcess - */ - public function testGetTempdataKeys() - { - $session = $this->getInstance(); - $session->start(); - - $data = [ - 'foo' => 'bar', - 'bar' => 'baz' - ]; - - $session->setTempdata($data); - $session->set('baz', 'ballywhoo'); - - $this->assertEquals(['foo', 'bar'], $session->getTempKeys()); - } + } + + /** + * @runInSeparateProcess + */ + public function testGetAsProperty() + { + $session = $this->getInstance(); + $session->start(); + + $session->set('foo', 'bar'); + + $this->assertEquals('bar', $session->foo); + } + + /** + * @runInSeparateProcess + */ + public function testGetAsNormal() + { + $session = $this->getInstance(); + $session->start(); + + $session->set('foo', 'bar'); + + $this->assertEquals('bar', $_SESSION['foo']); + } + + /** + * @runInSeparateProcess + */ + public function testHasReturnsTrueOnSuccess() + { + $session = $this->getInstance(); + $session->start(); + + $_SESSION['foo'] = 'bar'; + + $this->assertTrue($session->has('foo')); + } + + /** + * @runInSeparateProcess + */ + public function testHasReturnsFalseOnNotFound() + { + $session = $this->getInstance(); + $session->start(); + + $_SESSION['foo'] = 'bar'; + + $this->assertFalse($session->has('bar')); + } + + /** + * @runInSeparateProcess + */ + public function testRemoveActuallyRemoves() + { + $session = $this->getInstance(); + $session->start(); + + $_SESSION['foo'] = 'bar'; + $session->remove('foo'); + + $this->assertArrayNotHasKey('foo', $_SESSION); + $this->assertFalse($session->has('foo')); + } + + /** + * @runInSeparateProcess + */ + public function testHasReturnsCanRemoveArray() + { + $session = $this->getInstance(); + $session->start(); + + $_SESSION = [ + 'foo' => 'bar', + 'bar' => 'baz' + ]; + + $this->assertTrue($session->has('foo')); + + $session->remove(['foo', 'bar']); + + $this->assertArrayNotHasKey('foo', $_SESSION); + $this->assertArrayNotHasKey('bar', $_SESSION); + } + + /** + * @runInSeparateProcess + */ + public function testSetMagicMethod() + { + $session = $this->getInstance(); + $session->start(); + + $session->foo = 'bar'; + + $this->assertArrayHasKey('foo', $_SESSION); + $this->assertEquals('bar', $_SESSION['foo']); + } + + /** + * @runInSeparateProcess + */ + public function testCanFlashData() + { + $session = $this->getInstance(); + $session->start(); + + $session->setFlashdata('foo', 'bar'); + + $this->assertTrue($session->has('foo')); + $this->assertEquals('new', $_SESSION['__ci_vars']['foo']); + + // Should reset the 'new' to 'old' + $session->start(); + + $this->assertTrue($session->has('foo')); + $this->assertEquals('old', $_SESSION['__ci_vars']['foo']); + + // Should no longer be available + $session->start(); + + $this->assertFalse($session->has('foo')); + } + + /** + * @runInSeparateProcess + */ + public function testCanFlashArray() + { + $session = $this->getInstance(); + $session->start(); + + $session->setFlashdata([ + 'foo' => 'bar', + 'bar' => 'baz' + ]); + + $this->assertTrue($session->has('foo')); + $this->assertEquals('new', $_SESSION['__ci_vars']['foo']); + $this->assertTrue($session->has('bar')); + $this->assertEquals('new', $_SESSION['__ci_vars']['bar']); + } + + /** + * @runInSeparateProcess + */ + public function testKeepFlashData() + { + $session = $this->getInstance(); + $session->start(); + + $session->setFlashdata('foo', 'bar'); + + $this->assertTrue($session->has('foo')); + $this->assertEquals('new', $_SESSION['__ci_vars']['foo']); + + // Should reset the 'new' to 'old' + $session->start(); + + $this->assertTrue($session->has('foo')); + $this->assertEquals('old', $_SESSION['__ci_vars']['foo']); + + $session->keepFlashdata('foo'); + + $this->assertEquals('new', $_SESSION['__ci_vars']['foo']); + + // Should no longer be available + $session->start(); + + $this->assertTrue($session->has('foo')); + $this->assertEquals('old', $_SESSION['__ci_vars']['foo']); + } + + /** + * @runInSeparateProcess + */ + public function testUnmarkFlashDataRemovesData() + { + $session = $this->getInstance(); + $session->start(); + + $session->setFlashdata('foo', 'bar'); + $session->set('bar', 'baz'); + + $this->assertTrue($session->has('foo')); + $this->assertArrayHasKey('foo', $_SESSION['__ci_vars']); + + $session->unmarkFlashdata('foo'); + + // Should still be here + $this->assertTrue($session->has('foo')); + // but no longer marked as flash + $this->assertFalse(isset($_SESSION['__ci_vars']['foo'])); + } + + /** + * @runInSeparateProcess + */ + public function testGetFlashKeysOnlyReturnsFlashKeys() + { + $session = $this->getInstance(); + $session->start(); + + $session->setFlashdata('foo', 'bar'); + $session->set('bar', 'baz'); + + $keys = $session->getFlashKeys(); + + $this->assertContains('foo', $keys); + $this->assertNotContains('bar', $keys); + } + + /** + * @runInSeparateProcess + */ + public function testSetTempDataWorks() + { + $session = $this->getInstance(); + $session->start(); + + $session->setTempdata('foo', 'bar', 300); + $this->assertGreaterThanOrEqual($_SESSION['__ci_vars']['foo'], time() + 300); + } + + /** + * @runInSeparateProcess + */ + public function testSetTempDataArrayMultiTTL() + { + $session = $this->getInstance(); + $session->start(); + + $time = time(); + + $session->setTempdata([ + 'foo' => 300, + 'bar' => 400, + 'baz' => 100 + ]); + + $this->assertLessThanOrEqual($_SESSION['__ci_vars']['foo'], $time + 300); + $this->assertLessThanOrEqual($_SESSION['__ci_vars']['bar'], $time + 400); + $this->assertLessThanOrEqual($_SESSION['__ci_vars']['baz'], $time + 100); + } + + /** + * @runInSeparateProcess + */ + public function testSetTempDataArraySingleTTL() + { + $session = $this->getInstance(); + $session->start(); + + $time = time(); + + $session->setTempdata(['foo', 'bar', 'baz'], null, 200); + + $this->assertLessThanOrEqual($_SESSION['__ci_vars']['foo'], $time + 200); + $this->assertLessThanOrEqual($_SESSION['__ci_vars']['bar'], $time + 200); + $this->assertLessThanOrEqual($_SESSION['__ci_vars']['baz'], $time + 200); + } + + /** + * @group single + * @runInSeparateProcess + */ + public function testGetTestDataReturnsAll() + { + $session = $this->getInstance(); + $session->start(); + + $data = [ + 'foo' => 'bar', + 'bar' => 'baz' + ]; + + $session->setTempdata($data); + $session->set('baz', 'ballywhoo'); + + $this->assertEquals($data, $session->getTempdata()); + } + + /** + * @runInSeparateProcess + */ + public function testGetTestDataReturnsSingle() + { + $session = $this->getInstance(); + $session->start(); + + $data = [ + 'foo' => 'bar', + 'bar' => 'baz' + ]; + + $session->setTempdata($data); + + $this->assertEquals('bar', $session->getTempdata('foo')); + } + + /** + * @runInSeparateProcess + */ + public function testRemoveTempDataActuallyDeletes() + { + $session = $this->getInstance(); + $session->start(); + + $data = [ + 'foo' => 'bar', + 'bar' => 'baz' + ]; + + $session->setTempdata($data); + $session->removeTempdata('foo'); + + $this->assertEquals(['bar' => 'baz'], $session->getTempdata()); + } + + /** + * @runInSeparateProcess + */ + public function testUnMarkTempDataSingle() + { + $session = $this->getInstance(); + $session->start(); + + $data = [ + 'foo' => 'bar', + 'bar' => 'baz' + ]; + + $session->setTempdata($data); + $session->unmarkTempdata('foo'); + + $this->assertEquals(['bar' => 'baz'], $session->getTempdata()); + } + + /** + * @runInSeparateProcess + */ + public function testUnMarkTempDataArray() + { + $session = $this->getInstance(); + $session->start(); + + $data = [ + 'foo' => 'bar', + 'bar' => 'baz' + ]; + + $session->setTempdata($data); + $session->unmarkTempdata(['foo', 'bar']); + + $this->assertEquals([], $session->getTempdata()); + } + + /** + * @runInSeparateProcess + */ + public function testGetTempdataKeys() + { + $session = $this->getInstance(); + $session->start(); + + $data = [ + 'foo' => 'bar', + 'bar' => 'baz' + ]; + + $session->setTempdata($data); + $session->set('baz', 'ballywhoo'); + + $this->assertEquals(['foo', 'bar'], $session->getTempKeys()); + } } From 6c7329092a20c24f982320c11c990249a95d4e70 Mon Sep 17 00:00:00 2001 From: Andrei Furnica Date: Wed, 1 Aug 2018 13:09:31 +0300 Subject: [PATCH 03/10] Revert "tabs, not spaces" This reverts commit 9a317e8 --- tests/system/Session/SessionTest.php | 1010 +++++++++++++------------- 1 file changed, 505 insertions(+), 505 deletions(-) diff --git a/tests/system/Session/SessionTest.php b/tests/system/Session/SessionTest.php index a216b82f3786..7f0a319c592d 100644 --- a/tests/system/Session/SessionTest.php +++ b/tests/system/Session/SessionTest.php @@ -7,131 +7,131 @@ class SessionTest extends \CIUnitTestCase { - public function setUp() - { - parent::setUp(); - - $_COOKIE = []; - $_SESSION = []; - } - - public function tearDown() - { - - } - - protected function getInstance($options = []) - { - $defaults = [ - 'sessionDriver' => 'CodeIgniter\Session\Handlers\FileHandler', - 'sessionCookieName' => 'ci_session', - 'sessionExpiration' => 7200, - 'sessionSavePath' => null, - 'sessionMatchIP' => false, - 'sessionTimeToUpdate' => 300, - 'sessionRegenerateDestroy' => false, - 'cookieDomain' => '', - 'cookiePrefix' => '', - 'cookiePath' => '/', - 'cookieSecure' => false, - ]; - - $config = array_merge($defaults, $options); - $config = (object)$config; - - $session = new MockSession(new FileHandler($config), $config); - $session->setLogger(new TestLogger(new Logger())); - - return $session; - } - - /** - * @runInSeparateProcess - */ - public function testSessionSetsRegenerateTime() - { - $session = $this->getInstance(); - $session->start(); - - $this->assertTrue(isset($_SESSION['__ci_last_regenerate']) && !empty($_SESSION['__ci_last_regenerate'])); - } - - /** - * @runInSeparateProcess - */ - public function testWillRegenerateSessionAutomatically() - { - $session = $this->getInstance(); - - $time = time() - 400; - $_SESSION['__ci_last_regenerate'] = $time; - $session->start(); - - $this->assertTrue($session->didRegenerate); - $this->assertGreaterThan($time + 90, $_SESSION['__ci_last_regenerate']); - } - - /** - * @runInSeparateProcess - */ - public function testCanSetSingleValue() - { - $session = $this->getInstance(); - $session->start(); - - $session->set('foo', 'bar'); - - $this->assertEquals('bar', $_SESSION['foo']); - } - - /** - * @runInSeparateProcess - */ - public function testCanSetArray() - { - $session = $this->getInstance(); - $session->start(); - - $session->set([ - 'foo' => 'bar', - 'bar' => 'baz' - ]); - - $this->assertEquals('bar', $_SESSION['foo']); - $this->assertEquals('baz', $_SESSION['bar']); - $this->assertArrayNotHasKey('__ci_vars', $_SESSION); - } - - /** - * @runInSeparateProcess - */ - public function testGetSimpleKey() - { - $session = $this->getInstance(); - $session->start(); - - $session->set('foo', 'bar'); - - $this->assertEquals('bar', $session->get('foo')); - } - - /** - * @runInSeparateProcess - */ - public function testGetReturnsNullWhenNotFound() - { - $_SESSION = []; - - $session = $this->getInstance(); - $session->start(); - - $this->assertNull($session->get('foo')); - } - - /** - * @runInSeparateProcess - */ - public function testGetReturnsAllWithNoKeys() + public function setUp() + { + parent::setUp(); + + $_COOKIE = []; + $_SESSION = []; + } + + public function tearDown() + { + + } + + protected function getInstance($options=[]) + { + $defaults = [ + 'sessionDriver' => 'CodeIgniter\Session\Handlers\FileHandler', + 'sessionCookieName' => 'ci_session', + 'sessionExpiration' => 7200, + 'sessionSavePath' => null, + 'sessionMatchIP' => false, + 'sessionTimeToUpdate' => 300, + 'sessionRegenerateDestroy' => false, + 'cookieDomain' => '', + 'cookiePrefix' => '', + 'cookiePath' => '/', + 'cookieSecure' => false, + ]; + + $config = array_merge($defaults, $options); + $config = (object)$config; + + $session = new MockSession(new FileHandler($config), $config); + $session->setLogger(new TestLogger(new Logger())); + + return $session; + } + + /** + * @runInSeparateProcess + */ + public function testSessionSetsRegenerateTime() + { + $session = $this->getInstance(); + $session->start(); + + $this->assertTrue(isset($_SESSION['__ci_last_regenerate']) && ! empty($_SESSION['__ci_last_regenerate'])); + } + + /** + * @runInSeparateProcess + */ + public function testWillRegenerateSessionAutomatically() + { + $session = $this->getInstance(); + + $time = time()-400; + $_SESSION['__ci_last_regenerate'] = $time; + $session->start(); + + $this->assertTrue($session->didRegenerate); + $this->assertGreaterThan($time + 90 ,$_SESSION['__ci_last_regenerate']); + } + + /** + * @runInSeparateProcess + */ + public function testCanSetSingleValue() + { + $session = $this->getInstance(); + $session->start(); + + $session->set('foo', 'bar'); + + $this->assertEquals('bar', $_SESSION['foo']); + } + + /** + * @runInSeparateProcess + */ + public function testCanSetArray() + { + $session = $this->getInstance(); + $session->start(); + + $session->set([ + 'foo' => 'bar', + 'bar' => 'baz' + ]); + + $this->assertEquals('bar', $_SESSION['foo']); + $this->assertEquals('baz', $_SESSION['bar']); + $this->assertArrayNotHasKey('__ci_vars', $_SESSION); + } + + /** + * @runInSeparateProcess + */ + public function testGetSimpleKey() + { + $session = $this->getInstance(); + $session->start(); + + $session->set('foo', 'bar'); + + $this->assertEquals('bar', $session->get('foo')); + } + + /** + * @runInSeparateProcess + */ + public function testGetReturnsNullWhenNotFound() + { + $_SESSION = []; + + $session = $this->getInstance(); + $session->start(); + + $this->assertNull($session->get('foo')); + } + + /** + * @runInSeparateProcess + */ + public function testGetReturnsAllWithNoKeys() { $_SESSION = [ 'foo' => 'bar', @@ -145,384 +145,384 @@ public function testGetReturnsAllWithNoKeys() $this->assertTrue(array_key_exists('foo', $result)); $this->assertTrue(array_key_exists('bar', $result)); - } - - /** - * @runInSeparateProcess - */ - public function testGetAsProperty() - { - $session = $this->getInstance(); - $session->start(); - - $session->set('foo', 'bar'); - - $this->assertEquals('bar', $session->foo); - } - - /** - * @runInSeparateProcess - */ - public function testGetAsNormal() - { - $session = $this->getInstance(); - $session->start(); - - $session->set('foo', 'bar'); - - $this->assertEquals('bar', $_SESSION['foo']); - } - - /** - * @runInSeparateProcess - */ - public function testHasReturnsTrueOnSuccess() - { - $session = $this->getInstance(); - $session->start(); - - $_SESSION['foo'] = 'bar'; - - $this->assertTrue($session->has('foo')); - } - - /** - * @runInSeparateProcess - */ - public function testHasReturnsFalseOnNotFound() - { - $session = $this->getInstance(); - $session->start(); - - $_SESSION['foo'] = 'bar'; - - $this->assertFalse($session->has('bar')); - } - - /** - * @runInSeparateProcess - */ - public function testRemoveActuallyRemoves() - { - $session = $this->getInstance(); - $session->start(); - - $_SESSION['foo'] = 'bar'; - $session->remove('foo'); - - $this->assertArrayNotHasKey('foo', $_SESSION); - $this->assertFalse($session->has('foo')); - } - - /** - * @runInSeparateProcess - */ - public function testHasReturnsCanRemoveArray() - { - $session = $this->getInstance(); - $session->start(); - - $_SESSION = [ - 'foo' => 'bar', - 'bar' => 'baz' - ]; - - $this->assertTrue($session->has('foo')); - - $session->remove(['foo', 'bar']); - - $this->assertArrayNotHasKey('foo', $_SESSION); - $this->assertArrayNotHasKey('bar', $_SESSION); - } - - /** - * @runInSeparateProcess - */ - public function testSetMagicMethod() - { - $session = $this->getInstance(); - $session->start(); - - $session->foo = 'bar'; - - $this->assertArrayHasKey('foo', $_SESSION); - $this->assertEquals('bar', $_SESSION['foo']); - } - - /** - * @runInSeparateProcess - */ - public function testCanFlashData() - { - $session = $this->getInstance(); - $session->start(); - - $session->setFlashdata('foo', 'bar'); - - $this->assertTrue($session->has('foo')); - $this->assertEquals('new', $_SESSION['__ci_vars']['foo']); - - // Should reset the 'new' to 'old' - $session->start(); - - $this->assertTrue($session->has('foo')); - $this->assertEquals('old', $_SESSION['__ci_vars']['foo']); - - // Should no longer be available - $session->start(); - - $this->assertFalse($session->has('foo')); - } - - /** - * @runInSeparateProcess - */ - public function testCanFlashArray() - { - $session = $this->getInstance(); - $session->start(); - - $session->setFlashdata([ - 'foo' => 'bar', - 'bar' => 'baz' - ]); - - $this->assertTrue($session->has('foo')); - $this->assertEquals('new', $_SESSION['__ci_vars']['foo']); - $this->assertTrue($session->has('bar')); - $this->assertEquals('new', $_SESSION['__ci_vars']['bar']); - } - - /** - * @runInSeparateProcess - */ - public function testKeepFlashData() - { - $session = $this->getInstance(); - $session->start(); - - $session->setFlashdata('foo', 'bar'); - - $this->assertTrue($session->has('foo')); - $this->assertEquals('new', $_SESSION['__ci_vars']['foo']); - - // Should reset the 'new' to 'old' - $session->start(); - - $this->assertTrue($session->has('foo')); - $this->assertEquals('old', $_SESSION['__ci_vars']['foo']); - - $session->keepFlashdata('foo'); - - $this->assertEquals('new', $_SESSION['__ci_vars']['foo']); - - // Should no longer be available - $session->start(); - - $this->assertTrue($session->has('foo')); - $this->assertEquals('old', $_SESSION['__ci_vars']['foo']); - } - - /** - * @runInSeparateProcess - */ - public function testUnmarkFlashDataRemovesData() - { - $session = $this->getInstance(); - $session->start(); - - $session->setFlashdata('foo', 'bar'); - $session->set('bar', 'baz'); - - $this->assertTrue($session->has('foo')); - $this->assertArrayHasKey('foo', $_SESSION['__ci_vars']); - - $session->unmarkFlashdata('foo'); - - // Should still be here - $this->assertTrue($session->has('foo')); - // but no longer marked as flash - $this->assertFalse(isset($_SESSION['__ci_vars']['foo'])); - } - - /** - * @runInSeparateProcess - */ - public function testGetFlashKeysOnlyReturnsFlashKeys() - { - $session = $this->getInstance(); - $session->start(); - - $session->setFlashdata('foo', 'bar'); - $session->set('bar', 'baz'); - - $keys = $session->getFlashKeys(); - - $this->assertContains('foo', $keys); - $this->assertNotContains('bar', $keys); - } - - /** - * @runInSeparateProcess - */ - public function testSetTempDataWorks() - { - $session = $this->getInstance(); - $session->start(); - - $session->setTempdata('foo', 'bar', 300); - $this->assertGreaterThanOrEqual($_SESSION['__ci_vars']['foo'], time() + 300); - } - - /** - * @runInSeparateProcess - */ - public function testSetTempDataArrayMultiTTL() - { - $session = $this->getInstance(); - $session->start(); - - $time = time(); - - $session->setTempdata([ - 'foo' => 300, - 'bar' => 400, - 'baz' => 100 - ]); - - $this->assertLessThanOrEqual($_SESSION['__ci_vars']['foo'], $time + 300); - $this->assertLessThanOrEqual($_SESSION['__ci_vars']['bar'], $time + 400); - $this->assertLessThanOrEqual($_SESSION['__ci_vars']['baz'], $time + 100); - } - - /** - * @runInSeparateProcess - */ - public function testSetTempDataArraySingleTTL() - { - $session = $this->getInstance(); - $session->start(); - - $time = time(); - - $session->setTempdata(['foo', 'bar', 'baz'], null, 200); - - $this->assertLessThanOrEqual($_SESSION['__ci_vars']['foo'], $time + 200); - $this->assertLessThanOrEqual($_SESSION['__ci_vars']['bar'], $time + 200); - $this->assertLessThanOrEqual($_SESSION['__ci_vars']['baz'], $time + 200); - } - - /** - * @group single - * @runInSeparateProcess - */ - public function testGetTestDataReturnsAll() - { - $session = $this->getInstance(); - $session->start(); - - $data = [ - 'foo' => 'bar', - 'bar' => 'baz' - ]; - - $session->setTempdata($data); - $session->set('baz', 'ballywhoo'); - - $this->assertEquals($data, $session->getTempdata()); - } - - /** - * @runInSeparateProcess - */ - public function testGetTestDataReturnsSingle() - { - $session = $this->getInstance(); - $session->start(); - - $data = [ - 'foo' => 'bar', - 'bar' => 'baz' - ]; - - $session->setTempdata($data); - - $this->assertEquals('bar', $session->getTempdata('foo')); - } - - /** - * @runInSeparateProcess - */ - public function testRemoveTempDataActuallyDeletes() - { - $session = $this->getInstance(); - $session->start(); - - $data = [ - 'foo' => 'bar', - 'bar' => 'baz' - ]; - - $session->setTempdata($data); - $session->removeTempdata('foo'); - - $this->assertEquals(['bar' => 'baz'], $session->getTempdata()); - } - - /** - * @runInSeparateProcess - */ - public function testUnMarkTempDataSingle() - { - $session = $this->getInstance(); - $session->start(); - - $data = [ - 'foo' => 'bar', - 'bar' => 'baz' - ]; - - $session->setTempdata($data); - $session->unmarkTempdata('foo'); - - $this->assertEquals(['bar' => 'baz'], $session->getTempdata()); - } - - /** - * @runInSeparateProcess - */ - public function testUnMarkTempDataArray() - { - $session = $this->getInstance(); - $session->start(); - - $data = [ - 'foo' => 'bar', - 'bar' => 'baz' - ]; - - $session->setTempdata($data); - $session->unmarkTempdata(['foo', 'bar']); - - $this->assertEquals([], $session->getTempdata()); - } - - /** - * @runInSeparateProcess - */ - public function testGetTempdataKeys() - { - $session = $this->getInstance(); - $session->start(); - - $data = [ - 'foo' => 'bar', - 'bar' => 'baz' - ]; - - $session->setTempdata($data); - $session->set('baz', 'ballywhoo'); - - $this->assertEquals(['foo', 'bar'], $session->getTempKeys()); - } + } + + /** + * @runInSeparateProcess + */ + public function testGetAsProperty() + { + $session = $this->getInstance(); + $session->start(); + + $session->set('foo', 'bar'); + + $this->assertEquals('bar', $session->foo); + } + + /** + * @runInSeparateProcess + */ + public function testGetAsNormal() + { + $session = $this->getInstance(); + $session->start(); + + $session->set('foo', 'bar'); + + $this->assertEquals('bar', $_SESSION['foo']); + } + + /** + * @runInSeparateProcess + */ + public function testHasReturnsTrueOnSuccess() + { + $session = $this->getInstance(); + $session->start(); + + $_SESSION['foo'] = 'bar'; + + $this->assertTrue($session->has('foo')); + } + + /** + * @runInSeparateProcess + */ + public function testHasReturnsFalseOnNotFound() + { + $session = $this->getInstance(); + $session->start(); + + $_SESSION['foo'] = 'bar'; + + $this->assertFalse($session->has('bar')); + } + + /** + * @runInSeparateProcess + */ + public function testRemoveActuallyRemoves() + { + $session = $this->getInstance(); + $session->start(); + + $_SESSION['foo'] = 'bar'; + $session->remove('foo'); + + $this->assertArrayNotHasKey('foo', $_SESSION); + $this->assertFalse($session->has('foo')); + } + + /** + * @runInSeparateProcess + */ + public function testHasReturnsCanRemoveArray() + { + $session = $this->getInstance(); + $session->start(); + + $_SESSION = [ + 'foo' => 'bar', + 'bar' => 'baz' + ]; + + $this->assertTrue($session->has('foo')); + + $session->remove(['foo', 'bar']); + + $this->assertArrayNotHasKey('foo', $_SESSION); + $this->assertArrayNotHasKey('bar', $_SESSION); + } + + /** + * @runInSeparateProcess + */ + public function testSetMagicMethod() + { + $session = $this->getInstance(); + $session->start(); + + $session->foo = 'bar'; + + $this->assertArrayHasKey('foo', $_SESSION); + $this->assertEquals('bar', $_SESSION['foo']); + } + + /** + * @runInSeparateProcess + */ + public function testCanFlashData() + { + $session = $this->getInstance(); + $session->start(); + + $session->setFlashdata('foo', 'bar'); + + $this->assertTrue($session->has('foo')); + $this->assertEquals('new', $_SESSION['__ci_vars']['foo']); + + // Should reset the 'new' to 'old' + $session->start(); + + $this->assertTrue($session->has('foo')); + $this->assertEquals('old', $_SESSION['__ci_vars']['foo']); + + // Should no longer be available + $session->start(); + + $this->assertFalse($session->has('foo')); + } + + /** + * @runInSeparateProcess + */ + public function testCanFlashArray() + { + $session = $this->getInstance(); + $session->start(); + + $session->setFlashdata([ + 'foo' => 'bar', + 'bar' => 'baz' + ]); + + $this->assertTrue($session->has('foo')); + $this->assertEquals('new', $_SESSION['__ci_vars']['foo']); + $this->assertTrue($session->has('bar')); + $this->assertEquals('new', $_SESSION['__ci_vars']['bar']); + } + + /** + * @runInSeparateProcess + */ + public function testKeepFlashData() + { + $session = $this->getInstance(); + $session->start(); + + $session->setFlashdata('foo', 'bar'); + + $this->assertTrue($session->has('foo')); + $this->assertEquals('new', $_SESSION['__ci_vars']['foo']); + + // Should reset the 'new' to 'old' + $session->start(); + + $this->assertTrue($session->has('foo')); + $this->assertEquals('old', $_SESSION['__ci_vars']['foo']); + + $session->keepFlashdata('foo'); + + $this->assertEquals('new', $_SESSION['__ci_vars']['foo']); + + // Should no longer be available + $session->start(); + + $this->assertTrue($session->has('foo')); + $this->assertEquals('old', $_SESSION['__ci_vars']['foo']); + } + + /** + * @runInSeparateProcess + */ + public function testUnmarkFlashDataRemovesData() + { + $session = $this->getInstance(); + $session->start(); + + $session->setFlashdata('foo', 'bar'); + $session->set('bar', 'baz'); + + $this->assertTrue($session->has('foo')); + $this->assertArrayHasKey('foo', $_SESSION['__ci_vars']); + + $session->unmarkFlashdata('foo'); + + // Should still be here + $this->assertTrue($session->has('foo')); + // but no longer marked as flash + $this->assertFalse(isset($_SESSION['__ci_vars']['foo'])); + } + + /** + * @runInSeparateProcess + */ + public function testGetFlashKeysOnlyReturnsFlashKeys() + { + $session = $this->getInstance(); + $session->start(); + + $session->setFlashdata('foo', 'bar'); + $session->set('bar', 'baz'); + + $keys = $session->getFlashKeys(); + + $this->assertContains('foo', $keys); + $this->assertNotContains('bar', $keys); + } + + /** + * @runInSeparateProcess + */ + public function testSetTempDataWorks() + { + $session = $this->getInstance(); + $session->start(); + + $session->setTempdata('foo', 'bar', 300); + $this->assertGreaterThanOrEqual($_SESSION['__ci_vars']['foo'], time() + 300); + } + + /** + * @runInSeparateProcess + */ + public function testSetTempDataArrayMultiTTL() + { + $session = $this->getInstance(); + $session->start(); + + $time = time(); + + $session->setTempdata([ + 'foo' => 300, + 'bar' => 400, + 'baz' => 100 + ]); + + $this->assertLessThanOrEqual($_SESSION['__ci_vars']['foo'], $time + 300); + $this->assertLessThanOrEqual($_SESSION['__ci_vars']['bar'], $time + 400); + $this->assertLessThanOrEqual($_SESSION['__ci_vars']['baz'], $time + 100); + } + + /** + * @runInSeparateProcess + */ + public function testSetTempDataArraySingleTTL() + { + $session = $this->getInstance(); + $session->start(); + + $time = time(); + + $session->setTempdata(['foo', 'bar', 'baz'], null, 200); + + $this->assertLessThanOrEqual($_SESSION['__ci_vars']['foo'], $time + 200); + $this->assertLessThanOrEqual($_SESSION['__ci_vars']['bar'], $time + 200); + $this->assertLessThanOrEqual($_SESSION['__ci_vars']['baz'], $time + 200); + } + + /** + * @group single + * @runInSeparateProcess + */ + public function testGetTestDataReturnsAll() + { + $session = $this->getInstance(); + $session->start(); + + $data = [ + 'foo' => 'bar', + 'bar' => 'baz' + ]; + + $session->setTempdata($data); + $session->set('baz', 'ballywhoo'); + + $this->assertEquals($data, $session->getTempdata()); + } + + /** + * @runInSeparateProcess + */ + public function testGetTestDataReturnsSingle() + { + $session = $this->getInstance(); + $session->start(); + + $data = [ + 'foo' => 'bar', + 'bar' => 'baz' + ]; + + $session->setTempdata($data); + + $this->assertEquals('bar', $session->getTempdata('foo')); + } + + /** + * @runInSeparateProcess + */ + public function testRemoveTempDataActuallyDeletes() + { + $session = $this->getInstance(); + $session->start(); + + $data = [ + 'foo' => 'bar', + 'bar' => 'baz' + ]; + + $session->setTempdata($data); + $session->removeTempdata('foo'); + + $this->assertEquals(['bar' => 'baz'], $session->getTempdata()); + } + + /** + * @runInSeparateProcess + */ + public function testUnMarkTempDataSingle() + { + $session = $this->getInstance(); + $session->start(); + + $data = [ + 'foo' => 'bar', + 'bar' => 'baz' + ]; + + $session->setTempdata($data); + $session->unmarkTempdata('foo'); + + $this->assertEquals(['bar' => 'baz'], $session->getTempdata()); + } + + /** + * @runInSeparateProcess + */ + public function testUnMarkTempDataArray() + { + $session = $this->getInstance(); + $session->start(); + + $data = [ + 'foo' => 'bar', + 'bar' => 'baz' + ]; + + $session->setTempdata($data); + $session->unmarkTempdata(['foo', 'bar']); + + $this->assertEquals([], $session->getTempdata()); + } + + /** + * @runInSeparateProcess + */ + public function testGetTempdataKeys() + { + $session = $this->getInstance(); + $session->start(); + + $data = [ + 'foo' => 'bar', + 'bar' => 'baz' + ]; + + $session->setTempdata($data); + $session->set('baz', 'ballywhoo'); + + $this->assertEquals(['foo', 'bar'], $session->getTempKeys()); + } } From 603468cfad63f53c1443632722bc1ac07cec4458 Mon Sep 17 00:00:00 2001 From: Andrei Furnica Date: Wed, 1 Aug 2018 13:39:21 +0300 Subject: [PATCH 04/10] defined or define --- application/Config/Boot/testing.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/Config/Boot/testing.php b/application/Config/Boot/testing.php index f3c7f1c7c6d2..ff3262fdb8dc 100644 --- a/application/Config/Boot/testing.php +++ b/application/Config/Boot/testing.php @@ -19,7 +19,7 @@ | backtraces along with the other error information. If you would | prefer to not see this, set this value to false. */ -define('SHOW_DEBUG_BACKTRACE', true); +defined('SHOW_DEBUG_BACKTRACE') or define('SHOW_DEBUG_BACKTRACE', true); /* |-------------------------------------------------------------------------- @@ -30,4 +30,4 @@ | release of the framework. */ -define('CI_DEBUG', 1); +defined('CI_DEBUG') or define('CI_DEBUG', 1); From 0d16b33326be02c1f90841b640c8ff0e4e72207f Mon Sep 17 00:00:00 2001 From: Andrei Furnica Date: Thu, 2 Aug 2018 14:27:13 +0300 Subject: [PATCH 05/10] mark whole session test class to run as separate process and don't preserve global state --- tests/system/Session/SessionTest.php | 86 ++-------------------------- 1 file changed, 4 insertions(+), 82 deletions(-) diff --git a/tests/system/Session/SessionTest.php b/tests/system/Session/SessionTest.php index 7f0a319c592d..bba8db126928 100644 --- a/tests/system/Session/SessionTest.php +++ b/tests/system/Session/SessionTest.php @@ -5,6 +5,10 @@ use Tests\Support\Session\MockSession; use CodeIgniter\Session\Handlers\FileHandler; +/** + * @runTestsInSeparateProcesses + * @preserveGlobalState disabled + */ class SessionTest extends \CIUnitTestCase { public function setUp() @@ -45,9 +49,6 @@ protected function getInstance($options=[]) return $session; } - /** - * @runInSeparateProcess - */ public function testSessionSetsRegenerateTime() { $session = $this->getInstance(); @@ -56,9 +57,6 @@ public function testSessionSetsRegenerateTime() $this->assertTrue(isset($_SESSION['__ci_last_regenerate']) && ! empty($_SESSION['__ci_last_regenerate'])); } - /** - * @runInSeparateProcess - */ public function testWillRegenerateSessionAutomatically() { $session = $this->getInstance(); @@ -71,9 +69,6 @@ public function testWillRegenerateSessionAutomatically() $this->assertGreaterThan($time + 90 ,$_SESSION['__ci_last_regenerate']); } - /** - * @runInSeparateProcess - */ public function testCanSetSingleValue() { $session = $this->getInstance(); @@ -84,9 +79,6 @@ public function testCanSetSingleValue() $this->assertEquals('bar', $_SESSION['foo']); } - /** - * @runInSeparateProcess - */ public function testCanSetArray() { $session = $this->getInstance(); @@ -102,9 +94,6 @@ public function testCanSetArray() $this->assertArrayNotHasKey('__ci_vars', $_SESSION); } - /** - * @runInSeparateProcess - */ public function testGetSimpleKey() { $session = $this->getInstance(); @@ -115,9 +104,6 @@ public function testGetSimpleKey() $this->assertEquals('bar', $session->get('foo')); } - /** - * @runInSeparateProcess - */ public function testGetReturnsNullWhenNotFound() { $_SESSION = []; @@ -128,9 +114,6 @@ public function testGetReturnsNullWhenNotFound() $this->assertNull($session->get('foo')); } - /** - * @runInSeparateProcess - */ public function testGetReturnsAllWithNoKeys() { $_SESSION = [ @@ -147,9 +130,6 @@ public function testGetReturnsAllWithNoKeys() $this->assertTrue(array_key_exists('bar', $result)); } - /** - * @runInSeparateProcess - */ public function testGetAsProperty() { $session = $this->getInstance(); @@ -160,9 +140,6 @@ public function testGetAsProperty() $this->assertEquals('bar', $session->foo); } - /** - * @runInSeparateProcess - */ public function testGetAsNormal() { $session = $this->getInstance(); @@ -173,9 +150,6 @@ public function testGetAsNormal() $this->assertEquals('bar', $_SESSION['foo']); } - /** - * @runInSeparateProcess - */ public function testHasReturnsTrueOnSuccess() { $session = $this->getInstance(); @@ -186,9 +160,6 @@ public function testHasReturnsTrueOnSuccess() $this->assertTrue($session->has('foo')); } - /** - * @runInSeparateProcess - */ public function testHasReturnsFalseOnNotFound() { $session = $this->getInstance(); @@ -199,9 +170,6 @@ public function testHasReturnsFalseOnNotFound() $this->assertFalse($session->has('bar')); } - /** - * @runInSeparateProcess - */ public function testRemoveActuallyRemoves() { $session = $this->getInstance(); @@ -214,9 +182,6 @@ public function testRemoveActuallyRemoves() $this->assertFalse($session->has('foo')); } - /** - * @runInSeparateProcess - */ public function testHasReturnsCanRemoveArray() { $session = $this->getInstance(); @@ -235,9 +200,6 @@ public function testHasReturnsCanRemoveArray() $this->assertArrayNotHasKey('bar', $_SESSION); } - /** - * @runInSeparateProcess - */ public function testSetMagicMethod() { $session = $this->getInstance(); @@ -249,9 +211,6 @@ public function testSetMagicMethod() $this->assertEquals('bar', $_SESSION['foo']); } - /** - * @runInSeparateProcess - */ public function testCanFlashData() { $session = $this->getInstance(); @@ -274,9 +233,6 @@ public function testCanFlashData() $this->assertFalse($session->has('foo')); } - /** - * @runInSeparateProcess - */ public function testCanFlashArray() { $session = $this->getInstance(); @@ -293,9 +249,6 @@ public function testCanFlashArray() $this->assertEquals('new', $_SESSION['__ci_vars']['bar']); } - /** - * @runInSeparateProcess - */ public function testKeepFlashData() { $session = $this->getInstance(); @@ -323,9 +276,6 @@ public function testKeepFlashData() $this->assertEquals('old', $_SESSION['__ci_vars']['foo']); } - /** - * @runInSeparateProcess - */ public function testUnmarkFlashDataRemovesData() { $session = $this->getInstance(); @@ -345,9 +295,6 @@ public function testUnmarkFlashDataRemovesData() $this->assertFalse(isset($_SESSION['__ci_vars']['foo'])); } - /** - * @runInSeparateProcess - */ public function testGetFlashKeysOnlyReturnsFlashKeys() { $session = $this->getInstance(); @@ -362,9 +309,6 @@ public function testGetFlashKeysOnlyReturnsFlashKeys() $this->assertNotContains('bar', $keys); } - /** - * @runInSeparateProcess - */ public function testSetTempDataWorks() { $session = $this->getInstance(); @@ -374,9 +318,6 @@ public function testSetTempDataWorks() $this->assertGreaterThanOrEqual($_SESSION['__ci_vars']['foo'], time() + 300); } - /** - * @runInSeparateProcess - */ public function testSetTempDataArrayMultiTTL() { $session = $this->getInstance(); @@ -395,9 +336,6 @@ public function testSetTempDataArrayMultiTTL() $this->assertLessThanOrEqual($_SESSION['__ci_vars']['baz'], $time + 100); } - /** - * @runInSeparateProcess - */ public function testSetTempDataArraySingleTTL() { $session = $this->getInstance(); @@ -414,7 +352,6 @@ public function testSetTempDataArraySingleTTL() /** * @group single - * @runInSeparateProcess */ public function testGetTestDataReturnsAll() { @@ -432,9 +369,6 @@ public function testGetTestDataReturnsAll() $this->assertEquals($data, $session->getTempdata()); } - /** - * @runInSeparateProcess - */ public function testGetTestDataReturnsSingle() { $session = $this->getInstance(); @@ -450,9 +384,6 @@ public function testGetTestDataReturnsSingle() $this->assertEquals('bar', $session->getTempdata('foo')); } - /** - * @runInSeparateProcess - */ public function testRemoveTempDataActuallyDeletes() { $session = $this->getInstance(); @@ -469,9 +400,6 @@ public function testRemoveTempDataActuallyDeletes() $this->assertEquals(['bar' => 'baz'], $session->getTempdata()); } - /** - * @runInSeparateProcess - */ public function testUnMarkTempDataSingle() { $session = $this->getInstance(); @@ -488,9 +416,6 @@ public function testUnMarkTempDataSingle() $this->assertEquals(['bar' => 'baz'], $session->getTempdata()); } - /** - * @runInSeparateProcess - */ public function testUnMarkTempDataArray() { $session = $this->getInstance(); @@ -507,9 +432,6 @@ public function testUnMarkTempDataArray() $this->assertEquals([], $session->getTempdata()); } - /** - * @runInSeparateProcess - */ public function testGetTempdataKeys() { $session = $this->getInstance(); From ee5f6a5355dc1dc9914441168e872a6212f710d1 Mon Sep 17 00:00:00 2001 From: Andrei Furnica Date: Thu, 2 Aug 2018 14:36:24 +0300 Subject: [PATCH 06/10] mark all tests that use session to run as separate processes and not share global state --- application/Config/Boot/testing.php | 4 ++-- tests/system/CommonFunctionsTest.php | 12 ++++++++++++ tests/system/Config/ServicesTest.php | 12 ++++++++++++ tests/system/HTTP/RedirectResponseTest.php | 12 ++++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/application/Config/Boot/testing.php b/application/Config/Boot/testing.php index ff3262fdb8dc..f3c7f1c7c6d2 100644 --- a/application/Config/Boot/testing.php +++ b/application/Config/Boot/testing.php @@ -19,7 +19,7 @@ | backtraces along with the other error information. If you would | prefer to not see this, set this value to false. */ -defined('SHOW_DEBUG_BACKTRACE') or define('SHOW_DEBUG_BACKTRACE', true); +define('SHOW_DEBUG_BACKTRACE', true); /* |-------------------------------------------------------------------------- @@ -30,4 +30,4 @@ | release of the framework. */ -defined('CI_DEBUG') or define('CI_DEBUG', 1); +define('CI_DEBUG', 1); diff --git a/tests/system/CommonFunctionsTest.php b/tests/system/CommonFunctionsTest.php index 0c88d29c2525..10df01699790 100644 --- a/tests/system/CommonFunctionsTest.php +++ b/tests/system/CommonFunctionsTest.php @@ -156,17 +156,29 @@ public function testEscapeBadContext() // ------------------------------------------------------------------------ + /** + * @runTestsInSeparateProcesses + * @preserveGlobalState disabled + */ public function testSessionInstance() { $this->assertInstanceOf(CodeIgniter\Session\Session::class, session()); } + /** + * @runTestsInSeparateProcesses + * @preserveGlobalState disabled + */ public function testSessionVariable() { $_SESSION['notbogus'] = 'Hi there'; $this->assertEquals('Hi there', session('notbogus')); } + /** + * @runTestsInSeparateProcesses + * @preserveGlobalState disabled + */ public function testSessionVariableNotThere() { $_SESSION['bogus'] = 'Hi there'; diff --git a/tests/system/Config/ServicesTest.php b/tests/system/Config/ServicesTest.php index 9fe949d14b1f..9fc5061c3f62 100644 --- a/tests/system/Config/ServicesTest.php +++ b/tests/system/Config/ServicesTest.php @@ -129,18 +129,30 @@ public function testNewViewcell() $this->assertInstanceOf(\CodeIgniter\View\Cell::class, $actual); } + /** + * @runTestsInSeparateProcesses + * @preserveGlobalState disabled + */ public function testNewSession() { $actual = Services::session($this->config); $this->assertInstanceOf(\CodeIgniter\Session\Session::class, $actual); } + /** + * @runTestsInSeparateProcesses + * @preserveGlobalState disabled + */ public function testNewSessionWithNullConfig() { $actual = Services::session(null, false); $this->assertInstanceOf(\CodeIgniter\Session\Session::class, $actual); } + /** + * @runTestsInSeparateProcesses + * @preserveGlobalState disabled + */ public function testCallStatic() { // __callStatic should kick in for this but fail diff --git a/tests/system/HTTP/RedirectResponseTest.php b/tests/system/HTTP/RedirectResponseTest.php index d5e0a8ac1855..3bdaaa72abe8 100644 --- a/tests/system/HTTP/RedirectResponseTest.php +++ b/tests/system/HTTP/RedirectResponseTest.php @@ -52,6 +52,10 @@ public function testRedirectRelativeConvertsToFullURI() $this->assertEquals('http://example.com/foo', $response->getHeaderLine('Location')); } + /** + * @runTestsInSeparateProcesses + * @preserveGlobalState disabled + */ public function testWithInput() { $_SESSION = []; @@ -68,6 +72,10 @@ public function testWithInput() $this->assertEquals('baz', $_SESSION['_ci_old_input']['post']['bar']); } + /** + * @runTestsInSeparateProcesses + * @preserveGlobalState disabled + */ public function testWithValidationErrors() { $_SESSION = []; @@ -85,6 +93,10 @@ public function testWithValidationErrors() $this->assertArrayHasKey('_ci_validation_errors', $_SESSION); } + /** + * @runTestsInSeparateProcesses + * @preserveGlobalState disabled + */ public function testWith() { $_SESSION = []; From 1f1149e2eeacf4049401f1c60df8aade21eafa87 Mon Sep 17 00:00:00 2001 From: Andrei Furnica Date: Thu, 2 Aug 2018 14:41:52 +0300 Subject: [PATCH 07/10] mark all tests that use session to run as separate processes and not share global state --- tests/system/CommonFunctionsTest.php | 6 +++--- tests/system/Config/ServicesTest.php | 6 +++--- tests/system/HTTP/RedirectResponseTest.php | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/system/CommonFunctionsTest.php b/tests/system/CommonFunctionsTest.php index 10df01699790..3bd694fb4826 100644 --- a/tests/system/CommonFunctionsTest.php +++ b/tests/system/CommonFunctionsTest.php @@ -157,7 +157,7 @@ public function testEscapeBadContext() // ------------------------------------------------------------------------ /** - * @runTestsInSeparateProcesses + * @runInSeparateProcess * @preserveGlobalState disabled */ public function testSessionInstance() @@ -166,7 +166,7 @@ public function testSessionInstance() } /** - * @runTestsInSeparateProcesses + * @runInSeparateProcess * @preserveGlobalState disabled */ public function testSessionVariable() @@ -176,7 +176,7 @@ public function testSessionVariable() } /** - * @runTestsInSeparateProcesses + * @runInSeparateProcess * @preserveGlobalState disabled */ public function testSessionVariableNotThere() diff --git a/tests/system/Config/ServicesTest.php b/tests/system/Config/ServicesTest.php index 9fc5061c3f62..bc569434d187 100644 --- a/tests/system/Config/ServicesTest.php +++ b/tests/system/Config/ServicesTest.php @@ -130,7 +130,7 @@ public function testNewViewcell() } /** - * @runTestsInSeparateProcesses + * @runInSeparateProcess * @preserveGlobalState disabled */ public function testNewSession() @@ -140,7 +140,7 @@ public function testNewSession() } /** - * @runTestsInSeparateProcesses + * @runInSeparateProcess * @preserveGlobalState disabled */ public function testNewSessionWithNullConfig() @@ -150,7 +150,7 @@ public function testNewSessionWithNullConfig() } /** - * @runTestsInSeparateProcesses + * @runInSeparateProcess * @preserveGlobalState disabled */ public function testCallStatic() diff --git a/tests/system/HTTP/RedirectResponseTest.php b/tests/system/HTTP/RedirectResponseTest.php index 3bdaaa72abe8..a6b28724c236 100644 --- a/tests/system/HTTP/RedirectResponseTest.php +++ b/tests/system/HTTP/RedirectResponseTest.php @@ -53,7 +53,7 @@ public function testRedirectRelativeConvertsToFullURI() } /** - * @runTestsInSeparateProcesses + * @runInSeparateProcess * @preserveGlobalState disabled */ public function testWithInput() @@ -73,7 +73,7 @@ public function testWithInput() } /** - * @runTestsInSeparateProcesses + * @runInSeparateProcess * @preserveGlobalState disabled */ public function testWithValidationErrors() @@ -94,7 +94,7 @@ public function testWithValidationErrors() } /** - * @runTestsInSeparateProcesses + * @runInSeparateProcess * @preserveGlobalState disabled */ public function testWith() From 9d16520e113c71bed9ddbe01a883102471525496 Mon Sep 17 00:00:00 2001 From: Andrei Furnica Date: Thu, 2 Aug 2018 14:53:20 +0300 Subject: [PATCH 08/10] use session mock instead of the real driver --- tests/system/CommonFunctionsTest.php | 39 ++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/system/CommonFunctionsTest.php b/tests/system/CommonFunctionsTest.php index 3bd694fb4826..90b243ec4920 100644 --- a/tests/system/CommonFunctionsTest.php +++ b/tests/system/CommonFunctionsTest.php @@ -1,5 +1,6 @@ injectSessionMock(); + $this->assertInstanceOf(CodeIgniter\Session\Session::class, session()); } @@ -171,7 +177,10 @@ public function testSessionInstance() */ public function testSessionVariable() { + $this->injectSessionMock(); + $_SESSION['notbogus'] = 'Hi there'; + $this->assertEquals('Hi there', session('notbogus')); } @@ -181,6 +190,8 @@ public function testSessionVariable() */ public function testSessionVariableNotThere() { + $this->injectSessionMock(); + $_SESSION['bogus'] = 'Hi there'; $this->assertEquals(null, session('notbogus')); } @@ -243,8 +254,13 @@ public function testCSRFField() // ------------------------------------------------------------------------ + /** + * @runInSeparateProcess + * @preserveGlobalState disabled + */ public function testOldInput() { + $this->injectSessionMock(); // setup from RedirectResponseTest... $_SERVER['REQUEST_METHOD'] = 'GET'; @@ -287,4 +303,27 @@ public function testSlashItem() $this->assertEquals('en/', slash_item('defaultLocale')); // slash appended } + protected function injectSessionMock() + { + $defaults = [ + 'sessionDriver' => 'CodeIgniter\Session\Handlers\FileHandler', + 'sessionCookieName' => 'ci_session', + 'sessionExpiration' => 7200, + 'sessionSavePath' => null, + 'sessionMatchIP' => false, + 'sessionTimeToUpdate' => 300, + 'sessionRegenerateDestroy' => false, + 'cookieDomain' => '', + 'cookiePrefix' => '', + 'cookiePath' => '/', + 'cookieSecure' => false, + ]; + + $config = (object)$defaults; + + $session = new MockSession(new FileHandler($config), $config); + $session->setLogger(new TestLogger(new Logger())); + \CodeIgniter\Config\BaseService::injectMock('session', $session); + } + } From 25922b5cfc62e464c20f45fc4f95987ec405f8b6 Mon Sep 17 00:00:00 2001 From: Andrei Furnica Date: Thu, 2 Aug 2018 15:16:59 +0300 Subject: [PATCH 09/10] fix form helper set_radio --- system/Helpers/form_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Helpers/form_helper.php b/system/Helpers/form_helper.php index a4dca20006cb..384b2d09665d 100644 --- a/system/Helpers/form_helper.php +++ b/system/Helpers/form_helper.php @@ -925,7 +925,7 @@ function set_radio(string $field, string $value = '', bool $default = false): st // Unchecked checkbox and radio inputs are not even submitted by browsers ... $result = ''; - if ($request->getPost()) + if (!empty($request->getPost()) || !empty(old($field))) { $result = ($input === $value) ? ' checked="checked"' : ''; } From 6b6703dab1eef265325e4c03f5bda3e8a39d6b63 Mon Sep 17 00:00:00 2001 From: Andrei Furnica Date: Thu, 2 Aug 2018 15:55:03 +0300 Subject: [PATCH 10/10] fix form helper set_radio --- system/Helpers/form_helper.php | 2 +- tests/system/Helpers/FormHelperTest.php | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/system/Helpers/form_helper.php b/system/Helpers/form_helper.php index 384b2d09665d..fcac0adbabe8 100644 --- a/system/Helpers/form_helper.php +++ b/system/Helpers/form_helper.php @@ -925,7 +925,7 @@ function set_radio(string $field, string $value = '', bool $default = false): st // Unchecked checkbox and radio inputs are not even submitted by browsers ... $result = ''; - if (!empty($request->getPost()) || !empty(old($field))) + if (!empty($input = $request->getPost($field)) || !empty($input = old($field))) { $result = ($input === $value) ? ' checked="checked"' : ''; } diff --git a/tests/system/Helpers/FormHelperTest.php b/tests/system/Helpers/FormHelperTest.php index daf865189497..867f969be897 100644 --- a/tests/system/Helpers/FormHelperTest.php +++ b/tests/system/Helpers/FormHelperTest.php @@ -756,6 +756,10 @@ public function testSetCheckbox() } // ------------------------------------------------------------------------ + /** + * @runInSeparateProcess + * @preserveGlobalState disabled + */ public function testSetRadio() { $_SESSION = [ @@ -771,6 +775,10 @@ public function testSetRadio() unset($_SESSION['_ci_old_input']); } + /** + * @runInSeparateProcess + * @preserveGlobalState disabled + */ public function testSetRadioFromPost() { $_POST['bar'] = 'baz';