mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-08 10:41:25 +02:00
The main benefit of this is so that authors who make use of .editorconfig don't end up with whitespace changes in their PRs. Spaces vs. tabs has been left alone, although that could do with a tidy-up in SS4 after the switch to PSR-1/2. The command used was this: for match in '*.ss' '*.css' '*.scss' '*.html' '*.yml' '*.php' '*.js' '*.csv' '*.inc' '*.php5'; do find . -path ./thirdparty -not -prune -o -path ./admin/thirdparty -not -prune -o -type f -name "$match" -exec sed -E -i '' 's/[[:space:]]+$//' {} \+ find . -path ./thirdparty -not -prune -o -path ./admin/thirdparty -not -prune -o -type f -name "$match" | xargs perl -pi -e 's/ +$//' done
72 lines
2.3 KiB
PHP
72 lines
2.3 KiB
PHP
<?php
|
|
|
|
class HtmlEditorFieldToolbarTest_Toolbar extends HtmlEditorField_Toolbar {
|
|
public function viewfile_getLocalFileByID($id) {
|
|
return parent::viewfile_getLocalFileByID($id);
|
|
}
|
|
|
|
public function viewfile_getLocalFileByURL($fileUrl) {
|
|
return parent::viewfile_getLocalFileByURL($fileUrl);
|
|
}
|
|
|
|
public function viewfile_getRemoteFileByURL($fileUrl) {
|
|
return parent::viewfile_getRemoteFileByURL($fileUrl);
|
|
}
|
|
}
|
|
|
|
class HtmlEditorFieldToolbarTest extends SapphireTest {
|
|
|
|
protected static $fixture_file = 'HtmlEditorFieldToolbarTest.yml';
|
|
|
|
protected function getToolbar() {
|
|
return new HtmlEditorFieldToolbarTest_Toolbar(null, '/');
|
|
}
|
|
|
|
public function setUp() {
|
|
parent::setUp();
|
|
|
|
Config::nest();
|
|
Config::inst()->update('HtmlEditorField_Toolbar', 'fileurl_scheme_whitelist', array('http'));
|
|
Config::inst()->update('HtmlEditorField_Toolbar', 'fileurl_domain_whitelist', array('example.com'));
|
|
}
|
|
|
|
public function tearDown() {
|
|
Config::unnest();
|
|
|
|
parent::tearDown();
|
|
}
|
|
|
|
public function testValidLocalReference() {
|
|
list($file, $url) = $this->getToolbar()->viewfile_getLocalFileByURL('folder/subfolder/example.pdf');
|
|
$this->assertEquals($this->objFromFixture('File', 'example_file'), $file);
|
|
}
|
|
|
|
public function testInvalidLocalReference() {
|
|
list($file, $url) = $this->getToolbar()->viewfile_getLocalFileByURL('folder/subfolder/missing.pdf');
|
|
$this->assertNull($file);
|
|
}
|
|
|
|
public function testValidScheme() {
|
|
list($file, $url) = $this->getToolbar()->viewfile_getRemoteFileByURL('http://example.com/test.pdf');
|
|
$this->assertInstanceOf('File', $file);
|
|
$this->assertEquals($file->Filename, 'http://example.com/test.pdf');
|
|
}
|
|
|
|
/** @expectedException SS_HTTPResponse_Exception */
|
|
public function testInvalidScheme() {
|
|
list($file, $url) = $this->getToolbar()->viewfile_getRemoteFileByURL('nosuchscheme://example.com/test.pdf');
|
|
}
|
|
|
|
public function testValidDomain() {
|
|
list($file, $url) = $this->getToolbar()->viewfile_getRemoteFileByURL('http://example.com/test.pdf');
|
|
$this->assertInstanceOf('File', $file);
|
|
$this->assertEquals($file->Filename, 'http://example.com/test.pdf');
|
|
}
|
|
|
|
/** @expectedException SS_HTTPResponse_Exception */
|
|
public function testInvalidDomain() {
|
|
list($file, $url) = $this->getToolbar()->viewfile_getRemoteFileByURL('http://evil.com/test.pdf');
|
|
}
|
|
|
|
}
|