diff options
author | Gerrit Uitslag <klapinklapin@gmail.com> | 2013-11-19 21:26:50 +0100 |
---|---|---|
committer | Gerrit Uitslag <klapinklapin@gmail.com> | 2013-11-19 21:26:50 +0100 |
commit | 703aeaef1a43b07dc5497dba72c98151466396cc (patch) | |
tree | 1e18a6b3fc3c28156c2e56f8a3d515b8dd6a9cf9 /_test/tests/lib | |
parent | 33c3b3817b00aa9384760813643fac0e33daaaff (diff) | |
parent | 14b3007921f7b66fc9e3621b861a3c83e7e9093c (diff) | |
download | rpg-703aeaef1a43b07dc5497dba72c98151466396cc.tar.gz rpg-703aeaef1a43b07dc5497dba72c98151466396cc.tar.bz2 |
Merge remote-tracking branch 'origin/master' into diff_navigation
Diffstat (limited to '_test/tests/lib')
-rw-r--r-- | _test/tests/lib/exe/css_at_import_less.test.php | 78 | ||||
-rw-r--r-- | _test/tests/lib/exe/css_css_compress.test.php | 40 | ||||
-rw-r--r-- | _test/tests/lib/exe/css_css_loadfile.test.php | 42 | ||||
-rw-r--r-- | _test/tests/lib/exe/fetch_imagetoken.test.php | 44 | ||||
-rw-r--r-- | _test/tests/lib/exe/fetch_statuscodes_external.test.php | 107 |
5 files changed, 287 insertions, 24 deletions
diff --git a/_test/tests/lib/exe/css_at_import_less.test.php b/_test/tests/lib/exe/css_at_import_less.test.php new file mode 100644 index 000000000..4a6efcf44 --- /dev/null +++ b/_test/tests/lib/exe/css_at_import_less.test.php @@ -0,0 +1,78 @@ +<?php + +require_once DOKU_INC.'lib/exe/css.php'; + +class css_at_import_less_test extends DokuWikiTest { + + protected $file = ''; + protected $import = ''; + + public function setUpFiles($subdir = '') { + + $dir = TMP_DIR . $subdir; + if (!is_dir($dir)) { + mkdir($dir, 0777, true); + } + if (!is_dir($dir)) { + $this->markTestSkipped('Could not create directory.'); + } + + $this->file = tempnam($dir, 'css'); + + $import = ''; + do { + if ($import) unlink($import); + $import = tempnam($dir, 'less'); + $ok = rename($import, $import.'.less'); + } while (!$ok); + + $this->import = $import.'.less'; + } + + private function csstest($input, $expected_css, $expected_less) { + $location = "http://test.com/"; + io_saveFile($this->file, $input); + $css = css_loadfile($this->file, $location); + $less = css_parseless($css); + $this->assertEquals($expected_css, $css); + $this->assertEquals($expected_less, $less); + } + + public function test_basic() { + $this->setUpFiles(); + + $import = preg_replace('#(^.*[/])#','',$this->import); + $in_css = '@import "'.$import.'";'; + $in_less = '@foo: "bar"; +content: @foo;'; + + $expected_css = '@import "/'.$import.'";'; + $expected_less = 'content: "bar";'; + + io_saveFile($this->import, $in_less); + $this->csstest($in_css, $expected_css, $expected_less); + } + + public function test_subdirectory() { + $this->setUpFiles('/foo/bar'); + + $import = preg_replace('#(^.*[/])#','',$this->import); + $in_css = '@import "'.$import.'";'; + $in_less = '@foo: "bar"; +content: @foo;'; + + $expected_css = '@import "/foo/bar/'.$import.'";'; + $expected_less = 'content: "bar";'; + + io_saveFile($this->import, $in_less); + $this->csstest($in_css, $expected_css, $expected_less); + } + + public function tearDown() { + unlink($this->file); + unlink($this->import); + unset($this->file, $this->import); + } +} + +//Setup VIM: ex: et ts=4 sw=4 : diff --git a/_test/tests/lib/exe/css_css_compress.test.php b/_test/tests/lib/exe/css_css_compress.test.php index a7c87b6a7..a614ea2fd 100644 --- a/_test/tests/lib/exe/css_css_compress.test.php +++ b/_test/tests/lib/exe/css_css_compress.test.php @@ -62,6 +62,46 @@ class css_css_compress_test extends DokuWikiTest { $this->assertEquals(css_compress($text), 'a{left:20px;top:20px}'); } + function test_shortening() { + $input = array( + 'margin:0em 0em 0em 0em ul.test margin:0em :0em div#FFFFFF {', + 'margin: 1px 1px 1px 1px;', + 'padding: 1px 2px 1px 2px;', + 'margin: 1px 2px 3px 1px;', + 'padding: 1px 2px 3px 4px;', + 'margin: 00.00em 0em 01.00px 0em;', + 'padding: 0010em 0010.00em 00.00em 00.00100em;', + 'padding: 0010% 0010.00% 00.00% 00.00100xxx;', + 'padding: 0.0em .0em 0.em 00.00em;', + 'padding: 01.0em;', + 'color: #FFFFFF;', + 'color: #777777;', + 'color: #123456;', + 'border: 01.0em solid #ffffff;', + ); + + $expected = array( + 'margin:0em 0em 0em 0em ul.test margin:0em :0em div#FFFFFF{', + 'margin:1px;', + 'padding:1px 2px;', + 'margin:1px 2px 3px 1px;', + 'padding:1px 2px 3px 4px;', + 'margin:0 0 1px 0;', + 'padding:10em 10em 0 .001em;', + 'padding:10% 10% 0 00.00100xxx;', + 'padding:0;', + 'padding:1em;', + 'color:#FFF;', + 'color:#777;', + 'color:#123456;', + 'border:1em solid #fff;', + ); + + $input = array_map('css_compress', $input); + + $this->assertEquals($expected, $input); + } + } //Setup VIM: ex: et ts=4 : diff --git a/_test/tests/lib/exe/css_css_loadfile.test.php b/_test/tests/lib/exe/css_css_loadfile.test.php index c89b69b2c..624becd29 100644 --- a/_test/tests/lib/exe/css_css_loadfile.test.php +++ b/_test/tests/lib/exe/css_css_loadfile.test.php @@ -3,13 +3,16 @@ require_once DOKU_INC.'lib/exe/css.php'; class css_css_loadfile_test extends DokuWikiTest { + + protected $file = ''; + public function setUp() { - $this->file = tempnam('/tmp', 'css'); + $this->file = tempnam(TMP_DIR, 'css'); } private function csstest($input, $output = null, $location = 'http://www.example.com/') { io_saveFile($this->file, $input); - $this->assertEquals(css_loadfile($this->file, $location), (is_null($output) ? $input : $output)); + $this->assertEquals((is_null($output) ? $input : $output), css_loadfile($this->file, $location)); } public function test_url_relative() { @@ -32,11 +35,15 @@ class css_css_loadfile_test extends DokuWikiTest { public function test_import_relative() { $this->csstest('@import "test/test.png";', '@import "http://www.example.com/test/test.png";'); $this->csstest('@import \'test/test.png\';', '@import \'http://www.example.com/test/test.png\';'); + $this->csstest('@import url(test/test.png);', '@import url(http://www.example.com/test/test.png);'); + $this->csstest('@import url("test/test.png");', '@import url("http://www.example.com/test/test.png");'); } public function test_import_absolute() { $this->csstest('@import "/test/test.png";'); $this->csstest('@import \'/test/test.png\';'); + $this->csstest('@import url(/test/test.png);'); + $this->csstest('@import url("/test/test.png");'); } public function test_import_with_protocol() { @@ -44,6 +51,37 @@ class css_css_loadfile_test extends DokuWikiTest { $this->csstest('@import "https://www.test.com/test/test.png";'); $this->csstest('@import \'http://www.test.com/test/test.png\';'); $this->csstest('@import \'https://www.test.com/test/test.png\';'); + $this->csstest('@import url(http://www.test.com/test/test.png);'); + $this->csstest('@import url("http://www.test.com/test/test.png");'); + } + + public function test_less_basic() { + $this->csstest('@import "test.less"', '@import "/test.less"'); + $this->csstest('@import "/test.less"', '@import "/test.less"'); + $this->csstest('@import "foo/test.less"', '@import "/foo/test.less"'); + $this->csstest('@import url(http://test.less)'); + } + + // more expected use, where less @import(ed) from e.g. lib/plugins/plugin_name + public function test_less_subdirectories() { + + unlink($this->file); + + $dir = TMP_DIR.'/foo/bar'; + if (!is_dir($dir)) { + mkdir($dir, 0777, true); + } + if (!is_dir($dir)) { + $this->markTestSkipped('Could not create directory.'); + } + + $this->file = tempnam($dir, 'css'); + + $this->csstest('@import "test.less"', '@import "/foo/bar/test.less"'); + $this->csstest('@import \'test.less\'', '@import \'/foo/bar/test.less\''); + $this->csstest('@import url(test.less)', '@import url(/foo/bar/test.less)'); + + $this->csstest('@import "abc/test.less"', '@import "/foo/bar/abc/test.less"'); } public function tearDown() { diff --git a/_test/tests/lib/exe/fetch_imagetoken.test.php b/_test/tests/lib/exe/fetch_imagetoken.test.php index 9e5b6e4a2..99e642557 100644 --- a/_test/tests/lib/exe/fetch_imagetoken.test.php +++ b/_test/tests/lib/exe/fetch_imagetoken.test.php @@ -23,10 +23,10 @@ class fetch_imagetoken_test extends DokuWikiTest { parent::setUp(); global $conf; - $conf['sendfile'] = 0; + $conf['xsendfile'] = 0; global $MIME, $EXT, $CACHE, $INPUT; // variables fetch creates in global scope -- should this be in fetch? - }
+ } function getUri() { $w = $this->width ? 'w='.$this->width.'&' : ''; @@ -39,14 +39,14 @@ class fetch_imagetoken_test extends DokuWikiTest { $request = new TestRequest(); return $request->get(array(),str_replace('{%token%}',$token,$this->getUri())); } -
- /**
+ + /** * modified image request with valid token * expect: header with mime-type * expect: content * expect: no error response - */
- function test_valid_token(){
+ */ + function test_valid_token(){ $valid_token = 'tok='.media_get_token($this->media, $this->width, $this->height).'&'; $response = $this->fetchResponse($valid_token); $this->assertTrue((bool)$response->getHeader('Content-Type')); @@ -54,24 +54,24 @@ class fetch_imagetoken_test extends DokuWikiTest { $status_code = $response->getStatusCode(); $this->assertTrue(is_null($status_code) || (200 == $status_code)); - }
-
- /**
+ } + + /** * modified image request with invalid token - * expect: 412 status code
- */
- function test_invalid_token(){
- $invalid_token = 'tok='.media_get_token('junk',200,100).'&';
- $this->assertEquals(412,$this->fetchResponse($invalid_token)->getStatusCode());
- }
-
- /**
- * modified image request with no token
* expect: 412 status code - */
- function test_missing_token(){
- $no_token = '';
- $this->assertEquals(412,$this->fetchResponse($notoken)->getStatusCode()); + */ + function test_invalid_token(){ + $invalid_token = 'tok='.media_get_token('junk',200,100).'&'; + $this->assertEquals(412,$this->fetchResponse($invalid_token)->getStatusCode()); + } + + /** + * modified image request with no token + * expect: 412 status code + */ + function test_missing_token(){ + $no_token = ''; + $this->assertEquals(412,$this->fetchResponse($no_token)->getStatusCode()); } /** diff --git a/_test/tests/lib/exe/fetch_statuscodes_external.test.php b/_test/tests/lib/exe/fetch_statuscodes_external.test.php new file mode 100644 index 000000000..79a45ec93 --- /dev/null +++ b/_test/tests/lib/exe/fetch_statuscodes_external.test.php @@ -0,0 +1,107 @@ +<?php + +/** + * @group internet + */ +class fetch_statuscodes_external_test extends DokuWikiTest { + + private $media = 'http://www.google.com/images/srpr/logo3w.png'; //used in media_get_from_url test too + private $width = 200; + private $height = 0; + + function setUp() { + + header('X-Test: check headers working'); + $header_check = function_exists('xdebug_get_headers') ? xdebug_get_headers() : headers_list(); + if(empty($header_check)) { + $this->markTestSkipped('headers not returned, perhaps your sapi does not return headers, try xdebug'); + } else { + header_remove('X-Test'); + } + + parent::setUp(); + + global $conf; + $conf['fetchsize'] = 500 * 1024; //500kb + $conf['xsendfile'] = 0; + + global $MIME, $EXT, $CACHE, $INPUT; // variables fetch creates in global scope -- should this be in fetch? + } + + function getUri() { + $w = $this->width ? 'w='.$this->width.'&' : ''; + $h = $this->height ? 'h='.$this->height.'&' : ''; + return '/lib/exe/fetch.php?'.$w.$h.'{%token%}media='.rawurlencode($this->media); + } + + function fetchResponse($token) { + $request = new TestRequest(); + return $request->get(array(), str_replace('{%token%}', $token, $this->getUri())); + } + + /** + * modified image request with valid token + * and not-modified image request with valid token + * + * expect: header with mime-type + * expect: content + * expect: no error response + */ + function test_valid_token() { + $valid_token_resize = 'tok='.media_get_token($this->media, $this->width, $this->height).'&'; + + $this->handlevalidresponse($valid_token_resize); + + //original size + $this->width = $this->height = 0; + $valid_token_original = 'tok='.media_get_token($this->media, $this->width, $this->height).'&'; + + $this->handlevalidresponse($valid_token_original); + + } + + /** + * Performs asserts for valid request + * + * @param $valid_token + */ + private function handlevalidresponse($valid_token){ + $response = $this->fetchResponse($valid_token); + $this->assertTrue((bool) $response->getHeader('Content-Type')); + $this->assertTrue((bool) ($response->getContent())); + + $status_code = $response->getStatusCode(); + $this->assertTrue(is_null($status_code) || (200 == $status_code)); + } + + /** + * modified image request with invalid token + * expect: 412 status code + */ + function test_invalid_token() { + $invalid_tokens = array( + 'invalid_token_wrongid' => media_get_token('junk', 200, 100), + 'invalid_token_wrongh' => media_get_token($this->media, 200, 10), + 'invalid_token_wrongw' => media_get_token($this->media, 20, 100), + 'invalid_token_wrongwh' => media_get_token($this->media, 20, 10) + ); + foreach($invalid_tokens as $invalid_token) + $this->assertEquals(412, $this->fetchResponse('tok='.$invalid_token.'&')->getStatusCode()); + + } + + /** + * modified image request with no token + * and not modified image with no token + * expect: 412 status code + */ + function test_missing_token() { + $no_token = ''; + + $this->assertEquals(412, $this->fetchResponse($no_token)->getStatusCode()); + + $this->width = $this->height = 0; + $this->assertEquals(412, $this->fetchResponse($no_token)->getStatusCode()); + } +} +//Setup VIM: ex: et ts=4 : |