@@ -12,29 +12,29 @@ |
||
| 12 | 12 | class HybridSessionTest extends AbstractTest |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - protected function setUp() |
|
| 16 | - { |
|
| 17 | - parent::setUp(); |
|
| 15 | + protected function setUp() |
|
| 16 | + { |
|
| 17 | + parent::setUp(); |
|
| 18 | 18 | |
| 19 | - if (!DB::get_conn() instanceof MySQLDatabase) { |
|
| 20 | - // we can't always use the DB driver, so remove it if we aren't running a MySQL DB |
|
| 21 | - Config::modify()->set(HybridSession::class, 'dependencies', [ |
|
| 22 | - 'handlers' => [ |
|
| 23 | - '%$\SilverStripe\HybridSessions\Store\CookieStore', |
|
| 24 | - ], |
|
| 25 | - ]); |
|
| 26 | - } |
|
| 27 | - } |
|
| 19 | + if (!DB::get_conn() instanceof MySQLDatabase) { |
|
| 20 | + // we can't always use the DB driver, so remove it if we aren't running a MySQL DB |
|
| 21 | + Config::modify()->set(HybridSession::class, 'dependencies', [ |
|
| 22 | + 'handlers' => [ |
|
| 23 | + '%$\SilverStripe\HybridSessions\Store\CookieStore', |
|
| 24 | + ], |
|
| 25 | + ]); |
|
| 26 | + } |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @return HybridSessionStore_Cookie |
|
| 31 | - */ |
|
| 32 | - protected function getStore() |
|
| 33 | - { |
|
| 34 | - $store = Injector::inst()->create(HybridSession::class); |
|
| 35 | - $store->setKey(uniqid()); |
|
| 36 | - $store->open(TempFolder::getTempFolder(BASE_PATH).'/'.__CLASS__, 'SESSIONCOOKIE'); |
|
| 29 | + /** |
|
| 30 | + * @return HybridSessionStore_Cookie |
|
| 31 | + */ |
|
| 32 | + protected function getStore() |
|
| 33 | + { |
|
| 34 | + $store = Injector::inst()->create(HybridSession::class); |
|
| 35 | + $store->setKey(uniqid()); |
|
| 36 | + $store->open(TempFolder::getTempFolder(BASE_PATH).'/'.__CLASS__, 'SESSIONCOOKIE'); |
|
| 37 | 37 | |
| 38 | - return $store; |
|
| 39 | - } |
|
| 38 | + return $store; |
|
| 39 | + } |
|
| 40 | 40 | } |
@@ -10,104 +10,104 @@ |
||
| 10 | 10 | |
| 11 | 11 | abstract class AbstractTest extends SapphireTest |
| 12 | 12 | { |
| 13 | - protected $usesDatabase = true; |
|
| 14 | - |
|
| 15 | - protected function setUp() |
|
| 16 | - { |
|
| 17 | - parent::setUp(); |
|
| 18 | - |
|
| 19 | - TestCookieStore::$override_headers_sent = false; |
|
| 20 | - |
|
| 21 | - Injector::inst()->registerService( |
|
| 22 | - new TestCookieStore(), |
|
| 23 | - CookieStore::class |
|
| 24 | - ); |
|
| 25 | - |
|
| 26 | - DBDatetime::set_mock_now('2010-03-15 12:00:00'); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - protected function tearDown() |
|
| 30 | - { |
|
| 31 | - DBDatetime::clear_mock_now(); |
|
| 32 | - |
|
| 33 | - parent::tearDown(); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - abstract protected function getStore(); |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Test how this store handles large volumes of data (>1000 characters) |
|
| 40 | - */ |
|
| 41 | - public function testStoreLargeData() |
|
| 42 | - { |
|
| 43 | - $session = uniqid(); |
|
| 44 | - $store = $this->getStore(); |
|
| 45 | - |
|
| 46 | - // Test new session is blank |
|
| 47 | - $result = $store->read($session); |
|
| 48 | - $this->assertEmpty($result); |
|
| 49 | - |
|
| 50 | - // Save data against session |
|
| 51 | - $data1 = array( |
|
| 52 | - 'Large' => str_repeat('A', 600), |
|
| 53 | - 'Content' => str_repeat('B', 600) |
|
| 54 | - ); |
|
| 55 | - $store->write($session, serialize($data1)); |
|
| 56 | - $result = $store->read($session); |
|
| 57 | - $this->assertEquals($data1, unserialize($result)); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Test storage of data |
|
| 62 | - */ |
|
| 63 | - public function testStoreData() |
|
| 64 | - { |
|
| 65 | - $session = uniqid(); |
|
| 66 | - $store = $this->getStore(); |
|
| 67 | - |
|
| 68 | - // Test new session is blank |
|
| 69 | - $result = $store->read($session); |
|
| 70 | - $this->assertEmpty($result); |
|
| 71 | - |
|
| 72 | - // Save data against session |
|
| 73 | - $data1 = array( |
|
| 74 | - 'Color' => 'red', |
|
| 75 | - 'Animal' => 'elephant' |
|
| 76 | - ); |
|
| 77 | - $store->write($session, serialize($data1)); |
|
| 78 | - $result = $store->read($session); |
|
| 79 | - $this->assertEquals($data1, unserialize($result)); |
|
| 80 | - |
|
| 81 | - // Save larger data |
|
| 82 | - $data2 = array( |
|
| 83 | - 'Color' => 'blue', |
|
| 84 | - 'Animal' => str_repeat('bat', 100) |
|
| 85 | - ); |
|
| 86 | - $store->write($session, serialize($data2)); |
|
| 87 | - $result = $store->read($session); |
|
| 88 | - $this->assertEquals($data2, unserialize($result)); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Test expiry of data |
|
| 93 | - */ |
|
| 94 | - public function testExpiry() |
|
| 95 | - { |
|
| 96 | - $session1 = uniqid(); |
|
| 97 | - $store = $this->getStore(); |
|
| 98 | - |
|
| 99 | - // Store data now |
|
| 100 | - $data1 = array( |
|
| 101 | - 'Food' => 'Pizza' |
|
| 102 | - ); |
|
| 103 | - $store->write($session1, serialize($data1)); |
|
| 104 | - $result1 = $store->read($session1); |
|
| 105 | - $this->assertEquals($data1, unserialize($result1)); |
|
| 106 | - |
|
| 107 | - // Go to the future and test that the expiry is accurate |
|
| 108 | - DBDatetime::set_mock_now('2040-03-16 12:00:00'); |
|
| 109 | - $result2 = $store->read($session1); |
|
| 110 | - |
|
| 111 | - $this->assertEmpty($result2); |
|
| 112 | - } |
|
| 13 | + protected $usesDatabase = true; |
|
| 14 | + |
|
| 15 | + protected function setUp() |
|
| 16 | + { |
|
| 17 | + parent::setUp(); |
|
| 18 | + |
|
| 19 | + TestCookieStore::$override_headers_sent = false; |
|
| 20 | + |
|
| 21 | + Injector::inst()->registerService( |
|
| 22 | + new TestCookieStore(), |
|
| 23 | + CookieStore::class |
|
| 24 | + ); |
|
| 25 | + |
|
| 26 | + DBDatetime::set_mock_now('2010-03-15 12:00:00'); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + protected function tearDown() |
|
| 30 | + { |
|
| 31 | + DBDatetime::clear_mock_now(); |
|
| 32 | + |
|
| 33 | + parent::tearDown(); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + abstract protected function getStore(); |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Test how this store handles large volumes of data (>1000 characters) |
|
| 40 | + */ |
|
| 41 | + public function testStoreLargeData() |
|
| 42 | + { |
|
| 43 | + $session = uniqid(); |
|
| 44 | + $store = $this->getStore(); |
|
| 45 | + |
|
| 46 | + // Test new session is blank |
|
| 47 | + $result = $store->read($session); |
|
| 48 | + $this->assertEmpty($result); |
|
| 49 | + |
|
| 50 | + // Save data against session |
|
| 51 | + $data1 = array( |
|
| 52 | + 'Large' => str_repeat('A', 600), |
|
| 53 | + 'Content' => str_repeat('B', 600) |
|
| 54 | + ); |
|
| 55 | + $store->write($session, serialize($data1)); |
|
| 56 | + $result = $store->read($session); |
|
| 57 | + $this->assertEquals($data1, unserialize($result)); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Test storage of data |
|
| 62 | + */ |
|
| 63 | + public function testStoreData() |
|
| 64 | + { |
|
| 65 | + $session = uniqid(); |
|
| 66 | + $store = $this->getStore(); |
|
| 67 | + |
|
| 68 | + // Test new session is blank |
|
| 69 | + $result = $store->read($session); |
|
| 70 | + $this->assertEmpty($result); |
|
| 71 | + |
|
| 72 | + // Save data against session |
|
| 73 | + $data1 = array( |
|
| 74 | + 'Color' => 'red', |
|
| 75 | + 'Animal' => 'elephant' |
|
| 76 | + ); |
|
| 77 | + $store->write($session, serialize($data1)); |
|
| 78 | + $result = $store->read($session); |
|
| 79 | + $this->assertEquals($data1, unserialize($result)); |
|
| 80 | + |
|
| 81 | + // Save larger data |
|
| 82 | + $data2 = array( |
|
| 83 | + 'Color' => 'blue', |
|
| 84 | + 'Animal' => str_repeat('bat', 100) |
|
| 85 | + ); |
|
| 86 | + $store->write($session, serialize($data2)); |
|
| 87 | + $result = $store->read($session); |
|
| 88 | + $this->assertEquals($data2, unserialize($result)); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Test expiry of data |
|
| 93 | + */ |
|
| 94 | + public function testExpiry() |
|
| 95 | + { |
|
| 96 | + $session1 = uniqid(); |
|
| 97 | + $store = $this->getStore(); |
|
| 98 | + |
|
| 99 | + // Store data now |
|
| 100 | + $data1 = array( |
|
| 101 | + 'Food' => 'Pizza' |
|
| 102 | + ); |
|
| 103 | + $store->write($session1, serialize($data1)); |
|
| 104 | + $result1 = $store->read($session1); |
|
| 105 | + $this->assertEquals($data1, unserialize($result1)); |
|
| 106 | + |
|
| 107 | + // Go to the future and test that the expiry is accurate |
|
| 108 | + DBDatetime::set_mock_now('2040-03-16 12:00:00'); |
|
| 109 | + $result2 = $store->read($session1); |
|
| 110 | + |
|
| 111 | + $this->assertEmpty($result2); |
|
| 112 | + } |
|
| 113 | 113 | } |
@@ -9,20 +9,20 @@ |
||
| 9 | 9 | |
| 10 | 10 | class DatabaseStoreTest extends AbstractTest |
| 11 | 11 | { |
| 12 | - protected function setUp() |
|
| 13 | - { |
|
| 14 | - parent::setUp(); |
|
| 12 | + protected function setUp() |
|
| 13 | + { |
|
| 14 | + parent::setUp(); |
|
| 15 | 15 | |
| 16 | - if (!DB::get_conn() instanceof MySQLDatabase) { |
|
| 17 | - $this->markTestSkipped('Only MySQL databases are supported'); |
|
| 18 | - } |
|
| 19 | - } |
|
| 16 | + if (!DB::get_conn() instanceof MySQLDatabase) { |
|
| 17 | + $this->markTestSkipped('Only MySQL databases are supported'); |
|
| 18 | + } |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - protected function getStore() |
|
| 22 | - { |
|
| 23 | - $store = Injector::inst()->get(DatabaseStore::class); |
|
| 24 | - $store->setKey(uniqid()); |
|
| 21 | + protected function getStore() |
|
| 22 | + { |
|
| 23 | + $store = Injector::inst()->get(DatabaseStore::class); |
|
| 24 | + $store->setKey(uniqid()); |
|
| 25 | 25 | |
| 26 | - return $store; |
|
| 27 | - } |
|
| 26 | + return $store; |
|
| 27 | + } |
|
| 28 | 28 | } |