@@ -18,80 +18,80 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class EnvironmentCheckerTest extends SapphireTest |
| 20 | 20 | { |
| 21 | - protected $usesDatabase = true; |
|
| 21 | + protected $usesDatabase = true; |
|
| 22 | 22 | |
| 23 | - protected function tearDown() |
|
| 24 | - { |
|
| 25 | - EnvironmentCheckSuite::reset(); |
|
| 26 | - parent::tearDown(); |
|
| 27 | - } |
|
| 23 | + protected function tearDown() |
|
| 24 | + { |
|
| 25 | + EnvironmentCheckSuite::reset(); |
|
| 26 | + parent::tearDown(); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - public function testOnlyLogsWithErrors() |
|
| 30 | - { |
|
| 31 | - Config::modify()->set(EnvironmentChecker::class, 'log_results_warning', true); |
|
| 32 | - Config::modify()->set(EnvironmentChecker::class, 'log_results_error', true); |
|
| 29 | + public function testOnlyLogsWithErrors() |
|
| 30 | + { |
|
| 31 | + Config::modify()->set(EnvironmentChecker::class, 'log_results_warning', true); |
|
| 32 | + Config::modify()->set(EnvironmentChecker::class, 'log_results_error', true); |
|
| 33 | 33 | |
| 34 | - EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest\CheckNoErrors()); |
|
| 34 | + EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest\CheckNoErrors()); |
|
| 35 | 35 | |
| 36 | - $logger = $this->getMockBuilder(Logger::class) |
|
| 37 | - ->disableOriginalConstructor() |
|
| 38 | - ->setMethods(['log']) |
|
| 39 | - ->getMock(); |
|
| 36 | + $logger = $this->getMockBuilder(Logger::class) |
|
| 37 | + ->disableOriginalConstructor() |
|
| 38 | + ->setMethods(['log']) |
|
| 39 | + ->getMock(); |
|
| 40 | 40 | |
| 41 | - $logger->expects($this->never())->method('log'); |
|
| 41 | + $logger->expects($this->never())->method('log'); |
|
| 42 | 42 | |
| 43 | - Injector::inst()->registerService($logger, LoggerInterface::class); |
|
| 43 | + Injector::inst()->registerService($logger, LoggerInterface::class); |
|
| 44 | 44 | |
| 45 | - (new EnvironmentChecker('test suite', 'test'))->index(); |
|
| 46 | - } |
|
| 45 | + (new EnvironmentChecker('test suite', 'test'))->index(); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - public function testLogsWithWarnings() |
|
| 49 | - { |
|
| 50 | - Config::modify()->set(EnvironmentChecker::class, 'log_results_warning', true); |
|
| 51 | - Config::modify()->set(EnvironmentChecker::class, 'log_results_error', false); |
|
| 48 | + public function testLogsWithWarnings() |
|
| 49 | + { |
|
| 50 | + Config::modify()->set(EnvironmentChecker::class, 'log_results_warning', true); |
|
| 51 | + Config::modify()->set(EnvironmentChecker::class, 'log_results_error', false); |
|
| 52 | 52 | |
| 53 | - EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest\CheckWarnings()); |
|
| 54 | - EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest\CheckErrors()); |
|
| 53 | + EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest\CheckWarnings()); |
|
| 54 | + EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest\CheckErrors()); |
|
| 55 | 55 | |
| 56 | - $logger = $this->getMockBuilder(Logger::class) |
|
| 57 | - ->disableOriginalConstructor() |
|
| 58 | - ->setMethods(['log']) |
|
| 59 | - ->getMock(); |
|
| 56 | + $logger = $this->getMockBuilder(Logger::class) |
|
| 57 | + ->disableOriginalConstructor() |
|
| 58 | + ->setMethods(['log']) |
|
| 59 | + ->getMock(); |
|
| 60 | 60 | |
| 61 | - $logger->expects($this->once()) |
|
| 62 | - ->method('log') |
|
| 63 | - ->withConsecutive( |
|
| 64 | - $this->equalTo(LogLevel::WARNING), |
|
| 65 | - $this->anything() |
|
| 66 | - ); |
|
| 61 | + $logger->expects($this->once()) |
|
| 62 | + ->method('log') |
|
| 63 | + ->withConsecutive( |
|
| 64 | + $this->equalTo(LogLevel::WARNING), |
|
| 65 | + $this->anything() |
|
| 66 | + ); |
|
| 67 | 67 | |
| 68 | - Injector::inst()->registerService($logger, LoggerInterface::class); |
|
| 68 | + Injector::inst()->registerService($logger, LoggerInterface::class); |
|
| 69 | 69 | |
| 70 | - (new EnvironmentChecker('test suite', 'test'))->index(); |
|
| 71 | - } |
|
| 70 | + (new EnvironmentChecker('test suite', 'test'))->index(); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - public function testLogsWithErrors() |
|
| 74 | - { |
|
| 75 | - Config::modify()->set(EnvironmentChecker::class, 'log_results_error', false); |
|
| 76 | - Config::modify()->set(EnvironmentChecker::class, 'log_results_error', true); |
|
| 73 | + public function testLogsWithErrors() |
|
| 74 | + { |
|
| 75 | + Config::modify()->set(EnvironmentChecker::class, 'log_results_error', false); |
|
| 76 | + Config::modify()->set(EnvironmentChecker::class, 'log_results_error', true); |
|
| 77 | 77 | |
| 78 | - EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest\CheckWarnings()); |
|
| 79 | - EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest\CheckErrors()); |
|
| 78 | + EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest\CheckWarnings()); |
|
| 79 | + EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest\CheckErrors()); |
|
| 80 | 80 | |
| 81 | - $logger = $this->getMockBuilder(Logger::class) |
|
| 82 | - ->disableOriginalConstructor() |
|
| 83 | - ->setMethods(['log']) |
|
| 84 | - ->getMock(); |
|
| 81 | + $logger = $this->getMockBuilder(Logger::class) |
|
| 82 | + ->disableOriginalConstructor() |
|
| 83 | + ->setMethods(['log']) |
|
| 84 | + ->getMock(); |
|
| 85 | 85 | |
| 86 | - $logger->expects($this->once()) |
|
| 87 | - ->method('log') |
|
| 88 | - ->withConsecutive( |
|
| 89 | - [$this->equalTo(LogLevel::ALERT), $this->anything()], |
|
| 90 | - [$this->equalTo(LogLevel::WARNING), $this->anything()] |
|
| 91 | - ); |
|
| 86 | + $logger->expects($this->once()) |
|
| 87 | + ->method('log') |
|
| 88 | + ->withConsecutive( |
|
| 89 | + [$this->equalTo(LogLevel::ALERT), $this->anything()], |
|
| 90 | + [$this->equalTo(LogLevel::WARNING), $this->anything()] |
|
| 91 | + ); |
|
| 92 | 92 | |
| 93 | - Injector::inst()->registerService($logger, LoggerInterface::class); |
|
| 93 | + Injector::inst()->registerService($logger, LoggerInterface::class); |
|
| 94 | 94 | |
| 95 | - (new EnvironmentChecker('test suite', 'test'))->index(); |
|
| 96 | - } |
|
| 95 | + (new EnvironmentChecker('test suite', 'test'))->index(); |
|
| 96 | + } |
|
| 97 | 97 | } |
@@ -7,8 +7,8 @@ |
||
| 7 | 7 | |
| 8 | 8 | class CheckNoErrors implements EnvironmentCheck, TestOnly |
| 9 | 9 | { |
| 10 | - public function check() |
|
| 11 | - { |
|
| 12 | - return [EnvironmentCheck::OK, '']; |
|
| 13 | - } |
|
| 10 | + public function check() |
|
| 11 | + { |
|
| 12 | + return [EnvironmentCheck::OK, '']; |
|
| 13 | + } |
|
| 14 | 14 | } |
@@ -7,8 +7,8 @@ |
||
| 7 | 7 | |
| 8 | 8 | class CheckErrors implements EnvironmentCheck, TestOnly |
| 9 | 9 | { |
| 10 | - public function check() |
|
| 11 | - { |
|
| 12 | - return [EnvironmentCheck::ERROR, 'test error']; |
|
| 13 | - } |
|
| 10 | + public function check() |
|
| 11 | + { |
|
| 12 | + return [EnvironmentCheck::ERROR, 'test error']; |
|
| 13 | + } |
|
| 14 | 14 | } |
@@ -7,8 +7,8 @@ |
||
| 7 | 7 | |
| 8 | 8 | class CheckWarnings implements EnvironmentCheck, TestOnly |
| 9 | 9 | { |
| 10 | - public function check() |
|
| 11 | - { |
|
| 12 | - return [EnvironmentCheck::WARNING, 'test warning']; |
|
| 13 | - } |
|
| 10 | + public function check() |
|
| 11 | + { |
|
| 12 | + return [EnvironmentCheck::WARNING, 'test warning']; |
|
| 13 | + } |
|
| 14 | 14 | } |
@@ -15,38 +15,38 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class SolrIndexCheck implements EnvironmentCheck |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * {@inheritDoc} |
|
| 20 | - * |
|
| 21 | - * @return array |
|
| 22 | - */ |
|
| 23 | - public function check() |
|
| 24 | - { |
|
| 25 | - $brokenCores = []; |
|
| 18 | + /** |
|
| 19 | + * {@inheritDoc} |
|
| 20 | + * |
|
| 21 | + * @return array |
|
| 22 | + */ |
|
| 23 | + public function check() |
|
| 24 | + { |
|
| 25 | + $brokenCores = []; |
|
| 26 | 26 | |
| 27 | - if (!class_exists(Solr::class)) { |
|
| 28 | - return [ |
|
| 29 | - EnvironmentCheck::ERROR, |
|
| 30 | - 'Class `' . Solr::class . '` not found. Is the fulltextsearch module installed?' |
|
| 31 | - ]; |
|
| 32 | - } |
|
| 27 | + if (!class_exists(Solr::class)) { |
|
| 28 | + return [ |
|
| 29 | + EnvironmentCheck::ERROR, |
|
| 30 | + 'Class `' . Solr::class . '` not found. Is the fulltextsearch module installed?' |
|
| 31 | + ]; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - $service = Solr::service(); |
|
| 35 | - foreach (Solr::get_indexes() as $index) { |
|
| 36 | - /** @var SolrIndex $core */ |
|
| 37 | - $core = $index->getIndexName(); |
|
| 38 | - if (!$service->coreIsActive($core)) { |
|
| 39 | - $brokenCores[] = $core; |
|
| 40 | - } |
|
| 41 | - } |
|
| 34 | + $service = Solr::service(); |
|
| 35 | + foreach (Solr::get_indexes() as $index) { |
|
| 36 | + /** @var SolrIndex $core */ |
|
| 37 | + $core = $index->getIndexName(); |
|
| 38 | + if (!$service->coreIsActive($core)) { |
|
| 39 | + $brokenCores[] = $core; |
|
| 40 | + } |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - if (!empty($brokenCores)) { |
|
| 44 | - return [ |
|
| 45 | - EnvironmentCheck::ERROR, |
|
| 46 | - 'The following indexes are unavailable: ' . implode($brokenCores, ', ') |
|
| 47 | - ]; |
|
| 48 | - } |
|
| 43 | + if (!empty($brokenCores)) { |
|
| 44 | + return [ |
|
| 45 | + EnvironmentCheck::ERROR, |
|
| 46 | + 'The following indexes are unavailable: ' . implode($brokenCores, ', ') |
|
| 47 | + ]; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - return [EnvironmentCheck::OK, 'Expected indexes are available.']; |
|
| 51 | - } |
|
| 50 | + return [EnvironmentCheck::OK, 'Expected indexes are available.']; |
|
| 51 | + } |
|
| 52 | 52 | } |
@@ -13,28 +13,28 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class EnvTypeCheck implements EnvironmentCheck |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * Check the environment setting. |
|
| 18 | - * |
|
| 19 | - * @return array |
|
| 20 | - */ |
|
| 21 | - public function check() |
|
| 22 | - { |
|
| 23 | - $envSetting = Director::get_environment_type(); |
|
| 24 | - switch ($envSetting) { |
|
| 25 | - case 'live': |
|
| 26 | - return [ |
|
| 27 | - EnvironmentCheck::OK, |
|
| 28 | - "Env setting is 'live'", |
|
| 29 | - ]; |
|
| 30 | - // Fallthrough |
|
| 31 | - default: |
|
| 32 | - case 'dev': |
|
| 33 | - case 'test': |
|
| 34 | - return [ |
|
| 35 | - EnvironmentCheck::ERROR, |
|
| 36 | - "Env setting is '{$envSetting}' and may disclose information", |
|
| 37 | - ]; |
|
| 38 | - } |
|
| 39 | - } |
|
| 16 | + /** |
|
| 17 | + * Check the environment setting. |
|
| 18 | + * |
|
| 19 | + * @return array |
|
| 20 | + */ |
|
| 21 | + public function check() |
|
| 22 | + { |
|
| 23 | + $envSetting = Director::get_environment_type(); |
|
| 24 | + switch ($envSetting) { |
|
| 25 | + case 'live': |
|
| 26 | + return [ |
|
| 27 | + EnvironmentCheck::OK, |
|
| 28 | + "Env setting is 'live'", |
|
| 29 | + ]; |
|
| 30 | + // Fallthrough |
|
| 31 | + default: |
|
| 32 | + case 'dev': |
|
| 33 | + case 'test': |
|
| 34 | + return [ |
|
| 35 | + EnvironmentCheck::ERROR, |
|
| 36 | + "Env setting is '{$envSetting}' and may disclose information", |
|
| 37 | + ]; |
|
| 38 | + } |
|
| 39 | + } |
|
| 40 | 40 | } |
@@ -14,60 +14,60 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class EnvTypeCheckTest extends SapphireTest |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * Check is OK when in live mode |
|
| 19 | - * |
|
| 20 | - * @return void |
|
| 21 | - */ |
|
| 22 | - public function testEnvSettingLive() |
|
| 23 | - { |
|
| 24 | - /** @var Kernel $kernel */ |
|
| 25 | - $kernel = Injector::inst()->get(Kernel::class); |
|
| 26 | - $kernel->setEnvironment('live'); |
|
| 17 | + /** |
|
| 18 | + * Check is OK when in live mode |
|
| 19 | + * |
|
| 20 | + * @return void |
|
| 21 | + */ |
|
| 22 | + public function testEnvSettingLive() |
|
| 23 | + { |
|
| 24 | + /** @var Kernel $kernel */ |
|
| 25 | + $kernel = Injector::inst()->get(Kernel::class); |
|
| 26 | + $kernel->setEnvironment('live'); |
|
| 27 | 27 | |
| 28 | - $this->assertTrue(Director::isLive()); |
|
| 28 | + $this->assertTrue(Director::isLive()); |
|
| 29 | 29 | |
| 30 | - $checker = Injector::inst()->get(EnvTypeCheck::class); |
|
| 31 | - $result = $checker->check(); |
|
| 30 | + $checker = Injector::inst()->get(EnvTypeCheck::class); |
|
| 31 | + $result = $checker->check(); |
|
| 32 | 32 | |
| 33 | - $this->assertSame($result[0], EnvironmentCheck::OK); |
|
| 34 | - } |
|
| 33 | + $this->assertSame($result[0], EnvironmentCheck::OK); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Check is ERROR when in test mode |
|
| 38 | - * |
|
| 39 | - * @return void |
|
| 40 | - */ |
|
| 41 | - public function testEnvSettingTest() |
|
| 42 | - { |
|
| 43 | - /** @var Kernel $kernel */ |
|
| 44 | - $kernel = Injector::inst()->get(Kernel::class); |
|
| 45 | - $kernel->setEnvironment('test'); |
|
| 36 | + /** |
|
| 37 | + * Check is ERROR when in test mode |
|
| 38 | + * |
|
| 39 | + * @return void |
|
| 40 | + */ |
|
| 41 | + public function testEnvSettingTest() |
|
| 42 | + { |
|
| 43 | + /** @var Kernel $kernel */ |
|
| 44 | + $kernel = Injector::inst()->get(Kernel::class); |
|
| 45 | + $kernel->setEnvironment('test'); |
|
| 46 | 46 | |
| 47 | - $this->assertTrue(Director::isTest()); |
|
| 47 | + $this->assertTrue(Director::isTest()); |
|
| 48 | 48 | |
| 49 | - $checker = Injector::inst()->get(EnvTypeCheck::class); |
|
| 50 | - $result = $checker->check(); |
|
| 49 | + $checker = Injector::inst()->get(EnvTypeCheck::class); |
|
| 50 | + $result = $checker->check(); |
|
| 51 | 51 | |
| 52 | - $this->assertSame($result[0], EnvironmentCheck::ERROR); |
|
| 53 | - } |
|
| 52 | + $this->assertSame($result[0], EnvironmentCheck::ERROR); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Check is ERROR when in dev mode |
|
| 57 | - * |
|
| 58 | - * @return void |
|
| 59 | - */ |
|
| 60 | - public function testEnvSettingDev() |
|
| 61 | - { |
|
| 62 | - /** @var Kernel $kernel */ |
|
| 63 | - $kernel = Injector::inst()->get(Kernel::class); |
|
| 64 | - $kernel->setEnvironment('dev'); |
|
| 55 | + /** |
|
| 56 | + * Check is ERROR when in dev mode |
|
| 57 | + * |
|
| 58 | + * @return void |
|
| 59 | + */ |
|
| 60 | + public function testEnvSettingDev() |
|
| 61 | + { |
|
| 62 | + /** @var Kernel $kernel */ |
|
| 63 | + $kernel = Injector::inst()->get(Kernel::class); |
|
| 64 | + $kernel->setEnvironment('dev'); |
|
| 65 | 65 | |
| 66 | - $this->assertTrue(Director::isDev()); |
|
| 66 | + $this->assertTrue(Director::isDev()); |
|
| 67 | 67 | |
| 68 | - $checker = Injector::inst()->get(EnvTypeCheck::class); |
|
| 69 | - $result = $checker->check(); |
|
| 68 | + $checker = Injector::inst()->get(EnvTypeCheck::class); |
|
| 69 | + $result = $checker->check(); |
|
| 70 | 70 | |
| 71 | - $this->assertSame($result[0], EnvironmentCheck::ERROR); |
|
| 72 | - } |
|
| 71 | + $this->assertSame($result[0], EnvironmentCheck::ERROR); |
|
| 72 | + } |
|
| 73 | 73 | } |
@@ -15,87 +15,87 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class CacheHeadersCheckTest extends SapphireTest |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Test that directives that must be included, are. |
|
| 20 | - * |
|
| 21 | - * @return void |
|
| 22 | - */ |
|
| 23 | - public function testMustInclude() |
|
| 24 | - { |
|
| 25 | - // Create a mock and queue responses |
|
| 26 | - $mock = new MockHandler([ |
|
| 27 | - new Response(200, ['Cache-Control' => 'must-revalidate', 'ETag' => '123']), |
|
| 28 | - new Response(200, ['Cache-Control' =>'no-cache', 'ETag' => '123']), |
|
| 29 | - new Response(200, ['ETag' => '123']), |
|
| 30 | - new Response(200, ['Cache-Control' => 'must-revalidate, private', 'ETag' => '123']), |
|
| 31 | - ]); |
|
| 18 | + /** |
|
| 19 | + * Test that directives that must be included, are. |
|
| 20 | + * |
|
| 21 | + * @return void |
|
| 22 | + */ |
|
| 23 | + public function testMustInclude() |
|
| 24 | + { |
|
| 25 | + // Create a mock and queue responses |
|
| 26 | + $mock = new MockHandler([ |
|
| 27 | + new Response(200, ['Cache-Control' => 'must-revalidate', 'ETag' => '123']), |
|
| 28 | + new Response(200, ['Cache-Control' =>'no-cache', 'ETag' => '123']), |
|
| 29 | + new Response(200, ['ETag' => '123']), |
|
| 30 | + new Response(200, ['Cache-Control' => 'must-revalidate, private', 'ETag' => '123']), |
|
| 31 | + ]); |
|
| 32 | 32 | |
| 33 | - $handler = HandlerStack::create($mock); |
|
| 34 | - $client = new Client(['handler' => $handler]); |
|
| 33 | + $handler = HandlerStack::create($mock); |
|
| 34 | + $client = new Client(['handler' => $handler]); |
|
| 35 | 35 | |
| 36 | - $cacheHeadersCheck = new CacheHeadersCheck('/', ['must-revalidate']); |
|
| 37 | - $cacheHeadersCheck->client = $client; |
|
| 36 | + $cacheHeadersCheck = new CacheHeadersCheck('/', ['must-revalidate']); |
|
| 37 | + $cacheHeadersCheck->client = $client; |
|
| 38 | 38 | |
| 39 | - // Run checks for each response above |
|
| 40 | - $this->assertContains(EnvironmentCheck::OK, $cacheHeadersCheck->check()); |
|
| 41 | - $this->assertContains(EnvironmentCheck::ERROR, $cacheHeadersCheck->check()); |
|
| 42 | - $this->assertContains(EnvironmentCheck::ERROR, $cacheHeadersCheck->check()); |
|
| 43 | - $this->assertContains(EnvironmentCheck::OK, $cacheHeadersCheck->check()); |
|
| 44 | - } |
|
| 39 | + // Run checks for each response above |
|
| 40 | + $this->assertContains(EnvironmentCheck::OK, $cacheHeadersCheck->check()); |
|
| 41 | + $this->assertContains(EnvironmentCheck::ERROR, $cacheHeadersCheck->check()); |
|
| 42 | + $this->assertContains(EnvironmentCheck::ERROR, $cacheHeadersCheck->check()); |
|
| 43 | + $this->assertContains(EnvironmentCheck::OK, $cacheHeadersCheck->check()); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Test that directives that must be excluded, are. |
|
| 48 | - * |
|
| 49 | - * @return void |
|
| 50 | - */ |
|
| 51 | - public function testMustExclude() |
|
| 52 | - { |
|
| 53 | - // Create a mock and queue responses |
|
| 54 | - $mock = new MockHandler([ |
|
| 55 | - new Response(200, ['Cache-Control' => 'must-revalidate', 'ETag' => '123']), |
|
| 56 | - new Response(200, ['Cache-Control' =>'no-cache', 'ETag' => '123']), |
|
| 57 | - new Response(200, ['ETag' => '123']), |
|
| 58 | - new Response(200, ['Cache-Control' =>'private, no-store', ' ETag' => '123']), |
|
| 59 | - ]); |
|
| 46 | + /** |
|
| 47 | + * Test that directives that must be excluded, are. |
|
| 48 | + * |
|
| 49 | + * @return void |
|
| 50 | + */ |
|
| 51 | + public function testMustExclude() |
|
| 52 | + { |
|
| 53 | + // Create a mock and queue responses |
|
| 54 | + $mock = new MockHandler([ |
|
| 55 | + new Response(200, ['Cache-Control' => 'must-revalidate', 'ETag' => '123']), |
|
| 56 | + new Response(200, ['Cache-Control' =>'no-cache', 'ETag' => '123']), |
|
| 57 | + new Response(200, ['ETag' => '123']), |
|
| 58 | + new Response(200, ['Cache-Control' =>'private, no-store', ' ETag' => '123']), |
|
| 59 | + ]); |
|
| 60 | 60 | |
| 61 | - $handler = HandlerStack::create($mock); |
|
| 62 | - $client = new Client(['handler' => $handler]); |
|
| 61 | + $handler = HandlerStack::create($mock); |
|
| 62 | + $client = new Client(['handler' => $handler]); |
|
| 63 | 63 | |
| 64 | - $cacheHeadersCheck = new CacheHeadersCheck('/', [], ["no-store", "no-cache", "private"]); |
|
| 65 | - $cacheHeadersCheck->client = $client; |
|
| 64 | + $cacheHeadersCheck = new CacheHeadersCheck('/', [], ["no-store", "no-cache", "private"]); |
|
| 65 | + $cacheHeadersCheck->client = $client; |
|
| 66 | 66 | |
| 67 | - // Run checks for each response above |
|
| 68 | - $this->assertContains(EnvironmentCheck::OK, $cacheHeadersCheck->check()); |
|
| 69 | - $this->assertContains(EnvironmentCheck::ERROR, $cacheHeadersCheck->check()); |
|
| 70 | - $this->assertContains(EnvironmentCheck::OK, $cacheHeadersCheck->check()); |
|
| 71 | - $this->assertContains(EnvironmentCheck::ERROR, $cacheHeadersCheck->check()); |
|
| 72 | - } |
|
| 67 | + // Run checks for each response above |
|
| 68 | + $this->assertContains(EnvironmentCheck::OK, $cacheHeadersCheck->check()); |
|
| 69 | + $this->assertContains(EnvironmentCheck::ERROR, $cacheHeadersCheck->check()); |
|
| 70 | + $this->assertContains(EnvironmentCheck::OK, $cacheHeadersCheck->check()); |
|
| 71 | + $this->assertContains(EnvironmentCheck::ERROR, $cacheHeadersCheck->check()); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Test that Etag header must exist in response. |
|
| 76 | - * |
|
| 77 | - * @return void |
|
| 78 | - */ |
|
| 79 | - public function testEtag() |
|
| 80 | - { |
|
| 81 | - // Create a mock and queue responses |
|
| 82 | - $mock = new MockHandler([ |
|
| 83 | - new Response(200, ['Cache-Control' => 'must-revalidate', 'ETag' => '123']), |
|
| 84 | - new Response(200, ['Cache-Control' =>'no-cache']), |
|
| 85 | - new Response(200, ['ETag' => '123']), |
|
| 86 | - new Response(200, []), |
|
| 87 | - ]); |
|
| 74 | + /** |
|
| 75 | + * Test that Etag header must exist in response. |
|
| 76 | + * |
|
| 77 | + * @return void |
|
| 78 | + */ |
|
| 79 | + public function testEtag() |
|
| 80 | + { |
|
| 81 | + // Create a mock and queue responses |
|
| 82 | + $mock = new MockHandler([ |
|
| 83 | + new Response(200, ['Cache-Control' => 'must-revalidate', 'ETag' => '123']), |
|
| 84 | + new Response(200, ['Cache-Control' =>'no-cache']), |
|
| 85 | + new Response(200, ['ETag' => '123']), |
|
| 86 | + new Response(200, []), |
|
| 87 | + ]); |
|
| 88 | 88 | |
| 89 | - $handler = HandlerStack::create($mock); |
|
| 90 | - $client = new Client(['handler' => $handler]); |
|
| 89 | + $handler = HandlerStack::create($mock); |
|
| 90 | + $client = new Client(['handler' => $handler]); |
|
| 91 | 91 | |
| 92 | - $cacheHeadersCheck = new CacheHeadersCheck('/'); |
|
| 93 | - $cacheHeadersCheck->client = $client; |
|
| 92 | + $cacheHeadersCheck = new CacheHeadersCheck('/'); |
|
| 93 | + $cacheHeadersCheck->client = $client; |
|
| 94 | 94 | |
| 95 | - // Run checks for each response above |
|
| 96 | - $this->assertContains(EnvironmentCheck::OK, $cacheHeadersCheck->check()); |
|
| 97 | - $this->assertContains(EnvironmentCheck::ERROR, $cacheHeadersCheck->check()); |
|
| 98 | - $this->assertContains(EnvironmentCheck::OK, $cacheHeadersCheck->check()); |
|
| 99 | - $this->assertContains(EnvironmentCheck::ERROR, $cacheHeadersCheck->check()); |
|
| 100 | - } |
|
| 95 | + // Run checks for each response above |
|
| 96 | + $this->assertContains(EnvironmentCheck::OK, $cacheHeadersCheck->check()); |
|
| 97 | + $this->assertContains(EnvironmentCheck::ERROR, $cacheHeadersCheck->check()); |
|
| 98 | + $this->assertContains(EnvironmentCheck::OK, $cacheHeadersCheck->check()); |
|
| 99 | + $this->assertContains(EnvironmentCheck::ERROR, $cacheHeadersCheck->check()); |
|
| 100 | + } |
|
| 101 | 101 | } |
@@ -15,62 +15,62 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class SessionCheckTest extends SapphireTest |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * @var SilverStripe\EnvironmentCheck\Checks\SessionCheck |
|
| 20 | - */ |
|
| 21 | - public $sessionCheck = null; |
|
| 18 | + /** |
|
| 19 | + * @var SilverStripe\EnvironmentCheck\Checks\SessionCheck |
|
| 20 | + */ |
|
| 21 | + public $sessionCheck = null; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Create a session check for use by tests. |
|
| 25 | - * |
|
| 26 | - * @return void |
|
| 27 | - */ |
|
| 28 | - protected function setUp() |
|
| 29 | - { |
|
| 30 | - parent::setUp(); |
|
| 31 | - $this->sessionCheck = new SessionCheck('/'); |
|
| 32 | - } |
|
| 23 | + /** |
|
| 24 | + * Create a session check for use by tests. |
|
| 25 | + * |
|
| 26 | + * @return void |
|
| 27 | + */ |
|
| 28 | + protected function setUp() |
|
| 29 | + { |
|
| 30 | + parent::setUp(); |
|
| 31 | + $this->sessionCheck = new SessionCheck('/'); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Env check reports error when session cookies are being set. |
|
| 36 | - * |
|
| 37 | - * @return void |
|
| 38 | - */ |
|
| 39 | - public function testSessionSet() |
|
| 40 | - { |
|
| 41 | - // Create a mock and queue two responses. |
|
| 42 | - $mock = new MockHandler([ |
|
| 43 | - new Response(200, ['Set-Cookie' => 'PHPSESSID:foo']), |
|
| 44 | - new Response(200, ['Set-Cookie' => 'SECSESSID:bar']) |
|
| 45 | - ]); |
|
| 34 | + /** |
|
| 35 | + * Env check reports error when session cookies are being set. |
|
| 36 | + * |
|
| 37 | + * @return void |
|
| 38 | + */ |
|
| 39 | + public function testSessionSet() |
|
| 40 | + { |
|
| 41 | + // Create a mock and queue two responses. |
|
| 42 | + $mock = new MockHandler([ |
|
| 43 | + new Response(200, ['Set-Cookie' => 'PHPSESSID:foo']), |
|
| 44 | + new Response(200, ['Set-Cookie' => 'SECSESSID:bar']) |
|
| 45 | + ]); |
|
| 46 | 46 | |
| 47 | - $handler = HandlerStack::create($mock); |
|
| 48 | - $client = new Client(['handler' => $handler]); |
|
| 49 | - $this->sessionCheck->client = $client; |
|
| 47 | + $handler = HandlerStack::create($mock); |
|
| 48 | + $client = new Client(['handler' => $handler]); |
|
| 49 | + $this->sessionCheck->client = $client; |
|
| 50 | 50 | |
| 51 | - // Check for PHPSESSID |
|
| 52 | - $this->assertContains(EnvironmentCheck::ERROR, $this->sessionCheck->check()); |
|
| 51 | + // Check for PHPSESSID |
|
| 52 | + $this->assertContains(EnvironmentCheck::ERROR, $this->sessionCheck->check()); |
|
| 53 | 53 | |
| 54 | - // Check for SECSESSID |
|
| 55 | - $this->assertContains(EnvironmentCheck::ERROR, $this->sessionCheck->check()); |
|
| 56 | - } |
|
| 54 | + // Check for SECSESSID |
|
| 55 | + $this->assertContains(EnvironmentCheck::ERROR, $this->sessionCheck->check()); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Env check responds OK when no session cookies are set in response. |
|
| 60 | - * |
|
| 61 | - * @return void |
|
| 62 | - */ |
|
| 63 | - public function testSessionNotSet() |
|
| 64 | - { |
|
| 65 | - // Create a mock and queue two responses. |
|
| 66 | - $mock = new MockHandler([ |
|
| 67 | - new Response(200) |
|
| 68 | - ]); |
|
| 58 | + /** |
|
| 59 | + * Env check responds OK when no session cookies are set in response. |
|
| 60 | + * |
|
| 61 | + * @return void |
|
| 62 | + */ |
|
| 63 | + public function testSessionNotSet() |
|
| 64 | + { |
|
| 65 | + // Create a mock and queue two responses. |
|
| 66 | + $mock = new MockHandler([ |
|
| 67 | + new Response(200) |
|
| 68 | + ]); |
|
| 69 | 69 | |
| 70 | - $handler = HandlerStack::create($mock); |
|
| 71 | - $client = new Client(['handler' => $handler]); |
|
| 72 | - $this->sessionCheck->client = $client; |
|
| 70 | + $handler = HandlerStack::create($mock); |
|
| 71 | + $client = new Client(['handler' => $handler]); |
|
| 72 | + $this->sessionCheck->client = $client; |
|
| 73 | 73 | |
| 74 | - $this->assertContains(EnvironmentCheck::OK, $this->sessionCheck->check()); |
|
| 75 | - } |
|
| 74 | + $this->assertContains(EnvironmentCheck::OK, $this->sessionCheck->check()); |
|
| 75 | + } |
|
| 76 | 76 | } |