@@ -20,104 +20,104 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class CwpControllerExtensionTest extends SapphireTest |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * @var Controller |
|
| 25 | - */ |
|
| 26 | - protected $controller; |
|
| 23 | + /** |
|
| 24 | + * @var Controller |
|
| 25 | + */ |
|
| 26 | + protected $controller; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var CanonicalURLMiddleware |
|
| 30 | - */ |
|
| 31 | - protected $middlewareMock; |
|
| 28 | + /** |
|
| 29 | + * @var CanonicalURLMiddleware |
|
| 30 | + */ |
|
| 31 | + protected $middlewareMock; |
|
| 32 | 32 | |
| 33 | - protected function setUp() |
|
| 34 | - { |
|
| 35 | - parent::setUp(); |
|
| 33 | + protected function setUp() |
|
| 34 | + { |
|
| 35 | + parent::setUp(); |
|
| 36 | 36 | |
| 37 | - $this->logOut(); |
|
| 37 | + $this->logOut(); |
|
| 38 | 38 | |
| 39 | - $this->controller = new Controller(); |
|
| 39 | + $this->controller = new Controller(); |
|
| 40 | 40 | |
| 41 | - $request = new HTTPRequest('GET', '/'); |
|
| 42 | - $request->setSession(new Session([])); |
|
| 41 | + $request = new HTTPRequest('GET', '/'); |
|
| 42 | + $request->setSession(new Session([])); |
|
| 43 | 43 | |
| 44 | - $this->controller->setRequest($request); |
|
| 44 | + $this->controller->setRequest($request); |
|
| 45 | 45 | |
| 46 | - $this->middlewareMock = $this->getMockBuilder(CanonicalURLMiddleware::class) |
|
| 47 | - ->setMethods(['setForceSSL']) |
|
| 48 | - ->getMock(); |
|
| 46 | + $this->middlewareMock = $this->getMockBuilder(CanonicalURLMiddleware::class) |
|
| 47 | + ->setMethods(['setForceSSL']) |
|
| 48 | + ->getMock(); |
|
| 49 | 49 | |
| 50 | - Injector::inst()->registerService($this->middlewareMock, CanonicalURLMiddleware::class); |
|
| 51 | - } |
|
| 50 | + Injector::inst()->registerService($this->middlewareMock, CanonicalURLMiddleware::class); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - public function testRedirectsSSLToDomain() |
|
| 54 | - { |
|
| 55 | - Config::modify()->set(Director::class, 'alternate_base_url', 'http://nothttps.local'); |
|
| 53 | + public function testRedirectsSSLToDomain() |
|
| 54 | + { |
|
| 55 | + Config::modify()->set(Director::class, 'alternate_base_url', 'http://nothttps.local'); |
|
| 56 | 56 | |
| 57 | - // Expecting this to call forceSSL to forcedomain.org. |
|
| 58 | - $this->middlewareMock->expects($this->once()) |
|
| 59 | - ->method('setForceSSL') |
|
| 60 | - ->with(true) |
|
| 61 | - ->will($this->returnSelf()); |
|
| 57 | + // Expecting this to call forceSSL to forcedomain.org. |
|
| 58 | + $this->middlewareMock->expects($this->once()) |
|
| 59 | + ->method('setForceSSL') |
|
| 60 | + ->with(true) |
|
| 61 | + ->will($this->returnSelf()); |
|
| 62 | 62 | |
| 63 | - Config::modify()->set(CwpControllerExtension::class, 'ssl_redirection_enabled', true); |
|
| 64 | - Config::modify()->set(CwpControllerExtension::class, 'ssl_redirection_force_domain', 'forcedomain.org'); |
|
| 63 | + Config::modify()->set(CwpControllerExtension::class, 'ssl_redirection_enabled', true); |
|
| 64 | + Config::modify()->set(CwpControllerExtension::class, 'ssl_redirection_force_domain', 'forcedomain.org'); |
|
| 65 | 65 | |
| 66 | - $this->controller->handleRequest($this->controller->getRequest()); |
|
| 67 | - } |
|
| 66 | + $this->controller->handleRequest($this->controller->getRequest()); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - public function testRedirectsSSLToCurrentDomain() |
|
| 70 | - { |
|
| 71 | - Config::modify()->set(Director::class, 'alternate_base_url', 'http://nothttps.local'); |
|
| 69 | + public function testRedirectsSSLToCurrentDomain() |
|
| 70 | + { |
|
| 71 | + Config::modify()->set(Director::class, 'alternate_base_url', 'http://nothttps.local'); |
|
| 72 | 72 | |
| 73 | - // Expecting this to call forceSSL to current domain. |
|
| 74 | - $this->middlewareMock->expects($this->once()) |
|
| 75 | - ->method('setForceSSL') |
|
| 76 | - ->will($this->returnSelf()); |
|
| 73 | + // Expecting this to call forceSSL to current domain. |
|
| 74 | + $this->middlewareMock->expects($this->once()) |
|
| 75 | + ->method('setForceSSL') |
|
| 76 | + ->will($this->returnSelf()); |
|
| 77 | 77 | |
| 78 | - Config::modify()->set(CwpControllerExtension::class, 'ssl_redirection_enabled', true); |
|
| 79 | - Config::modify()->set(CwpControllerExtension::class, 'ssl_redirection_force_domain', false); |
|
| 78 | + Config::modify()->set(CwpControllerExtension::class, 'ssl_redirection_enabled', true); |
|
| 79 | + Config::modify()->set(CwpControllerExtension::class, 'ssl_redirection_force_domain', false); |
|
| 80 | 80 | |
| 81 | - $this->controller->handleRequest($this->controller->getRequest()); |
|
| 82 | - } |
|
| 81 | + $this->controller->handleRequest($this->controller->getRequest()); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - public function testRequiresLoginForTest() |
|
| 85 | - { |
|
| 86 | - Injector::inst()->get(Kernel::class)->setEnvironment('test'); |
|
| 84 | + public function testRequiresLoginForTest() |
|
| 85 | + { |
|
| 86 | + Injector::inst()->get(Kernel::class)->setEnvironment('test'); |
|
| 87 | 87 | |
| 88 | - try { |
|
| 89 | - $this->controller->handleRequest($this->controller->getRequest()); |
|
| 90 | - } catch (Exception $e) { |
|
| 91 | - $this->assertEquals($e->getResponse()->getStatusCode(), '401', 'Forces BasicAuth on test'); |
|
| 88 | + try { |
|
| 89 | + $this->controller->handleRequest($this->controller->getRequest()); |
|
| 90 | + } catch (Exception $e) { |
|
| 91 | + $this->assertEquals($e->getResponse()->getStatusCode(), '401', 'Forces BasicAuth on test'); |
|
| 92 | 92 | |
| 93 | - // We need to pop manually, since throwing an SS_HTTPResponse_Exception in onBeforeInit hijacks |
|
| 94 | - // the normal Controller control flow and confuses TestRunner (as they share global controller stack). |
|
| 95 | - $this->controller->popCurrent(); |
|
| 96 | - } |
|
| 97 | - } |
|
| 93 | + // We need to pop manually, since throwing an SS_HTTPResponse_Exception in onBeforeInit hijacks |
|
| 94 | + // the normal Controller control flow and confuses TestRunner (as they share global controller stack). |
|
| 95 | + $this->controller->popCurrent(); |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - public function testRequiresLoginForNonTest() |
|
| 100 | - { |
|
| 101 | - Injector::inst()->get(Kernel::class)->setEnvironment('live'); |
|
| 99 | + public function testRequiresLoginForNonTest() |
|
| 100 | + { |
|
| 101 | + Injector::inst()->get(Kernel::class)->setEnvironment('live'); |
|
| 102 | 102 | |
| 103 | - $response = $this->controller->handleRequest($this->controller->getRequest()); |
|
| 104 | - $this->assertEquals($response->getStatusCode(), '200', 'Does not force BasicAuth on live'); |
|
| 105 | - } |
|
| 103 | + $response = $this->controller->handleRequest($this->controller->getRequest()); |
|
| 104 | + $this->assertEquals($response->getStatusCode(), '200', 'Does not force BasicAuth on live'); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - public function testRequiresLoginForLiveWhenEnabled() |
|
| 108 | - { |
|
| 109 | - Config::modify()->set(CwpControllerExtension::class, 'live_basicauth_enabled', true); |
|
| 107 | + public function testRequiresLoginForLiveWhenEnabled() |
|
| 108 | + { |
|
| 109 | + Config::modify()->set(CwpControllerExtension::class, 'live_basicauth_enabled', true); |
|
| 110 | 110 | |
| 111 | - Injector::inst()->get(Kernel::class)->setEnvironment('live'); |
|
| 111 | + Injector::inst()->get(Kernel::class)->setEnvironment('live'); |
|
| 112 | 112 | |
| 113 | - try { |
|
| 114 | - $this->controller->handleRequest($this->controller->getRequest()); |
|
| 115 | - } catch (Exception $e) { |
|
| 116 | - $this->assertEquals($e->getResponse()->getStatusCode(), '401', 'Forces BasicAuth on live (optionally)'); |
|
| 113 | + try { |
|
| 114 | + $this->controller->handleRequest($this->controller->getRequest()); |
|
| 115 | + } catch (Exception $e) { |
|
| 116 | + $this->assertEquals($e->getResponse()->getStatusCode(), '401', 'Forces BasicAuth on live (optionally)'); |
|
| 117 | 117 | |
| 118 | - // We need to pop manually, since throwing an SS_HTTPResponse_Exception in onBeforeInit hijacks |
|
| 119 | - // the normal Controller control flow and confuses TestRunner (as they share global controller stack). |
|
| 120 | - $this->controller->popCurrent(); |
|
| 121 | - } |
|
| 122 | - } |
|
| 118 | + // We need to pop manually, since throwing an SS_HTTPResponse_Exception in onBeforeInit hijacks |
|
| 119 | + // the normal Controller control flow and confuses TestRunner (as they share global controller stack). |
|
| 120 | + $this->controller->popCurrent(); |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | 123 | } |
@@ -14,67 +14,67 @@ |
||
| 14 | 14 | |
| 15 | 15 | class AtomFeedTest extends SapphireTest |
| 16 | 16 | { |
| 17 | - protected static $original_host; |
|
| 17 | + protected static $original_host; |
|
| 18 | 18 | |
| 19 | - public function testAtomFeed() |
|
| 20 | - { |
|
| 21 | - $list = new ArrayList(); |
|
| 22 | - $list->push(new ItemA()); |
|
| 23 | - $list->push(new ItemB()); |
|
| 24 | - $list->push(new ItemC()); |
|
| 19 | + public function testAtomFeed() |
|
| 20 | + { |
|
| 21 | + $list = new ArrayList(); |
|
| 22 | + $list->push(new ItemA()); |
|
| 23 | + $list->push(new ItemB()); |
|
| 24 | + $list->push(new ItemC()); |
|
| 25 | 25 | |
| 26 | - $atomFeed = new CwpAtomFeed( |
|
| 27 | - $list, |
|
| 28 | - "http://www.example.com", |
|
| 29 | - "Test Atom Feed", |
|
| 30 | - "Test Atom Feed Description" |
|
| 31 | - ); |
|
| 32 | - $content = $atomFeed->outputToBrowser(); |
|
| 26 | + $atomFeed = new CwpAtomFeed( |
|
| 27 | + $list, |
|
| 28 | + "http://www.example.com", |
|
| 29 | + "Test Atom Feed", |
|
| 30 | + "Test Atom Feed Description" |
|
| 31 | + ); |
|
| 32 | + $content = $atomFeed->outputToBrowser(); |
|
| 33 | 33 | |
| 34 | - //Debug::message($content); |
|
| 35 | - $this->assertContains('<link href="http://www.example.org/item-a/" />', $content); |
|
| 36 | - $this->assertContains('<link href="http://www.example.com/item-b.html" />', $content); |
|
| 37 | - $this->assertContains('<link href="http://www.example.com/item-c.html" />', $content); |
|
| 34 | + //Debug::message($content); |
|
| 35 | + $this->assertContains('<link href="http://www.example.org/item-a/" />', $content); |
|
| 36 | + $this->assertContains('<link href="http://www.example.com/item-b.html" />', $content); |
|
| 37 | + $this->assertContains('<link href="http://www.example.com/item-c.html" />', $content); |
|
| 38 | 38 | |
| 39 | - $this->assertContains('<title type="html">ItemA</title>', $content); |
|
| 40 | - $this->assertContains('<title type="html">ItemB</title>', $content); |
|
| 41 | - $this->assertContains('<title type="html">ItemC</title>', $content); |
|
| 39 | + $this->assertContains('<title type="html">ItemA</title>', $content); |
|
| 40 | + $this->assertContains('<title type="html">ItemB</title>', $content); |
|
| 41 | + $this->assertContains('<title type="html">ItemC</title>', $content); |
|
| 42 | 42 | |
| 43 | - $this->assertContains("\tItemA Content\n", $content); |
|
| 44 | - $this->assertContains("\tItemB Content\n", $content); |
|
| 45 | - $this->assertContains("\tItemC Content\n", $content); |
|
| 46 | - } |
|
| 43 | + $this->assertContains("\tItemA Content\n", $content); |
|
| 44 | + $this->assertContains("\tItemB Content\n", $content); |
|
| 45 | + $this->assertContains("\tItemC Content\n", $content); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - public function testRenderWithTemplate() |
|
| 49 | - { |
|
| 50 | - $atomFeed = new CwpAtomFeed(new ArrayList(), "", "", ""); |
|
| 51 | - $content = $atomFeed->outputToBrowser(); |
|
| 52 | - // test we have switched from a RSS feed test template tot he AtomFeed template |
|
| 53 | - $this->assertNotContains('<title>Test Custom Template</title>', $content); |
|
| 54 | - } |
|
| 48 | + public function testRenderWithTemplate() |
|
| 49 | + { |
|
| 50 | + $atomFeed = new CwpAtomFeed(new ArrayList(), "", "", ""); |
|
| 51 | + $content = $atomFeed->outputToBrowser(); |
|
| 52 | + // test we have switched from a RSS feed test template tot he AtomFeed template |
|
| 53 | + $this->assertNotContains('<title>Test Custom Template</title>', $content); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - public function testLinkToFeed() |
|
| 57 | - { |
|
| 58 | - $link = AtomTagsStub::linkToFeed('atomLinkUrl', 'Atom feed of this blog'); |
|
| 59 | - $this->assertContains('atomLinkUrl', $link); |
|
| 60 | - $this->assertContains('Atom feed of this blog', $link); |
|
| 61 | - $this->assertContains('application/atom+xml', $link); |
|
| 62 | - } |
|
| 56 | + public function testLinkToFeed() |
|
| 57 | + { |
|
| 58 | + $link = AtomTagsStub::linkToFeed('atomLinkUrl', 'Atom feed of this blog'); |
|
| 59 | + $this->assertContains('atomLinkUrl', $link); |
|
| 60 | + $this->assertContains('Atom feed of this blog', $link); |
|
| 61 | + $this->assertContains('application/atom+xml', $link); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - protected function setUp() |
|
| 65 | - { |
|
| 66 | - parent::setUp(); |
|
| 67 | - Config::modify()->set(Director::class, 'alternate_base_url', '/'); |
|
| 68 | - if (!self::$original_host) { |
|
| 69 | - self::$original_host = $_SERVER['HTTP_HOST']; |
|
| 70 | - } |
|
| 71 | - $_SERVER['HTTP_HOST'] = 'www.example.org'; |
|
| 72 | - } |
|
| 64 | + protected function setUp() |
|
| 65 | + { |
|
| 66 | + parent::setUp(); |
|
| 67 | + Config::modify()->set(Director::class, 'alternate_base_url', '/'); |
|
| 68 | + if (!self::$original_host) { |
|
| 69 | + self::$original_host = $_SERVER['HTTP_HOST']; |
|
| 70 | + } |
|
| 71 | + $_SERVER['HTTP_HOST'] = 'www.example.org'; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - protected function tearDown() |
|
| 75 | - { |
|
| 76 | - parent::tearDown(); |
|
| 77 | - Config::modify()->set(Director::class, 'alternate_base_url', null); |
|
| 78 | - $_SERVER['HTTP_HOST'] = self::$original_host; |
|
| 79 | - } |
|
| 74 | + protected function tearDown() |
|
| 75 | + { |
|
| 76 | + parent::tearDown(); |
|
| 77 | + Config::modify()->set(Director::class, 'alternate_base_url', null); |
|
| 78 | + $_SERVER['HTTP_HOST'] = self::$original_host; |
|
| 79 | + } |
|
| 80 | 80 | } |
@@ -7,35 +7,35 @@ |
||
| 7 | 7 | |
| 8 | 8 | class RichLinksExtensionTest extends SapphireTest |
| 9 | 9 | { |
| 10 | - public function testContentLinkInjections() |
|
| 11 | - { |
|
| 12 | - $field = new DBText(); |
|
| 10 | + public function testContentLinkInjections() |
|
| 11 | + { |
|
| 12 | + $field = new DBText(); |
|
| 13 | 13 | |
| 14 | - // External links injection. |
|
| 15 | - $field->setValue('<a href="http://newzealand.govt.nz">New Zealand Government</a>'); |
|
| 16 | - $this->assertEquals( |
|
| 17 | - $field->RichLinks(), |
|
| 18 | - '<a class="external" rel="external" title="Open external link" ' |
|
| 19 | - . 'href="http://newzealand.govt.nz">New Zealand Government' |
|
| 20 | - .'<span class="nonvisual-indicator">(external link)</span></a>', |
|
| 21 | - 'Injects attributes to external link without target.' |
|
| 22 | - ); |
|
| 14 | + // External links injection. |
|
| 15 | + $field->setValue('<a href="http://newzealand.govt.nz">New Zealand Government</a>'); |
|
| 16 | + $this->assertEquals( |
|
| 17 | + $field->RichLinks(), |
|
| 18 | + '<a class="external" rel="external" title="Open external link" ' |
|
| 19 | + . 'href="http://newzealand.govt.nz">New Zealand Government' |
|
| 20 | + .'<span class="nonvisual-indicator">(external link)</span></a>', |
|
| 21 | + 'Injects attributes to external link without target.' |
|
| 22 | + ); |
|
| 23 | 23 | |
| 24 | - $field->setValue('<a href="http://newzealand.govt.nz" target="_blank">New Zealand Government</a>'); |
|
| 25 | - $this->assertEquals( |
|
| 26 | - $field->RichLinks(), |
|
| 27 | - '<a class="external" rel="external" title="Open external link" ' |
|
| 28 | - . 'href="http://newzealand.govt.nz" target="_blank">New Zealand Government' |
|
| 29 | - .'<span class="nonvisual-indicator">(external link)</span></a>', |
|
| 30 | - 'Injects attributes to external link with target, while keeping the existing attributes.' |
|
| 31 | - ); |
|
| 24 | + $field->setValue('<a href="http://newzealand.govt.nz" target="_blank">New Zealand Government</a>'); |
|
| 25 | + $this->assertEquals( |
|
| 26 | + $field->RichLinks(), |
|
| 27 | + '<a class="external" rel="external" title="Open external link" ' |
|
| 28 | + . 'href="http://newzealand.govt.nz" target="_blank">New Zealand Government' |
|
| 29 | + .'<span class="nonvisual-indicator">(external link)</span></a>', |
|
| 30 | + 'Injects attributes to external link with target, while keeping the existing attributes.' |
|
| 31 | + ); |
|
| 32 | 32 | |
| 33 | - // Check the normal links are not affected. |
|
| 34 | - $field->setValue('<a href="[sitetree_link,id=1]">Internal</a>'); |
|
| 35 | - $this->assertEquals( |
|
| 36 | - $field->RichLinks(), |
|
| 37 | - '<a href="[sitetree_link,id=1]">Internal</a>', |
|
| 38 | - 'Regular link is not modified.' |
|
| 39 | - ); |
|
| 40 | - } |
|
| 33 | + // Check the normal links are not affected. |
|
| 34 | + $field->setValue('<a href="[sitetree_link,id=1]">Internal</a>'); |
|
| 35 | + $this->assertEquals( |
|
| 36 | + $field->RichLinks(), |
|
| 37 | + '<a href="[sitetree_link,id=1]">Internal</a>', |
|
| 38 | + 'Regular link is not modified.' |
|
| 39 | + ); |
|
| 40 | + } |
|
| 41 | 41 | } |
@@ -11,11 +11,11 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class AtomTagsStub implements TestOnly |
| 13 | 13 | { |
| 14 | - public static function linkToFeed($url, $title = null) |
|
| 15 | - { |
|
| 16 | - $link = '<link rel="alternate" type="application/atom+xml" title="' . $title . |
|
| 17 | - '" href="' . $url . '" />'; |
|
| 18 | - CwpAtomFeed::linkToFeed($url, $title); |
|
| 19 | - return $link; |
|
| 20 | - } |
|
| 14 | + public static function linkToFeed($url, $title = null) |
|
| 15 | + { |
|
| 16 | + $link = '<link rel="alternate" type="application/atom+xml" title="' . $title . |
|
| 17 | + '" href="' . $url . '" />'; |
|
| 18 | + CwpAtomFeed::linkToFeed($url, $title); |
|
| 19 | + return $link; |
|
| 20 | + } |
|
| 21 | 21 | } |
@@ -7,33 +7,33 @@ |
||
| 7 | 7 | |
| 8 | 8 | class ItemC extends ViewableData implements TestOnly |
| 9 | 9 | { |
| 10 | - // ItemC tests fields - Title has casting, Content doesn't. |
|
| 11 | - private static $casting = [ |
|
| 12 | - 'Title' => 'Varchar', |
|
| 13 | - 'AltContent' => 'Text', |
|
| 14 | - ]; |
|
| 15 | - |
|
| 16 | - public $Title = 'ItemC'; |
|
| 17 | - |
|
| 18 | - public function Title() |
|
| 19 | - { |
|
| 20 | - return "ItemC"; |
|
| 21 | - } |
|
| 22 | - |
|
| 23 | - public function Content() |
|
| 24 | - { |
|
| 25 | - return "ItemC Content"; |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - public $AltContent = "ItemC AltContent"; |
|
| 29 | - |
|
| 30 | - public function Link() |
|
| 31 | - { |
|
| 32 | - return "item-c.html"; |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - public function AbsoluteLink() |
|
| 36 | - { |
|
| 37 | - return "http://www.example.com/item-c.html"; |
|
| 38 | - } |
|
| 10 | + // ItemC tests fields - Title has casting, Content doesn't. |
|
| 11 | + private static $casting = [ |
|
| 12 | + 'Title' => 'Varchar', |
|
| 13 | + 'AltContent' => 'Text', |
|
| 14 | + ]; |
|
| 15 | + |
|
| 16 | + public $Title = 'ItemC'; |
|
| 17 | + |
|
| 18 | + public function Title() |
|
| 19 | + { |
|
| 20 | + return "ItemC"; |
|
| 21 | + } |
|
| 22 | + |
|
| 23 | + public function Content() |
|
| 24 | + { |
|
| 25 | + return "ItemC Content"; |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + public $AltContent = "ItemC AltContent"; |
|
| 29 | + |
|
| 30 | + public function Link() |
|
| 31 | + { |
|
| 32 | + return "item-c.html"; |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + public function AbsoluteLink() |
|
| 36 | + { |
|
| 37 | + return "http://www.example.com/item-c.html"; |
|
| 38 | + } |
|
| 39 | 39 | } |
@@ -7,26 +7,26 @@ |
||
| 7 | 7 | |
| 8 | 8 | class ItemB extends ViewableData implements TestOnly |
| 9 | 9 | { |
| 10 | - // ItemB tests without $casting |
|
| 11 | - public $Title = 'ItemB'; |
|
| 10 | + // ItemB tests without $casting |
|
| 11 | + public $Title = 'ItemB'; |
|
| 12 | 12 | |
| 13 | - public function Title() |
|
| 14 | - { |
|
| 15 | - return "ItemB"; |
|
| 16 | - } |
|
| 13 | + public function Title() |
|
| 14 | + { |
|
| 15 | + return "ItemB"; |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - public function AbsoluteLink() |
|
| 19 | - { |
|
| 20 | - return "http://www.example.com/item-b.html"; |
|
| 21 | - } |
|
| 18 | + public function AbsoluteLink() |
|
| 19 | + { |
|
| 20 | + return "http://www.example.com/item-b.html"; |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - public function Content() |
|
| 24 | - { |
|
| 25 | - return "ItemB Content"; |
|
| 26 | - } |
|
| 23 | + public function Content() |
|
| 24 | + { |
|
| 25 | + return "ItemB Content"; |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - public function AltContent() |
|
| 29 | - { |
|
| 30 | - return "ItemB AltContent"; |
|
| 31 | - } |
|
| 28 | + public function AltContent() |
|
| 29 | + { |
|
| 30 | + return "ItemB AltContent"; |
|
| 31 | + } |
|
| 32 | 32 | } |
@@ -8,32 +8,32 @@ |
||
| 8 | 8 | |
| 9 | 9 | class ItemA extends ViewableData implements TestOnly |
| 10 | 10 | { |
| 11 | - // Atom-feed items must have $casting/$db information. |
|
| 12 | - private static $casting = [ |
|
| 13 | - 'Title' => 'Varchar', |
|
| 14 | - 'Content' => 'Text', |
|
| 15 | - 'AltContent' => 'Text', |
|
| 16 | - ]; |
|
| 17 | - |
|
| 18 | - public $Title = 'ItemA'; |
|
| 19 | - |
|
| 20 | - public function Title() |
|
| 21 | - { |
|
| 22 | - return "ItemA"; |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - public function Content() |
|
| 26 | - { |
|
| 27 | - return "ItemA Content"; |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - public function AltContent() |
|
| 31 | - { |
|
| 32 | - return "ItemA AltContent"; |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - public function Link($action = null) |
|
| 36 | - { |
|
| 37 | - return Controller::join_links("item-a/", $action); |
|
| 38 | - } |
|
| 11 | + // Atom-feed items must have $casting/$db information. |
|
| 12 | + private static $casting = [ |
|
| 13 | + 'Title' => 'Varchar', |
|
| 14 | + 'Content' => 'Text', |
|
| 15 | + 'AltContent' => 'Text', |
|
| 16 | + ]; |
|
| 17 | + |
|
| 18 | + public $Title = 'ItemA'; |
|
| 19 | + |
|
| 20 | + public function Title() |
|
| 21 | + { |
|
| 22 | + return "ItemA"; |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + public function Content() |
|
| 26 | + { |
|
| 27 | + return "ItemA Content"; |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + public function AltContent() |
|
| 31 | + { |
|
| 32 | + return "ItemA AltContent"; |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + public function Link($action = null) |
|
| 36 | + { |
|
| 37 | + return Controller::join_links("item-a/", $action); |
|
| 38 | + } |
|
| 39 | 39 | } |
@@ -93,7 +93,7 @@ |
||
| 93 | 93 | */ |
| 94 | 94 | protected function runMiddleware() |
| 95 | 95 | { |
| 96 | - $this->middleware->process($this->request, function () { |
|
| 96 | + $this->middleware->process($this->request, function() { |
|
| 97 | 97 | // no op |
| 98 | 98 | }); |
| 99 | 99 | } |
@@ -10,105 +10,105 @@ |
||
| 10 | 10 | |
| 11 | 11 | class InitialisationMiddlewareTest extends FunctionalTest |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * @var HTTPRequest |
|
| 15 | - */ |
|
| 16 | - protected $request; |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * @var InitialisationMiddleware |
|
| 20 | - */ |
|
| 21 | - protected $middleware; |
|
| 22 | - |
|
| 23 | - protected function setUp() |
|
| 24 | - { |
|
| 25 | - parent::setUp(); |
|
| 26 | - |
|
| 27 | - $this->request = new HTTPRequest('GET', '/'); |
|
| 28 | - $this->middleware = new InitialisationMiddleware(); |
|
| 29 | - |
|
| 30 | - Environment::setEnv('SS_OUTBOUND_PROXY', ''); |
|
| 31 | - Environment::setEnv('SS_OUTBOUND_PROXY_PORT', ''); |
|
| 32 | - Environment::setEnv('NO_PROXY', ''); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - public function testDoNotConfigureProxyIfNoEnvironmentVarsAreSet() |
|
| 36 | - { |
|
| 37 | - $this->runMiddleware(); |
|
| 38 | - |
|
| 39 | - $this->assertEmpty( |
|
| 40 | - Environment::getEnv('http_proxy'), |
|
| 41 | - 'Proxy information is not set if no outbound proxy is configured' |
|
| 42 | - ); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - public function testConfigureEgressProxyWhenVarsAreSet() |
|
| 46 | - { |
|
| 47 | - Environment::setEnv('SS_OUTBOUND_PROXY', 'http://example.com'); |
|
| 48 | - Environment::setEnv('SS_OUTBOUND_PROXY_PORT', '8024'); |
|
| 49 | - |
|
| 50 | - $this->runMiddleware(); |
|
| 51 | - |
|
| 52 | - $this->assertEquals( |
|
| 53 | - 'http://example.com:8024', |
|
| 54 | - Environment::getEnv('http_proxy'), |
|
| 55 | - 'Proxy is configured with proxy and port' |
|
| 56 | - ); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - public function testDoNotConfigureProxyDomainExclusionsWhenNoneAreDefined() |
|
| 60 | - { |
|
| 61 | - Config::modify()->remove(InitialisationMiddleware::class, 'egress_proxy_exclude_domains'); |
|
| 62 | - |
|
| 63 | - $this->runMiddleware(); |
|
| 64 | - |
|
| 65 | - $this->assertSame( |
|
| 66 | - '', |
|
| 67 | - Environment::getEnv('NO_PROXY'), |
|
| 68 | - 'No domain exclusions are set when none are defined' |
|
| 69 | - ); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - public function testConfigureEgressProxyDomainExclusions() |
|
| 73 | - { |
|
| 74 | - Config::modify()->set( |
|
| 75 | - InitialisationMiddleware::class, |
|
| 76 | - 'egress_proxy_exclude_domains', |
|
| 77 | - 'example.com' |
|
| 78 | - ); |
|
| 79 | - |
|
| 80 | - Environment::setEnv('NO_PROXY', 'foo.com,bar.com'); |
|
| 81 | - |
|
| 82 | - $this->runMiddleware(); |
|
| 83 | - |
|
| 84 | - $this->assertSame( |
|
| 85 | - 'foo.com,bar.com,example.com', |
|
| 86 | - Environment::getEnv('NO_PROXY'), |
|
| 87 | - 'Domain exclusions are combined with existing values and configuration settings' |
|
| 88 | - ); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - public function testSecurityHeadersAddedByDefault() |
|
| 92 | - { |
|
| 93 | - $response = $this->get('test'); |
|
| 94 | - $this->assertArrayHasKey('x-xss-protection', $response->getHeaders()); |
|
| 95 | - $this->assertSame('1; mode=block', $response->getHeader('x-xss-protection')); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - public function testXSSProtectionHeaderNotAdded() |
|
| 99 | - { |
|
| 100 | - Config::modify()->set(InitialisationMiddleware::class, 'xss_protection_disabled', true); |
|
| 101 | - $response = $this->get('test'); |
|
| 102 | - $this->assertArrayNotHasKey('x-xss-protection', $response->getHeaders()); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Runs the middleware with a stubbed delegate |
|
| 107 | - */ |
|
| 108 | - protected function runMiddleware() |
|
| 109 | - { |
|
| 110 | - $this->middleware->process($this->request, function () { |
|
| 111 | - // no op |
|
| 112 | - }); |
|
| 113 | - } |
|
| 13 | + /** |
|
| 14 | + * @var HTTPRequest |
|
| 15 | + */ |
|
| 16 | + protected $request; |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * @var InitialisationMiddleware |
|
| 20 | + */ |
|
| 21 | + protected $middleware; |
|
| 22 | + |
|
| 23 | + protected function setUp() |
|
| 24 | + { |
|
| 25 | + parent::setUp(); |
|
| 26 | + |
|
| 27 | + $this->request = new HTTPRequest('GET', '/'); |
|
| 28 | + $this->middleware = new InitialisationMiddleware(); |
|
| 29 | + |
|
| 30 | + Environment::setEnv('SS_OUTBOUND_PROXY', ''); |
|
| 31 | + Environment::setEnv('SS_OUTBOUND_PROXY_PORT', ''); |
|
| 32 | + Environment::setEnv('NO_PROXY', ''); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + public function testDoNotConfigureProxyIfNoEnvironmentVarsAreSet() |
|
| 36 | + { |
|
| 37 | + $this->runMiddleware(); |
|
| 38 | + |
|
| 39 | + $this->assertEmpty( |
|
| 40 | + Environment::getEnv('http_proxy'), |
|
| 41 | + 'Proxy information is not set if no outbound proxy is configured' |
|
| 42 | + ); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + public function testConfigureEgressProxyWhenVarsAreSet() |
|
| 46 | + { |
|
| 47 | + Environment::setEnv('SS_OUTBOUND_PROXY', 'http://example.com'); |
|
| 48 | + Environment::setEnv('SS_OUTBOUND_PROXY_PORT', '8024'); |
|
| 49 | + |
|
| 50 | + $this->runMiddleware(); |
|
| 51 | + |
|
| 52 | + $this->assertEquals( |
|
| 53 | + 'http://example.com:8024', |
|
| 54 | + Environment::getEnv('http_proxy'), |
|
| 55 | + 'Proxy is configured with proxy and port' |
|
| 56 | + ); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + public function testDoNotConfigureProxyDomainExclusionsWhenNoneAreDefined() |
|
| 60 | + { |
|
| 61 | + Config::modify()->remove(InitialisationMiddleware::class, 'egress_proxy_exclude_domains'); |
|
| 62 | + |
|
| 63 | + $this->runMiddleware(); |
|
| 64 | + |
|
| 65 | + $this->assertSame( |
|
| 66 | + '', |
|
| 67 | + Environment::getEnv('NO_PROXY'), |
|
| 68 | + 'No domain exclusions are set when none are defined' |
|
| 69 | + ); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + public function testConfigureEgressProxyDomainExclusions() |
|
| 73 | + { |
|
| 74 | + Config::modify()->set( |
|
| 75 | + InitialisationMiddleware::class, |
|
| 76 | + 'egress_proxy_exclude_domains', |
|
| 77 | + 'example.com' |
|
| 78 | + ); |
|
| 79 | + |
|
| 80 | + Environment::setEnv('NO_PROXY', 'foo.com,bar.com'); |
|
| 81 | + |
|
| 82 | + $this->runMiddleware(); |
|
| 83 | + |
|
| 84 | + $this->assertSame( |
|
| 85 | + 'foo.com,bar.com,example.com', |
|
| 86 | + Environment::getEnv('NO_PROXY'), |
|
| 87 | + 'Domain exclusions are combined with existing values and configuration settings' |
|
| 88 | + ); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + public function testSecurityHeadersAddedByDefault() |
|
| 92 | + { |
|
| 93 | + $response = $this->get('test'); |
|
| 94 | + $this->assertArrayHasKey('x-xss-protection', $response->getHeaders()); |
|
| 95 | + $this->assertSame('1; mode=block', $response->getHeader('x-xss-protection')); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + public function testXSSProtectionHeaderNotAdded() |
|
| 99 | + { |
|
| 100 | + Config::modify()->set(InitialisationMiddleware::class, 'xss_protection_disabled', true); |
|
| 101 | + $response = $this->get('test'); |
|
| 102 | + $this->assertArrayNotHasKey('x-xss-protection', $response->getHeaders()); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Runs the middleware with a stubbed delegate |
|
| 107 | + */ |
|
| 108 | + protected function runMiddleware() |
|
| 109 | + { |
|
| 110 | + $this->middleware->process($this->request, function () { |
|
| 111 | + // no op |
|
| 112 | + }); |
|
| 113 | + } |
|
| 114 | 114 | } |
@@ -13,13 +13,13 @@ |
||
| 13 | 13 | class CustomHtmlEditorFieldToolbar extends Extension |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @param Form $form |
|
| 18 | - * @return void |
|
| 19 | - */ |
|
| 20 | - public function updateMediaForm(Form $form) |
|
| 21 | - { |
|
| 22 | - Requirements::add_i18n_javascript('cwp/cwp-core:javascript/lang'); |
|
| 23 | - Requirements::javascript('cwp/cwp-core:javascript/CustomHtmlEditorFieldToolbar.js'); |
|
| 24 | - } |
|
| 16 | + /** |
|
| 17 | + * @param Form $form |
|
| 18 | + * @return void |
|
| 19 | + */ |
|
| 20 | + public function updateMediaForm(Form $form) |
|
| 21 | + { |
|
| 22 | + Requirements::add_i18n_javascript('cwp/cwp-core:javascript/lang'); |
|
| 23 | + Requirements::javascript('cwp/cwp-core:javascript/CustomHtmlEditorFieldToolbar.js'); |
|
| 24 | + } |
|
| 25 | 25 | } |