From c8b12969295b0ead20d448176f971978d9061cf9 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sat, 29 Oct 2016 10:19:09 +0200 Subject: [PATCH 1/4] add adjusted StyleCI ruleset --- .styleci.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .styleci.yml diff --git a/.styleci.yml b/.styleci.yml new file mode 100644 index 00000000..eac39fb8 --- /dev/null +++ b/.styleci.yml @@ -0,0 +1,24 @@ +preset: recommended + +risky: false + +enabled: + - no_empty_comment + - align_equals + +disabled: + - blank_line_after_opening_tag + - blank_line_before_return + - concat_without_spaces + - declare_equal_normalize + - heredoc_to_nowdoc + - method_argument_space + - new_with_braces + - phpdoc_align + - phpdoc_no_access + - phpdoc_separation + - phpdoc_single_line_var_spacing + - phpdoc_summary + - short_array_syntax + - single_line_after_imports + - unalign_equals From 1f468239422d7beaa44f35a12ad8f9ff3df1549b Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sat, 29 Oct 2016 10:24:08 +0200 Subject: [PATCH 2/4] applying patch based on StyleCI ruleset --- lib/Configuration.php | 60 +++--- lib/Data/AbstractData.php | 1 - lib/Data/Database.php | 3 +- lib/Data/Filesystem.php | 3 +- lib/Filter.php | 2 - lib/I18n.php | 7 +- lib/Json.php | 1 - lib/Model.php | 2 - lib/Model/AbstractModel.php | 3 +- lib/Model/Comment.php | 9 +- lib/Model/Paste.php | 8 +- lib/Persistence/AbstractPersistence.php | 1 - lib/Persistence/PurgeLimiter.php | 1 - lib/Persistence/ServerSalt.php | 1 - lib/Persistence/TrafficLimiter.php | 1 - lib/PrivateBin.php | 5 +- lib/Request.php | 1 - lib/Sjcl.php | 3 +- lib/View.php | 1 - lib/Vizhash16x16.php | 14 +- tst/Bootstrap.php | 26 +-- tst/ConfigurationTest.php | 32 +-- tst/ConfigurationTestGenerator.php | 163 +++++++------- tst/Data/DatabaseTest.php | 52 ++--- tst/Data/FilesystemTest.php | 16 +- tst/I18nTest.php | 2 +- tst/JsonApiTest.php | 48 ++--- tst/ModelTest.php | 60 +++--- tst/PrivateBinTest.php | 270 ++++++++++++------------ tst/PrivateBinWithDbTest.php | 14 +- tst/RequestTest.php | 64 +++--- tst/ViewTest.php | 6 +- tst/Vizhash16x16Test.php | 2 +- 33 files changed, 430 insertions(+), 452 deletions(-) diff --git a/lib/Configuration.php b/lib/Configuration.php index 47daa5ac..0024701a 100644 --- a/lib/Configuration.php +++ b/lib/Configuration.php @@ -9,10 +9,8 @@ * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @version 1.0 */ - namespace PrivateBin; -use PrivateBin\I18n; use Exception; use PDO; @@ -37,51 +35,51 @@ class Configuration */ private static $_defaults = array( 'main' => array( - 'discussion' => true, - 'opendiscussion' => false, - 'password' => true, - 'fileupload' => false, + 'discussion' => true, + 'opendiscussion' => false, + 'password' => true, + 'fileupload' => false, 'burnafterreadingselected' => false, - 'defaultformatter' => 'plaintext', - 'syntaxhighlightingtheme' => null, - 'sizelimit' => 2097152, - 'template' => 'bootstrap', - 'notice' => '', - 'languageselection' => false, - 'languagedefault' => '', - 'urlshortener' => '', - 'icon' => 'identicon', - 'cspheader' => 'default-src \'none\'; manifest-src \'self\'; connect-src *; script-src \'self\'; style-src \'self\'; font-src \'self\'; img-src \'self\' data:; referrer no-referrer;', - 'zerobincompatibility' => false, + 'defaultformatter' => 'plaintext', + 'syntaxhighlightingtheme' => null, + 'sizelimit' => 2097152, + 'template' => 'bootstrap', + 'notice' => '', + 'languageselection' => false, + 'languagedefault' => '', + 'urlshortener' => '', + 'icon' => 'identicon', + 'cspheader' => 'default-src \'none\'; manifest-src \'self\'; connect-src *; script-src \'self\'; style-src \'self\'; font-src \'self\'; img-src \'self\' data:; referrer no-referrer;', + 'zerobincompatibility' => false, ), 'expire' => array( 'default' => '1week', - 'clone' => true, + 'clone' => true, ), 'expire_options' => array( - '5min' => 300, - '10min' => 600, - '1hour' => 3600, - '1day' => 86400, - '1week' => 604800, + '5min' => 300, + '10min' => 600, + '1hour' => 3600, + '1day' => 86400, + '1week' => 604800, '1month' => 2592000, - '1year' => 31536000, - 'never' => 0, + '1year' => 31536000, + 'never' => 0, ), 'formatter_options' => array( - 'plaintext' => 'Plain Text', + 'plaintext' => 'Plain Text', 'syntaxhighlighting' => 'Source Code', - 'markdown' => 'Markdown', + 'markdown' => 'Markdown', ), 'traffic' => array( - 'limit' => 10, + 'limit' => 10, 'header' => null, - 'dir' => 'data', + 'dir' => 'data', ), 'purge' => array( - 'limit' => 300, + 'limit' => 300, 'batchsize' => 10, - 'dir' => 'data', + 'dir' => 'data', ), 'model' => array( 'class' => 'Filesystem', diff --git a/lib/Data/AbstractData.php b/lib/Data/AbstractData.php index 1f9d3f8e..20008abd 100644 --- a/lib/Data/AbstractData.php +++ b/lib/Data/AbstractData.php @@ -9,7 +9,6 @@ * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @version 1.0 */ - namespace PrivateBin\Data; use stdClass; diff --git a/lib/Data/Database.php b/lib/Data/Database.php index 385ee94a..601c8f67 100644 --- a/lib/Data/Database.php +++ b/lib/Data/Database.php @@ -9,13 +9,12 @@ * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @version 1.0 */ - namespace PrivateBin\Data; -use PrivateBin\PrivateBin; use Exception; use PDO; use PDOException; +use PrivateBin\PrivateBin; use stdClass; /** diff --git a/lib/Data/Filesystem.php b/lib/Data/Filesystem.php index 7381dbdf..37f79860 100644 --- a/lib/Data/Filesystem.php +++ b/lib/Data/Filesystem.php @@ -9,11 +9,10 @@ * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @version 1.0 */ - namespace PrivateBin\Data; -use PrivateBin\Model\Paste; use PrivateBin\Json; +use PrivateBin\Model\Paste; /** * Filesystem diff --git a/lib/Filter.php b/lib/Filter.php index 9b1aece6..0ca1b1d7 100644 --- a/lib/Filter.php +++ b/lib/Filter.php @@ -9,10 +9,8 @@ * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @version 1.0 */ - namespace PrivateBin; -use PrivateBin\I18n; use Exception; /** diff --git a/lib/I18n.php b/lib/I18n.php index 7be42ea9..9410198a 100644 --- a/lib/I18n.php +++ b/lib/I18n.php @@ -9,7 +9,6 @@ * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @version 1.0 */ - namespace PrivateBin; /** @@ -296,12 +295,12 @@ class I18n switch (self::$_language) { case 'fr': case 'zh': - return ($n > 1 ? 1 : 0); + return $n > 1 ? 1 : 0; case 'pl': - return ($n == 1 ? 0 : $n % 10 >= 2 && $n % 10 <= 4 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2); + return $n == 1 ? 0 : $n % 10 >= 2 && $n % 10 <= 4 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2; // en, de default: - return ($n != 1 ? 1 : 0); + return $n != 1 ? 1 : 0; } } diff --git a/lib/Json.php b/lib/Json.php index 2f269565..a9ba09c7 100644 --- a/lib/Json.php +++ b/lib/Json.php @@ -9,7 +9,6 @@ * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @version 1.0 */ - namespace PrivateBin; use Exception; diff --git a/lib/Model.php b/lib/Model.php index 6e388e45..8819d303 100644 --- a/lib/Model.php +++ b/lib/Model.php @@ -9,10 +9,8 @@ * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @version 1.0 */ - namespace PrivateBin; -use PrivateBin\Data; use PrivateBin\Model\Paste; use PrivateBin\Persistence\PurgeLimiter; diff --git a/lib/Model/AbstractModel.php b/lib/Model/AbstractModel.php index 1bd436f2..180e6167 100644 --- a/lib/Model/AbstractModel.php +++ b/lib/Model/AbstractModel.php @@ -9,13 +9,12 @@ * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @version 1.0 */ - namespace PrivateBin\Model; +use Exception; use PrivateBin\Configuration; use PrivateBin\Data\AbstractData; use PrivateBin\Sjcl; -use Exception; use stdClass; /** diff --git a/lib/Model/Comment.php b/lib/Model/Comment.php index 1f4283f7..c4a7dd5b 100644 --- a/lib/Model/Comment.php +++ b/lib/Model/Comment.php @@ -9,14 +9,13 @@ * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @version 1.0 */ - namespace PrivateBin\Model; -use PrivateBin\Sjcl; -use PrivateBin\Persistence\TrafficLimiter; -use PrivateBin\Vizhash16x16; -use Identicon\Identicon; use Exception; +use Identicon\Identicon; +use PrivateBin\Persistence\TrafficLimiter; +use PrivateBin\Sjcl; +use PrivateBin\Vizhash16x16; /** * Comment diff --git a/lib/Model/Paste.php b/lib/Model/Paste.php index 97e6b97e..2502a4f9 100644 --- a/lib/Model/Paste.php +++ b/lib/Model/Paste.php @@ -9,13 +9,12 @@ * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @version 1.0 */ - namespace PrivateBin\Model; -use PrivateBin\PrivateBin; -use PrivateBin\Persistence\ServerSalt; -use PrivateBin\Sjcl; use Exception; +use PrivateBin\Persistence\ServerSalt; +use PrivateBin\PrivateBin; +use PrivateBin\Sjcl; /** * Paste @@ -307,7 +306,6 @@ class Paste extends AbstractModel $this->_data->meta->burnafterreading === true; } - /** * Check if paste has discussions enabled. * diff --git a/lib/Persistence/AbstractPersistence.php b/lib/Persistence/AbstractPersistence.php index d4dcd6c2..c52024ba 100644 --- a/lib/Persistence/AbstractPersistence.php +++ b/lib/Persistence/AbstractPersistence.php @@ -9,7 +9,6 @@ * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @version 1.0 */ - namespace PrivateBin\Persistence; use Exception; diff --git a/lib/Persistence/PurgeLimiter.php b/lib/Persistence/PurgeLimiter.php index d65eb320..a5111db2 100644 --- a/lib/Persistence/PurgeLimiter.php +++ b/lib/Persistence/PurgeLimiter.php @@ -9,7 +9,6 @@ * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @version 1.0 */ - namespace PrivateBin\Persistence; use PrivateBin\Configuration; diff --git a/lib/Persistence/ServerSalt.php b/lib/Persistence/ServerSalt.php index 1aa50ec0..0b3c7902 100644 --- a/lib/Persistence/ServerSalt.php +++ b/lib/Persistence/ServerSalt.php @@ -9,7 +9,6 @@ * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @version 1.0 */ - namespace PrivateBin\Persistence; use Exception; diff --git a/lib/Persistence/TrafficLimiter.php b/lib/Persistence/TrafficLimiter.php index 6c2ce42e..2545b280 100644 --- a/lib/Persistence/TrafficLimiter.php +++ b/lib/Persistence/TrafficLimiter.php @@ -9,7 +9,6 @@ * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @version 1.0 */ - namespace PrivateBin\Persistence; use PrivateBin\Configuration; diff --git a/lib/PrivateBin.php b/lib/PrivateBin.php index 68985e60..67d1f19d 100644 --- a/lib/PrivateBin.php +++ b/lib/PrivateBin.php @@ -9,12 +9,11 @@ * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @version 1.0 */ - namespace PrivateBin; -use PrivateBin\Persistence\TrafficLimiter; -use PrivateBin\Persistence\ServerSalt; use Exception; +use PrivateBin\Persistence\ServerSalt; +use PrivateBin\Persistence\TrafficLimiter; /** * PrivateBin diff --git a/lib/Request.php b/lib/Request.php index 03cd100e..59471f79 100644 --- a/lib/Request.php +++ b/lib/Request.php @@ -9,7 +9,6 @@ * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @version 1.0 */ - namespace PrivateBin; /** diff --git a/lib/Sjcl.php b/lib/Sjcl.php index 1e4ca2c8..69425875 100644 --- a/lib/Sjcl.php +++ b/lib/Sjcl.php @@ -9,7 +9,6 @@ * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @version 1.0 */ - namespace PrivateBin; /** @@ -31,7 +30,7 @@ class Sjcl */ public static function isValid($encoded) { - $accepted_keys = array('iv','v','iter','ks','ts','mode','adata','cipher','salt','ct'); + $accepted_keys = array('iv', 'v', 'iter', 'ks', 'ts', 'mode', 'adata', 'cipher', 'salt', 'ct'); // Make sure content is valid json $decoded = json_decode($encoded); diff --git a/lib/View.php b/lib/View.php index 45d7b3a0..494bcd5f 100644 --- a/lib/View.php +++ b/lib/View.php @@ -9,7 +9,6 @@ * @license http://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @version 1.0 */ - namespace PrivateBin; use Exception; diff --git a/lib/Vizhash16x16.php b/lib/Vizhash16x16.php index 5afca38a..265c3e9b 100644 --- a/lib/Vizhash16x16.php +++ b/lib/Vizhash16x16.php @@ -10,7 +10,6 @@ * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License * @version 0.0.5 beta PrivateBin 1.0 */ - namespace PrivateBin; /** @@ -23,7 +22,6 @@ namespace PrivateBin; * echo $data; * exit; */ - class Vizhash16x16 { /** @@ -105,7 +103,7 @@ class Vizhash16x16 $op = 'v'; if (($this->getInt() % 2) == 0) { $op = 'h'; - }; + } $image = $this->degrade($image, $op, array($r0, $g0, $b0), array(0, 0, 0)); for ($i = 0; $i < 7; ++$i) { @@ -189,7 +187,7 @@ class Vizhash16x16 $diffs = array( (($color2[0] - $color1[0]) / $size), (($color2[1] - $color1[1]) / $size), - (($color2[2] - $color1[2]) / $size) + (($color2[2] - $color1[2]) / $size), ); for ($i = 0; $i < $size; ++$i) { $r = $color1[0] + ($diffs[0] * $i); @@ -217,20 +215,20 @@ class Vizhash16x16 { switch ($action % 7) { case 0: - ImageFilledRectangle($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(), $color); + imagefilledrectangle($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(), $color); break; case 1: case 2: - ImageFilledEllipse($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(), $color); + imagefilledellipse($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(), $color); break; case 3: $points = array($this->getX(), $this->getY(), $this->getX(), $this->getY(), $this->getX(), $this->getY(), $this->getX(), $this->getY()); - ImageFilledPolygon($image, $points, 4, $color); + imagefilledpolygon($image, $points, 4, $color); break; default: $start = $this->getInt() * 360 / 256; $end = $start + $this->getInt() * 180 / 256; - ImageFilledArc($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(), $start, $end, $color, IMG_ARC_PIE); + imagefilledarc($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(), $start, $end, $color, IMG_ARC_PIE); } } } diff --git a/tst/Bootstrap.php b/tst/Bootstrap.php index 65e10397..1b423b29 100644 --- a/tst/Bootstrap.php +++ b/tst/Bootstrap.php @@ -36,12 +36,12 @@ class Helper * @var array */ private static $paste = array( - 'data' => '{"iv":"EN39/wd5Nk8HAiSG2K5AsQ","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"QKN1DBXe5PI","ct":"8hA83xDdXjD7K2qfmw5NdA"}', - 'attachment' => '{"iv":"Pd4pOKWkmDTT9uPwVwd5Ag","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ZIUhFTliVz4","ct":"6nOCU3peNDclDDpFtJEBKA"}', + 'data' => '{"iv":"EN39/wd5Nk8HAiSG2K5AsQ","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"QKN1DBXe5PI","ct":"8hA83xDdXjD7K2qfmw5NdA"}', + 'attachment' => '{"iv":"Pd4pOKWkmDTT9uPwVwd5Ag","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ZIUhFTliVz4","ct":"6nOCU3peNDclDDpFtJEBKA"}', 'attachmentname' => '{"iv":"76MkAtOGC4oFogX/aSMxRA","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ZIUhFTliVz4","ct":"b6Ae/U1xJdsX/+lATud4sQ"}', - 'meta' => array( - 'formatter' => 'plaintext', - 'postdate' => 1344803344, + 'meta' => array( + 'formatter' => 'plaintext', + 'postdate' => 1344803344, 'opendiscussion' => true, ), ); @@ -62,7 +62,7 @@ class Helper 'data' => '{"iv":"Pd4pOKWkmDTT9uPwVwd5Ag","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ZIUhFTliVz4","ct":"6nOCU3peNDclDDpFtJEBKA"}', 'meta' => array( 'nickname' => '{"iv":"76MkAtOGC4oFogX/aSMxRA","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ZIUhFTliVz4","ct":"b6Ae/U1xJdsX/+lATud4sQ"}', - 'vizhash' => 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABGUlEQVQokWOsl5/94983CNKQMjnxaOePf98MeKwPfNjkLZ3AgARab6b9+PeNEVnDj3/ff/z7ZiHnzsDA8Pv7H2TVPJw8EAYLAwb48OaVgIgYKycLsrYv378wMDB8//qdCVMDRA9EKSsnCwRBxNsepaLboMFlyMDAICAi9uHNK24GITQ/MDAwoNhgIGMLtwGrzegaLjw5jMz9+vUdnN17uwDCQDhJgk0O07yvX9+teDX1x79v6DYIsIjgcgMaYGFgYOBg4kJx2JejkAiBxAw+PzAwMNz4dp6wDXDw4MdNNOl0rWYsNkD89OLXI/xmo9sgzatJjAYmBgYGDiauD3/ePP18nVgb4MF89+M5ZX6js293wUMpnr8KTQMAxsCJnJ30apMAAAAASUVORK5CYII=', + 'vizhash' => 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABGUlEQVQokWOsl5/94983CNKQMjnxaOePf98MeKwPfNjkLZ3AgARab6b9+PeNEVnDj3/ff/z7ZiHnzsDA8Pv7H2TVPJw8EAYLAwb48OaVgIgYKycLsrYv378wMDB8//qdCVMDRA9EKSsnCwRBxNsepaLboMFlyMDAICAi9uHNK24GITQ/MDAwoNhgIGMLtwGrzegaLjw5jMz9+vUdnN17uwDCQDhJgk0O07yvX9+teDX1x79v6DYIsIjgcgMaYGFgYOBg4kJx2JejkAiBxAw+PzAwMNz4dp6wDXDw4MdNNOl0rWYsNkD89OLXI/xmo9sgzatJjAYmBgYGDiauD3/ePP18nVgb4MF89+M5ZX6js293wUMpnr8KTQMAxsCJnJ30apMAAAAASUVORK5CYII=', 'postdate' => 1344803528, ), ); @@ -103,9 +103,9 @@ class Helper */ public static function getPasteWithAttachment($meta = array()) { - $example = self::$paste; + $example = self::$paste; $example['meta']['salt'] = ServerSalt::generate(); - $example['meta'] = array_merge($example['meta'], $meta); + $example['meta'] = array_merge($example['meta'], $meta); return $example; } @@ -122,10 +122,10 @@ class Helper if (count($meta)) { $example['meta'] = $meta; } - $example['comments'] = array(); - $example['comment_count'] = 0; + $example['comments'] = array(); + $example['comment_count'] = 0; $example['comment_offset'] = 0; - $example['@context'] = 'js/paste.jsonld'; + $example['@context'] = 'js/paste.jsonld'; return json_encode($example); } @@ -146,7 +146,7 @@ class Helper */ public static function getComment($meta = array()) { - $example = self::$comment; + $example = self::$comment; $example['meta'] = array_merge($example['meta'], $meta); return $example; } @@ -158,7 +158,7 @@ class Helper */ public static function getCommentPost($meta = array()) { - $example = self::getComment($meta); + $example = self::getComment($meta); $example['nickname'] = $example['meta']['nickname']; unset($example['meta']['nickname']); return $example; diff --git a/tst/ConfigurationTest.php b/tst/ConfigurationTest.php index 7064a510..3b9b4420 100644 --- a/tst/ConfigurationTest.php +++ b/tst/ConfigurationTest.php @@ -12,11 +12,11 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase { /* Setup Routine */ Helper::confBackup(); - $this->_options = configuration::getDefaults(); + $this->_options = configuration::getDefaults(); $this->_options['model_options']['dir'] = PATH . $this->_options['model_options']['dir']; - $this->_options['traffic']['dir'] = PATH . $this->_options['traffic']['dir']; - $this->_options['purge']['dir'] = PATH . $this->_options['purge']['dir']; - $this->_minimalConfig = '[main]' . PHP_EOL . '[model]' . PHP_EOL . '[model_options]'; + $this->_options['traffic']['dir'] = PATH . $this->_options['traffic']['dir']; + $this->_options['purge']['dir'] = PATH . $this->_options['purge']['dir']; + $this->_minimalConfig = '[main]' . PHP_EOL . '[model]' . PHP_EOL . '[model_options]'; } public function tearDown() @@ -94,19 +94,19 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase public function testHandleWrongTypes() { - $original_options = $this->_options; + $original_options = $this->_options; $original_options['main']['syntaxhighlightingtheme'] = 'foo'; - $options = $original_options; - $options['main']['discussion'] = 'true'; - $options['main']['opendiscussion'] = 0; - $options['main']['password'] = -1; // evaluates to TRUE - $options['main']['fileupload'] = 'false'; - $options['expire_options']['foo'] = 'bar'; - $options['formatter_options'][] = 'foo'; + $options = $original_options; + $options['main']['discussion'] = 'true'; + $options['main']['opendiscussion'] = 0; + $options['main']['password'] = -1; // evaluates to TRUE + $options['main']['fileupload'] = 'false'; + $options['expire_options']['foo'] = 'bar'; + $options['formatter_options'][] = 'foo'; Helper::createIniFile(CONF, $options); - $conf = new Configuration; + $conf = new Configuration; $original_options['expire_options']['foo'] = intval('bar'); - $original_options['formatter_options'][0] = 'foo'; + $original_options['formatter_options'][0] = 'foo'; $this->assertEquals($original_options, $conf->get(), 'incorrect types are corrected'); } @@ -117,14 +117,14 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase unset($options['expire_options']['1year']); unset($options['expire_options']['never']); Helper::createIniFile(CONF, $options); - $conf = new Configuration; + $conf = new Configuration; $options['expire']['default'] = '5min'; $this->assertEquals($options, $conf->get(), 'not overriding "missing" subkeys'); } public function testHandlePreRenameConfig() { - $options = $this->_options; + $options = $this->_options; $options['model']['class'] = 'zerobin_data'; Helper::createIniFile(CONF, $options); $conf = new Configuration; diff --git a/tst/ConfigurationTestGenerator.php b/tst/ConfigurationTestGenerator.php index db174bff..1c39d7d5 100755 --- a/tst/ConfigurationTestGenerator.php +++ b/tst/ConfigurationTestGenerator.php @@ -9,7 +9,6 @@ * DANGER: Too many options/settings and too high max iteration setting may trigger * a fork bomb. Please save your work before executing this script. */ - include 'Bootstrap.php'; $vrd = array('view', 'read', 'delete'); @@ -19,85 +18,85 @@ new ConfigurationTestGenerator(array( 'main/discussion' => array( array( 'setting' => true, - 'tests' => array( + 'tests' => array( array( 'conditions' => array('steps' => $vrd), - 'type' => 'RegExp', - 'args' => array( + 'type' => 'RegExp', + 'args' => array( '#]*id="opendisc"[^>]*>#', '$content', - 'outputs enabled discussion correctly' + 'outputs enabled discussion correctly', ), ), array( 'conditions' => array('steps' => array('create'), 'traffic/limit' => 10), - 'settings' => array('$_POST["opendiscussion"] = "neither 1 nor 0"'), - 'type' => 'Equals', - 'args' => array( + 'settings' => array('$_POST["opendiscussion"] = "neither 1 nor 0"'), + 'type' => 'Equals', + 'args' => array( 1, '$response["status"]', - 'when discussions are enabled, but invalid flag posted, fail to create paste' + 'when discussions are enabled, but invalid flag posted, fail to create paste', ), ), array( 'conditions' => array('steps' => array('create'), 'traffic/limit' => 10), - 'settings' => array('$_POST["opendiscussion"] = "neither 1 nor 0"'), - 'type' => 'False', - 'args' => array( + 'settings' => array('$_POST["opendiscussion"] = "neither 1 nor 0"'), + 'type' => 'False', + 'args' => array( '$this->_model->exists(Helper::getPasteId())', - 'when discussions are enabled, but invalid flag posted, paste is not created' + 'when discussions are enabled, but invalid flag posted, paste is not created', ), ), ), - 'affects' => $vcud + 'affects' => $vcud, ), array( 'setting' => false, - 'tests' => array( + 'tests' => array( array( 'type' => 'NotRegExp', 'args' => array( '#]*id="opendisc"[^>]*>#', '$content', - 'outputs disabled discussion correctly' + 'outputs disabled discussion correctly', ), ), ), - 'affects' => $vrd + 'affects' => $vrd, ), ), 'main/opendiscussion' => array( array( 'setting' => true, - 'tests' => array( + 'tests' => array( array( 'conditions' => array('main/discussion' => true), - 'type' => 'RegExp', - 'args' => array( + 'type' => 'RegExp', + 'args' => array( '#]+id="opendiscussion"[^>]*checked="checked"[^>]*>#', '$content', - 'outputs checked discussion correctly' + 'outputs checked discussion correctly', ), ), ), - 'affects' => $vrd + 'affects' => $vrd, ), array( 'setting' => false, - 'tests' => array( + 'tests' => array( array( 'conditions' => array('main/discussion' => true), - 'type' => 'NotRegExp', - 'args' => array( + 'type' => 'NotRegExp', + 'args' => array( '#]+id="opendiscussion"[^>]*checked="checked"[^>]*>#', '$content', - 'outputs unchecked discussion correctly' + 'outputs unchecked discussion correctly', ), ), ), - 'affects' => $vrd + 'affects' => $vrd, ), ), 'main/burnafterreadingselected' => array( array( 'setting' => true, - 'tests' => array( + 'tests' => array( array( 'type' => 'RegExp', 'args' => array( @@ -110,7 +109,7 @@ new ConfigurationTestGenerator(array( 'affects' => array('view'), ), array( 'setting' => false, - 'tests' => array( + 'tests' => array( array( 'type' => 'NotRegExp', 'args' => array( @@ -126,37 +125,37 @@ new ConfigurationTestGenerator(array( 'main/password' => array( array( 'setting' => true, - 'tests' => array( + 'tests' => array( array( 'type' => 'RegExp', 'args' => array( '#]*id="password"[^>]*>#', '$content', - 'outputs password input correctly' + 'outputs password input correctly', ), ), ), - 'affects' => $vrd + 'affects' => $vrd, ), array( 'setting' => false, - 'tests' => array( + 'tests' => array( array( 'conditions' => array('main/discussion' => true), - 'type' => 'NotRegExp', - 'args' => array( + 'type' => 'NotRegExp', + 'args' => array( '#]*id="password"[^>]*>#', '$content', - 'removes password input correctly' + 'removes password input correctly', ), ), ), - 'affects' => $vrd + 'affects' => $vrd, ), ), 'main/template' => array( array( 'setting' => 'page', - 'tests' => array( + 'tests' => array( array( 'type' => 'RegExp', 'args' => array( @@ -176,7 +175,7 @@ new ConfigurationTestGenerator(array( 'affects' => $vrd, ), array( 'setting' => 'bootstrap', - 'tests' => array( + 'tests' => array( array( 'type' => 'NotRegExp', 'args' => array( @@ -199,102 +198,102 @@ new ConfigurationTestGenerator(array( 'main/sizelimit' => array( array( 'setting' => 10, - 'tests' => array( + 'tests' => array( array( 'conditions' => array('steps' => array('create'), 'traffic/limit' => 10), - 'type' => 'Equals', - 'args' => array( + 'type' => 'Equals', + 'args' => array( 1, '$response["status"]', - 'when sizelimit limit exceeded, fail to create paste' + 'when sizelimit limit exceeded, fail to create paste', ), ), ), - 'affects' => array('create') + 'affects' => array('create'), ), array( 'setting' => 2097152, - 'tests' => array( + 'tests' => array( array( 'conditions' => array('steps' => array('create'), 'traffic/limit' => 0, 'main/burnafterreadingselected' => true), - 'settings' => array('sleep(3)'), - 'type' => 'Equals', - 'args' => array( + 'settings' => array('sleep(3)'), + 'type' => 'Equals', + 'args' => array( 0, '$response["status"]', - 'when sizelimit limit is not reached, successfully create paste' + 'when sizelimit limit is not reached, successfully create paste', ), ), array( 'conditions' => array('steps' => array('create'), 'traffic/limit' => 0, 'main/burnafterreadingselected' => true), - 'settings' => array('sleep(3)'), - 'type' => 'True', - 'args' => array( + 'settings' => array('sleep(3)'), + 'type' => 'True', + 'args' => array( '$this->_model->exists($response["id"])', - 'when sizelimit limit is not reached, paste exists after posting data' + 'when sizelimit limit is not reached, paste exists after posting data', ), ), ), - 'affects' => array('create') + 'affects' => array('create'), ), ), 'traffic/limit' => array( array( 'setting' => 0, - 'tests' => array( + 'tests' => array( array( 'conditions' => array('steps' => array('create'), 'main/sizelimit' => 2097152), - 'type' => 'Equals', - 'args' => array( + 'type' => 'Equals', + 'args' => array( 0, '$response["status"]', - 'when traffic limit is disabled, successfully create paste' + 'when traffic limit is disabled, successfully create paste', ), ), array( 'conditions' => array('steps' => array('create'), 'main/sizelimit' => 2097152), - 'type' => 'True', - 'args' => array( + 'type' => 'True', + 'args' => array( '$this->_model->exists($response["id"])', - 'when traffic limit is disabled, paste exists after posting data' + 'when traffic limit is disabled, paste exists after posting data', ), ), ), - 'affects' => array('create') + 'affects' => array('create'), ), array( 'setting' => 10, - 'tests' => array( + 'tests' => array( array( 'conditions' => array('steps' => array('create')), - 'type' => 'Equals', - 'args' => array( + 'type' => 'Equals', + 'args' => array( 1, '$response["status"]', - 'when traffic limit is on and we do not wait, fail to create paste' + 'when traffic limit is on and we do not wait, fail to create paste', ), ), ), - 'affects' => array('create') + 'affects' => array('create'), ), array( 'setting' => 2, - 'tests' => array( + 'tests' => array( array( 'conditions' => array('steps' => array('create'), 'main/sizelimit' => 2097152), - 'settings' => array('sleep(3)'), - 'type' => 'Equals', - 'args' => array( + 'settings' => array('sleep(3)'), + 'type' => 'Equals', + 'args' => array( 0, '$response["status"]', - 'when traffic limit is on and we wait, successfully create paste' + 'when traffic limit is on and we wait, successfully create paste', ), ), array( 'conditions' => array('steps' => array('create'), 'main/sizelimit' => 2097152), - 'settings' => array('sleep(3)'), - 'type' => 'True', - 'args' => array( + 'settings' => array('sleep(3)'), + 'type' => 'True', + 'args' => array( '$this->_model->exists($response["id"])', - 'when traffic limit is on and we wait, paste exists after posting data' + 'when traffic limit is on and we wait, paste exists after posting data', ), ), ), - 'affects' => array('create') + 'affects' => array('create'), ), ), )); @@ -325,7 +324,7 @@ class ConfigurationTestGenerator * @var array */ private $_configurations = array( - array('options' => array(), 'tests' => array(), 'affects' => array()) + array('options' => array(), 'tests' => array(), 'affects' => array()), ); /** @@ -346,10 +345,10 @@ class ConfigurationTestGenerator private function _writeConfigurationTest() { $defaultOptions = parse_ini_file(CONF, true); - $code = $this->_getHeader(); + $code = $this->_getHeader(); foreach ($this->_configurations as $key => $conf) { $fullOptions = array_replace_recursive($defaultOptions, $conf['options']); - $options = Helper::varExportMin($fullOptions, true); + $options = Helper::varExportMin($fullOptions, true); foreach ($conf['affects'] as $step) { $testCode = $preCode = array(); foreach ($conf['tests'] as $tests) { @@ -593,7 +592,7 @@ EOT; // create clones for each of the other settings while ($setting = next($settings)) { - $clone = $this->_configurations[$c]; + $clone = $this->_configurations[$c]; $this->_configurations[] = $this->_addSetting($clone, $setting, $section, $option); } reset($settings); @@ -626,7 +625,7 @@ EOT; throw new Exception("Endless loop or error in options detected: option '$option' already exists with setting '$val' in one of the configurations!"); } $configuration['options'][$section][$option] = $setting['setting']; - $configuration['tests'][$option] = array($setting['tests'], $setting['affects']); + $configuration['tests'][$option] = array($setting['tests'], $setting['affects']); foreach ($setting['affects'] as $affects) { if (!in_array($affects, $configuration['affects'])) { $configuration['affects'][] = $affects; diff --git a/tst/Data/DatabaseTest.php b/tst/Data/DatabaseTest.php index 37865e5d..01955694 100644 --- a/tst/Data/DatabaseTest.php +++ b/tst/Data/DatabaseTest.php @@ -19,7 +19,7 @@ class DatabaseTest extends PHPUnit_Framework_TestCase public function setUp() { /* Setup Routine */ - $this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data'; + $this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data'; $this->_model = Database::getInstance($this->_options); } @@ -47,8 +47,8 @@ class DatabaseTest extends PHPUnit_Framework_TestCase $this->assertFalse($this->_model->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId()), 'comment does not yet exist'); $this->assertTrue($this->_model->createComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId(), Helper::getComment()) !== false, 'store comment'); $this->assertTrue($this->_model->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId()), 'comment exists after storing it'); - $comment = json_decode(json_encode(Helper::getComment())); - $comment->id = Helper::getCommentId(); + $comment = json_decode(json_encode(Helper::getComment())); + $comment->id = Helper::getCommentId(); $comment->parentid = Helper::getPasteId(); $this->assertEquals( array($comment->meta->postdate => $comment), @@ -65,10 +65,10 @@ class DatabaseTest extends PHPUnit_Framework_TestCase public function testDatabaseBasedAttachmentStoreWorks() { $this->_model->delete(Helper::getPasteId()); - $original = $paste = Helper::getPasteWithAttachment(array('expire_date' => 1344803344)); + $original = $paste = Helper::getPasteWithAttachment(array('expire_date' => 1344803344)); $paste['meta']['burnafterreading'] = $original['meta']['burnafterreading'] = true; - $paste['meta']['attachment'] = $paste['attachment']; - $paste['meta']['attachmentname'] = $paste['attachmentname']; + $paste['meta']['attachment'] = $paste['attachment']; + $paste['meta']['attachmentname'] = $paste['attachmentname']; unset($paste['attachment'], $paste['attachmentname']); $this->assertFalse($this->_model->exists(Helper::getPasteId()), 'paste does not yet exist'); $this->assertTrue($this->_model->create(Helper::getPasteId(), $paste), 'store new paste'); @@ -81,9 +81,9 @@ class DatabaseTest extends PHPUnit_Framework_TestCase { $this->_model->delete(Helper::getPasteId()); $expired = Helper::getPaste(array('expire_date' => 1344803344)); - $paste = Helper::getPaste(array('expire_date' => time() + 3600)); - $keys = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'x', 'y', 'z'); - $ids = array(); + $paste = Helper::getPaste(array('expire_date' => time() + 3600)); + $keys = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'x', 'y', 'z'); + $ids = array(); foreach ($keys as $key) { $ids[$key] = substr(md5($key), 0, 16); $this->_model->delete($ids[$key]); @@ -113,7 +113,7 @@ class DatabaseTest extends PHPUnit_Framework_TestCase { Database::getInstance(array( 'dsn' => 'ibm:', 'usr' => null, 'pwd' => null, - 'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION) + 'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION), )); } @@ -124,7 +124,7 @@ class DatabaseTest extends PHPUnit_Framework_TestCase { Database::getInstance(array( 'dsn' => 'informix:', 'usr' => null, 'pwd' => null, - 'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION) + 'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION), )); } @@ -135,7 +135,7 @@ class DatabaseTest extends PHPUnit_Framework_TestCase { Database::getInstance(array( 'dsn' => 'mssql:', 'usr' => null, 'pwd' => null, - 'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION) + 'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION), )); } @@ -146,7 +146,7 @@ class DatabaseTest extends PHPUnit_Framework_TestCase { Database::getInstance(array( 'dsn' => 'mysql:', 'usr' => null, 'pwd' => null, - 'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION) + 'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION), )); } @@ -157,7 +157,7 @@ class DatabaseTest extends PHPUnit_Framework_TestCase { Database::getInstance(array( 'dsn' => 'oci:', 'usr' => null, 'pwd' => null, - 'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION) + 'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION), )); } @@ -168,7 +168,7 @@ class DatabaseTest extends PHPUnit_Framework_TestCase { Database::getInstance(array( 'dsn' => 'pgsql:', 'usr' => null, 'pwd' => null, - 'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION) + 'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION), )); } @@ -179,7 +179,7 @@ class DatabaseTest extends PHPUnit_Framework_TestCase public function testGetFooInstance() { Database::getInstance(array( - 'dsn' => 'foo:', 'usr' => null, 'pwd' => null, 'opt' => null + 'dsn' => 'foo:', 'usr' => null, 'pwd' => null, 'opt' => null, )); } @@ -231,13 +231,15 @@ class DatabaseTest extends PHPUnit_Framework_TestCase { mkdir($this->_path); $path = $this->_path . DIRECTORY_SEPARATOR . 'attachement-test.sq3'; - if (is_file($path)) unlink($path); + if (is_file($path)) { + unlink($path); + } $this->_options['dsn'] = 'sqlite:' . $path; $this->_options['tbl'] = 'bar_'; - $model = Database::getInstance($this->_options); + $model = Database::getInstance($this->_options); - $original = $paste = Helper::getPasteWithAttachment(array('expire_date' => 1344803344)); - $paste['meta']['attachment'] = $paste['attachment']; + $original = $paste = Helper::getPasteWithAttachment(array('expire_date' => 1344803344)); + $paste['meta']['attachment'] = $paste['attachment']; $paste['meta']['attachmentname'] = $paste['attachmentname']; unset($paste['attachment'], $paste['attachmentname']); $meta = $paste['meta']; @@ -274,10 +276,12 @@ class DatabaseTest extends PHPUnit_Framework_TestCase { mkdir($this->_path); $path = $this->_path . DIRECTORY_SEPARATOR . 'db-test.sq3'; - if (is_file($path)) unlink($path); + if (is_file($path)) { + unlink($path); + } $this->_options['dsn'] = 'sqlite:' . $path; $this->_options['tbl'] = 'foo_'; - $db = new PDO( + $db = new PDO( $this->_options['dsn'], $this->_options['usr'], $this->_options['pwd'], @@ -294,13 +298,13 @@ class DatabaseTest extends PHPUnit_Framework_TestCase ); $db->exec( 'CREATE TABLE foo_comment ( ' . - "dataid CHAR(16) NOT NULL, " . + 'dataid CHAR(16) NOT NULL, ' . 'pasteid CHAR(16), ' . 'parentid CHAR(16), ' . 'data BLOB, ' . 'nickname BLOB, ' . 'vizhash BLOB, ' . - "postdate INT );" + 'postdate INT );' ); $this->assertInstanceOf(Database::class, Database::getInstance($this->_options)); diff --git a/tst/Data/FilesystemTest.php b/tst/Data/FilesystemTest.php index d76bab1e..33e37c84 100644 --- a/tst/Data/FilesystemTest.php +++ b/tst/Data/FilesystemTest.php @@ -11,7 +11,7 @@ class FilesystemTest extends PHPUnit_Framework_TestCase public function setUp() { /* Setup Routine */ - $this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data'; + $this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data'; $this->_model = Filesystem::getInstance(array('dir' => $this->_path)); } @@ -37,8 +37,8 @@ class FilesystemTest extends PHPUnit_Framework_TestCase $this->assertFalse($this->_model->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId()), 'comment does not yet exist'); $this->assertTrue($this->_model->createComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId(), Helper::getComment()), 'store comment'); $this->assertTrue($this->_model->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId()), 'comment exists after storing it'); - $comment = json_decode(json_encode(Helper::getComment())); - $comment->id = Helper::getCommentId(); + $comment = json_decode(json_encode(Helper::getComment())); + $comment->id = Helper::getCommentId(); $comment->parentid = Helper::getPasteId(); $this->assertEquals( array($comment->meta->postdate => $comment), @@ -55,8 +55,8 @@ class FilesystemTest extends PHPUnit_Framework_TestCase public function testFileBasedAttachmentStoreWorks() { $this->_model->delete(Helper::getPasteId()); - $original = $paste = Helper::getPasteWithAttachment(array('expire_date' => 1344803344)); - $paste['meta']['attachment'] = $paste['attachment']; + $original = $paste = Helper::getPasteWithAttachment(array('expire_date' => 1344803344)); + $paste['meta']['attachment'] = $paste['attachment']; $paste['meta']['attachmentname'] = $paste['attachmentname']; unset($paste['attachment'], $paste['attachmentname']); $this->assertFalse($this->_model->exists(Helper::getPasteId()), 'paste does not yet exist'); @@ -70,9 +70,9 @@ class FilesystemTest extends PHPUnit_Framework_TestCase { mkdir($this->_path . DIRECTORY_SEPARATOR . '00', 0777, true); $expired = Helper::getPaste(array('expire_date' => 1344803344)); - $paste = Helper::getPaste(array('expire_date' => time() + 3600)); - $keys = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'x', 'y', 'z'); - $ids = array(); + $paste = Helper::getPaste(array('expire_date' => time() + 3600)); + $keys = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'x', 'y', 'z'); + $ids = array(); foreach ($keys as $key) { $ids[$key] = substr(md5($key), 0, 16); $this->assertFalse($this->_model->exists($ids[$key]), "paste $key does not yet exist"); diff --git a/tst/I18nTest.php b/tst/I18nTest.php index 8026c158..f2f4eadc 100644 --- a/tst/I18nTest.php +++ b/tst/I18nTest.php @@ -23,7 +23,7 @@ class I18nTest extends PHPUnit_Framework_TestCase public function testTranslationFallback() { $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'foobar'; - $messageId = 'It does not matter if the message ID exists'; + $messageId = 'It does not matter if the message ID exists'; I18n::loadTranslations(); $this->assertEquals($messageId, I18n::_($messageId), 'fallback to en'); } diff --git a/tst/JsonApiTest.php b/tst/JsonApiTest.php index 2cedde17..8579f013 100644 --- a/tst/JsonApiTest.php +++ b/tst/JsonApiTest.php @@ -1,9 +1,9 @@ _path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data'; + $this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data'; $this->_model = Filesystem::getInstance(array('dir' => $this->_path)); ServerSalt::setPath($this->_path); $this->reset(); @@ -30,16 +30,16 @@ class JsonApiTest extends PHPUnit_Framework_TestCase public function reset() { - $_POST = array(); - $_GET = array(); + $_POST = array(); + $_GET = array(); $_SERVER = array(); if ($this->_model->exists(Helper::getPasteId())) { $this->_model->delete(Helper::getPasteId()); } Helper::confRestore(); - $options = parse_ini_file(CONF, true); - $options['purge']['dir'] = $this->_path; - $options['traffic']['dir'] = $this->_path; + $options = parse_ini_file(CONF, true); + $options['purge']['dir'] = $this->_path; + $options['traffic']['dir'] = $this->_path; $options['model_options']['dir'] = $this->_path; Helper::confBackup(); Helper::createIniFile(CONF, $options); @@ -51,14 +51,14 @@ class JsonApiTest extends PHPUnit_Framework_TestCase public function testCreate() { $this->reset(); - $options = parse_ini_file(CONF, true); + $options = parse_ini_file(CONF, true); $options['traffic']['limit'] = 0; Helper::confBackup(); Helper::createIniFile(CONF, $options); - $_POST = Helper::getPaste(); + $_POST = Helper::getPaste(); $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; - $_SERVER['REQUEST_METHOD'] = 'POST'; - $_SERVER['REMOTE_ADDR'] = '::1'; + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_SERVER['REMOTE_ADDR'] = '::1'; ob_start(); new PrivateBin; $content = ob_get_contents(); @@ -81,7 +81,7 @@ class JsonApiTest extends PHPUnit_Framework_TestCase public function testPut() { $this->reset(); - $options = parse_ini_file(CONF, true); + $options = parse_ini_file(CONF, true); $options['traffic']['limit'] = 0; Helper::confBackup(); Helper::createIniFile(CONF, $options); @@ -90,10 +90,10 @@ class JsonApiTest extends PHPUnit_Framework_TestCase $file = tempnam(sys_get_temp_dir(), 'FOO'); file_put_contents($file, http_build_query($paste)); Request::setInputStream($file); - $_SERVER['QUERY_STRING'] = Helper::getPasteId(); + $_SERVER['QUERY_STRING'] = Helper::getPasteId(); $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; - $_SERVER['REQUEST_METHOD'] = 'PUT'; - $_SERVER['REMOTE_ADDR'] = '::1'; + $_SERVER['REQUEST_METHOD'] = 'PUT'; + $_SERVER['REMOTE_ADDR'] = '::1'; ob_start(); new PrivateBin; $content = ob_get_contents(); @@ -120,14 +120,14 @@ class JsonApiTest extends PHPUnit_Framework_TestCase $this->_model->create(Helper::getPasteId(), Helper::getPaste()); $this->assertTrue($this->_model->exists(Helper::getPasteId()), 'paste exists before deleting data'); $paste = $this->_model->read(Helper::getPasteId()); - $file = tempnam(sys_get_temp_dir(), 'FOO'); + $file = tempnam(sys_get_temp_dir(), 'FOO'); file_put_contents($file, http_build_query(array( 'deletetoken' => hash_hmac('sha256', Helper::getPasteId(), $paste->meta->salt), ))); Request::setInputStream($file); - $_SERVER['QUERY_STRING'] = Helper::getPasteId(); + $_SERVER['QUERY_STRING'] = Helper::getPasteId(); $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; - $_SERVER['REQUEST_METHOD'] = 'DELETE'; + $_SERVER['REQUEST_METHOD'] = 'DELETE'; ob_start(); new PrivateBin; $content = ob_get_contents(); @@ -147,12 +147,12 @@ class JsonApiTest extends PHPUnit_Framework_TestCase $this->assertTrue($this->_model->exists(Helper::getPasteId()), 'paste exists before deleting data'); $paste = $this->_model->read(Helper::getPasteId()); $_POST = array( - 'action' => 'delete', + 'action' => 'delete', 'deletetoken' => hash_hmac('sha256', Helper::getPasteId(), $paste->meta->salt), ); - $_SERVER['QUERY_STRING'] = Helper::getPasteId(); + $_SERVER['QUERY_STRING'] = Helper::getPasteId(); $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; - $_SERVER['REQUEST_METHOD'] = 'POST'; + $_SERVER['REQUEST_METHOD'] = 'POST'; ob_start(); new PrivateBin; $content = ob_get_contents(); @@ -168,13 +168,13 @@ class JsonApiTest extends PHPUnit_Framework_TestCase public function testRead() { $this->reset(); - $paste = Helper::getPasteWithAttachment(); - $paste['meta']['attachment'] = $paste['attachment']; + $paste = Helper::getPasteWithAttachment(); + $paste['meta']['attachment'] = $paste['attachment']; $paste['meta']['attachmentname'] = $paste['attachmentname']; unset($paste['attachment']); unset($paste['attachmentname']); $this->_model->create(Helper::getPasteId(), $paste); - $_SERVER['QUERY_STRING'] = Helper::getPasteId(); + $_SERVER['QUERY_STRING'] = Helper::getPasteId(); $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; ob_start(); new PrivateBin; diff --git a/tst/ModelTest.php b/tst/ModelTest.php index 9ddfd172..8f7a40b0 100644 --- a/tst/ModelTest.php +++ b/tst/ModelTest.php @@ -1,5 +1,6 @@ _path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data'; - if (!is_dir($this->_path)) mkdir($this->_path); + if (!is_dir($this->_path)) { + mkdir($this->_path); + } ServerSalt::setPath($this->_path); - $options = parse_ini_file(CONF, true); + $options = parse_ini_file(CONF, true); $options['purge']['limit'] = 0; - $options['model'] = array( + $options['model'] = array( 'class' => 'Database', ); $options['model_options'] = array( @@ -37,8 +39,8 @@ class ModelTest extends PHPUnit_Framework_TestCase ); Helper::confBackup(); Helper::createIniFile(CONF, $options); - $this->_conf = new Configuration; - $this->_model = new Model($this->_conf); + $this->_conf = new Configuration; + $this->_model = new Model($this->_conf); $_SERVER['REMOTE_ADDR'] = '::1'; } @@ -73,8 +75,8 @@ class ModelTest extends PHPUnit_Framework_TestCase // storing comments $commentData = Helper::getComment(); - $paste = $this->_model->getPaste(Helper::getPasteId()); - $comment = $paste->getComment(Helper::getPasteId(), Helper::getCommentId()); + $paste = $this->_model->getPaste(Helper::getPasteId()); + $comment = $paste->getComment(Helper::getPasteId(), Helper::getCommentId()); $this->assertFalse($comment->exists(), 'comment does not yet exist'); $comment = $paste->getComment(Helper::getPasteId()); @@ -123,7 +125,7 @@ class ModelTest extends PHPUnit_Framework_TestCase */ public function testCommentDuplicate() { - $pasteData = Helper::getPaste(); + $pasteData = Helper::getPaste(); $commentData = Helper::getComment(); $this->_model->getPaste(Helper::getPasteId())->delete(); @@ -146,7 +148,7 @@ class ModelTest extends PHPUnit_Framework_TestCase public function testImplicitDefaults() { - $pasteData = Helper::getPaste(); + $pasteData = Helper::getPaste(); $commentData = Helper::getComment(); $this->_model->getPaste(Helper::getPasteId())->delete(); @@ -175,8 +177,8 @@ class ModelTest extends PHPUnit_Framework_TestCase $comment->store(); $identicon = new Identicon(); - $pngdata = $identicon->getImageDataUri(TrafficLimiter::getHash(), 16); - $comment = $paste->getComment(Helper::getPasteId(), Helper::getCommentId())->get(); + $pngdata = $identicon->getImageDataUri(TrafficLimiter::getHash(), 16); + $comment = $paste->getComment(Helper::getPasteId(), Helper::getCommentId())->get(); $this->assertEquals($pngdata, $comment->meta->vizhash, 'nickname triggers vizhash to be set'); } @@ -230,13 +232,13 @@ class ModelTest extends PHPUnit_Framework_TestCase public function testPurge() { - $conf = new Configuration; + $conf = new Configuration; $store = Database::getInstance($conf->getSection('model_options')); $store->delete(Helper::getPasteId()); $expired = Helper::getPaste(array('expire_date' => 1344803344)); - $paste = Helper::getPaste(array('expire_date' => time() + 3600)); - $keys = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'x', 'y', 'z'); - $ids = array(); + $paste = Helper::getPaste(array('expire_date' => time() + 3600)); + $keys = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'x', 'y', 'z'); + $ids = array(); foreach ($keys as $key) { $ids[$key] = substr(md5($key), 0, 16); $store->delete($ids[$key]); @@ -261,9 +263,9 @@ class ModelTest extends PHPUnit_Framework_TestCase public function testCommentWithDisabledVizhash() { - $options = parse_ini_file(CONF, true); + $options = parse_ini_file(CONF, true); $options['main']['icon'] = 'none'; - $options['model'] = array( + $options['model'] = array( 'class' => 'Database', ); $options['model_options'] = array( @@ -297,8 +299,8 @@ class ModelTest extends PHPUnit_Framework_TestCase // storing comments $commentData = Helper::getComment(); - $paste = $model->getPaste(Helper::getPasteId()); - $comment = $paste->getComment(Helper::getPasteId(), Helper::getCommentId()); + $paste = $model->getPaste(Helper::getPasteId()); + $comment = $paste->getComment(Helper::getPasteId(), Helper::getCommentId()); $this->assertFalse($comment->exists(), 'comment does not yet exist'); $comment = $paste->getComment(Helper::getPasteId()); @@ -316,9 +318,9 @@ class ModelTest extends PHPUnit_Framework_TestCase public function testCommentIdenticon() { - $options = parse_ini_file(CONF, true); + $options = parse_ini_file(CONF, true); $options['main']['icon'] = 'identicon'; - $options['model'] = array( + $options['model'] = array( 'class' => 'Database', ); $options['model_options'] = array( @@ -331,7 +333,7 @@ class ModelTest extends PHPUnit_Framework_TestCase Helper::createIniFile(CONF, $options); $model = new Model(new Configuration); - $pasteData = Helper::getPaste(); + $pasteData = Helper::getPaste(); $commentData = Helper::getComment(); $model->getPaste(Helper::getPasteId())->delete(); @@ -347,16 +349,16 @@ class ModelTest extends PHPUnit_Framework_TestCase $comment->store(); $identicon = new Identicon(); - $pngdata = $identicon->getImageDataUri(TrafficLimiter::getHash(), 16); - $comment = $paste->getComment(Helper::getPasteId(), Helper::getCommentId())->get(); + $pngdata = $identicon->getImageDataUri(TrafficLimiter::getHash(), 16); + $comment = $paste->getComment(Helper::getPasteId(), Helper::getCommentId())->get(); $this->assertEquals($pngdata, $comment->meta->vizhash, 'nickname triggers vizhash to be set'); } public function testCommentVizhash() { - $options = parse_ini_file(CONF, true); + $options = parse_ini_file(CONF, true); $options['main']['icon'] = 'vizhash'; - $options['model'] = array( + $options['model'] = array( 'class' => 'Database', ); $options['model_options'] = array( @@ -369,7 +371,7 @@ class ModelTest extends PHPUnit_Framework_TestCase Helper::createIniFile(CONF, $options); $model = new Model(new Configuration); - $pasteData = Helper::getPaste(); + $pasteData = Helper::getPaste(); $commentData = Helper::getComment(); $model->getPaste(Helper::getPasteId())->delete(); @@ -384,7 +386,7 @@ class ModelTest extends PHPUnit_Framework_TestCase $comment->setNickname($commentData['meta']['nickname']); $comment->store(); - $vz = new Vizhash16x16(); + $vz = new Vizhash16x16(); $pngdata = 'data:image/png;base64,' . base64_encode($vz->generate(TrafficLimiter::getHash())); $comment = $paste->getComment(Helper::getPasteId(), Helper::getCommentId())->get(); $this->assertEquals($pngdata, $comment->meta->vizhash, 'nickname triggers vizhash to be set'); diff --git a/tst/PrivateBinTest.php b/tst/PrivateBinTest.php index 4546de26..355b3f9d 100644 --- a/tst/PrivateBinTest.php +++ b/tst/PrivateBinTest.php @@ -1,9 +1,9 @@ _path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data'; + $this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data'; $this->_model = Filesystem::getInstance(array('dir' => $this->_path)); ServerSalt::setPath($this->_path); $this->reset(); @@ -29,16 +29,16 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase public function reset() { - $_POST = array(); - $_GET = array(); + $_POST = array(); + $_GET = array(); $_SERVER = array(); if ($this->_model->exists(Helper::getPasteId())) { $this->_model->delete(Helper::getPasteId()); } Helper::confRestore(); - $options = parse_ini_file(CONF, true); - $options['purge']['dir'] = $this->_path; - $options['traffic']['dir'] = $this->_path; + $options = parse_ini_file(CONF, true); + $options['purge']['dir'] = $this->_path; + $options['traffic']['dir'] = $this->_path; $options['model_options']['dir'] = $this->_path; Helper::confBackup(); Helper::createIniFile(CONF, $options); @@ -72,7 +72,7 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase public function testViewLanguageSelection() { $this->reset(); - $options = parse_ini_file(CONF, true); + $options = parse_ini_file(CONF, true); $options['main']['languageselection'] = true; Helper::confBackup(); Helper::createIniFile(CONF, $options); @@ -94,9 +94,9 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase public function testViewForceLanguageDefault() { $this->reset(); - $options = parse_ini_file(CONF, true); + $options = parse_ini_file(CONF, true); $options['main']['languageselection'] = false; - $options['main']['languagedefault'] = 'fr'; + $options['main']['languagedefault'] = 'fr'; Helper::confBackup(); Helper::createIniFile(CONF, $options); $_COOKIE['lang'] = 'de'; @@ -118,7 +118,7 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase { $shortener = 'https://shortener.example.com/api?link='; $this->reset(); - $options = parse_ini_file(CONF, true); + $options = parse_ini_file(CONF, true); $options['main']['urlshortener'] = $shortener; Helper::confBackup(); Helper::createIniFile(CONF, $options); @@ -175,14 +175,14 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase public function testCreate() { $this->reset(); - $options = parse_ini_file(CONF, true); + $options = parse_ini_file(CONF, true); $options['traffic']['limit'] = 0; Helper::confBackup(); Helper::createIniFile(CONF, $options); - $_POST = Helper::getPaste(); + $_POST = Helper::getPaste(); $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; - $_SERVER['REQUEST_METHOD'] = 'POST'; - $_SERVER['REMOTE_ADDR'] = '::1'; + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_SERVER['REMOTE_ADDR'] = '::1'; ob_start(); new PrivateBin; $content = ob_get_contents(); @@ -204,14 +204,14 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase public function testCreateInvalidTimelimit() { $this->reset(); - $options = parse_ini_file(CONF, true); + $options = parse_ini_file(CONF, true); $options['traffic']['limit'] = 0; Helper::confBackup(); Helper::createIniFile(CONF, $options); - $_POST = Helper::getPaste(array('expire' => 25)); + $_POST = Helper::getPaste(array('expire' => 25)); $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; - $_SERVER['REQUEST_METHOD'] = 'POST'; - $_SERVER['REMOTE_ADDR'] = '::1'; + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_SERVER['REMOTE_ADDR'] = '::1'; TrafficLimiter::canPass(); ob_start(); new PrivateBin; @@ -234,15 +234,15 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase public function testCreateInvalidSize() { $this->reset(); - $options = parse_ini_file(CONF, true); + $options = parse_ini_file(CONF, true); $options['main']['sizelimit'] = 10; - $options['traffic']['limit'] = 0; + $options['traffic']['limit'] = 0; Helper::confBackup(); Helper::createIniFile(CONF, $options); - $_POST = Helper::getPaste(); + $_POST = Helper::getPaste(); $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; - $_SERVER['REQUEST_METHOD'] = 'POST'; - $_SERVER['REMOTE_ADDR'] = '::1'; + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_SERVER['REMOTE_ADDR'] = '::1'; ob_start(); new PrivateBin; $content = ob_get_contents(); @@ -258,15 +258,15 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase public function testCreateProxyHeader() { $this->reset(); - $options = parse_ini_file(CONF, true); + $options = parse_ini_file(CONF, true); $options['traffic']['header'] = 'X_FORWARDED_FOR'; Helper::confBackup(); Helper::createIniFile(CONF, $options); - $_POST = Helper::getPaste(); - $_SERVER['HTTP_X_FORWARDED_FOR'] = '::2'; + $_POST = Helper::getPaste(); + $_SERVER['HTTP_X_FORWARDED_FOR'] = '::2'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; - $_SERVER['REQUEST_METHOD'] = 'POST'; - $_SERVER['REMOTE_ADDR'] = '::1'; + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_SERVER['REMOTE_ADDR'] = '::1'; ob_start(); new PrivateBin; $content = ob_get_contents(); @@ -288,15 +288,15 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase public function testCreateDuplicateId() { $this->reset(); - $options = parse_ini_file(CONF, true); + $options = parse_ini_file(CONF, true); $options['traffic']['limit'] = 0; Helper::confBackup(); Helper::createIniFile(CONF, $options); $this->_model->create(Helper::getPasteId(), Helper::getPaste()); - $_POST = Helper::getPaste(); + $_POST = Helper::getPaste(); $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; - $_SERVER['REQUEST_METHOD'] = 'POST'; - $_SERVER['REMOTE_ADDR'] = '::1'; + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_SERVER['REMOTE_ADDR'] = '::1'; ob_start(); new PrivateBin; $content = ob_get_contents(); @@ -312,17 +312,17 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase public function testCreateValidExpire() { $this->reset(); - $options = parse_ini_file(CONF, true); + $options = parse_ini_file(CONF, true); $options['traffic']['limit'] = 0; Helper::confBackup(); Helper::createIniFile(CONF, $options); - $_POST = Helper::getPaste(); - $_POST['expire'] = '5min'; - $_POST['formatter'] = 'foo'; + $_POST = Helper::getPaste(); + $_POST['expire'] = '5min'; + $_POST['formatter'] = 'foo'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; - $_SERVER['REQUEST_METHOD'] = 'POST'; - $_SERVER['REMOTE_ADDR'] = '::1'; - $time = time(); + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_SERVER['REMOTE_ADDR'] = '::1'; + $time = time(); ob_start(); new PrivateBin; $content = ob_get_contents(); @@ -345,17 +345,17 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase public function testCreateValidExpireWithDiscussion() { $this->reset(); - $options = parse_ini_file(CONF, true); + $options = parse_ini_file(CONF, true); $options['traffic']['limit'] = 0; Helper::confBackup(); Helper::createIniFile(CONF, $options); - $_POST = Helper::getPaste(); - $_POST['expire'] = '5min'; - $_POST['opendiscussion'] = '1'; + $_POST = Helper::getPaste(); + $_POST['expire'] = '5min'; + $_POST['opendiscussion'] = '1'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; - $_SERVER['REQUEST_METHOD'] = 'POST'; - $_SERVER['REMOTE_ADDR'] = '::1'; - $time = time(); + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_SERVER['REMOTE_ADDR'] = '::1'; + $time = time(); ob_start(); new PrivateBin; $content = ob_get_contents(); @@ -379,15 +379,15 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase public function testCreateInvalidExpire() { $this->reset(); - $options = parse_ini_file(CONF, true); + $options = parse_ini_file(CONF, true); $options['traffic']['limit'] = 0; Helper::confBackup(); Helper::createIniFile(CONF, $options); - $_POST = Helper::getPaste(); - $_POST['expire'] = 'foo'; + $_POST = Helper::getPaste(); + $_POST['expire'] = 'foo'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; - $_SERVER['REQUEST_METHOD'] = 'POST'; - $_SERVER['REMOTE_ADDR'] = '::1'; + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_SERVER['REMOTE_ADDR'] = '::1'; ob_start(); new PrivateBin; $content = ob_get_contents(); @@ -409,15 +409,15 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase public function testCreateInvalidBurn() { $this->reset(); - $options = parse_ini_file(CONF, true); + $options = parse_ini_file(CONF, true); $options['traffic']['limit'] = 0; Helper::confBackup(); Helper::createIniFile(CONF, $options); - $_POST = Helper::getPaste(); - $_POST['burnafterreading'] = 'neither 1 nor 0'; + $_POST = Helper::getPaste(); + $_POST['burnafterreading'] = 'neither 1 nor 0'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; - $_SERVER['REQUEST_METHOD'] = 'POST'; - $_SERVER['REMOTE_ADDR'] = '::1'; + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_SERVER['REMOTE_ADDR'] = '::1'; ob_start(); new PrivateBin; $content = ob_get_contents(); @@ -433,15 +433,15 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase public function testCreateInvalidOpenDiscussion() { $this->reset(); - $options = parse_ini_file(CONF, true); + $options = parse_ini_file(CONF, true); $options['traffic']['limit'] = 0; Helper::confBackup(); Helper::createIniFile(CONF, $options); - $_POST = Helper::getPaste(); - $_POST['opendiscussion'] = 'neither 1 nor 0'; + $_POST = Helper::getPaste(); + $_POST['opendiscussion'] = 'neither 1 nor 0'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; - $_SERVER['REQUEST_METHOD'] = 'POST'; - $_SERVER['REMOTE_ADDR'] = '::1'; + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_SERVER['REMOTE_ADDR'] = '::1'; ob_start(); new PrivateBin; $content = ob_get_contents(); @@ -457,15 +457,15 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase public function testCreateAttachment() { $this->reset(); - $options = parse_ini_file(CONF, true); - $options['traffic']['limit'] = 0; + $options = parse_ini_file(CONF, true); + $options['traffic']['limit'] = 0; $options['main']['fileupload'] = true; Helper::confBackup(); Helper::createIniFile(CONF, $options); - $_POST = Helper::getPasteWithAttachment(); + $_POST = Helper::getPasteWithAttachment(); $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; - $_SERVER['REQUEST_METHOD'] = 'POST'; - $_SERVER['REMOTE_ADDR'] = '::1'; + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_SERVER['REMOTE_ADDR'] = '::1'; $this->assertFalse($this->_model->exists(Helper::getPasteId()), 'paste does not exists before posting data'); ob_start(); new PrivateBin; @@ -475,7 +475,7 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase $this->assertEquals(0, $response['status'], 'outputs status'); $this->assertTrue($this->_model->exists($response['id']), 'paste exists after posting data'); $original = json_decode(json_encode($_POST)); - $stored = $this->_model->read($response['id']); + $stored = $this->_model->read($response['id']); foreach (array('data', 'attachment', 'attachmentname') as $key) { $this->assertEquals($original->$key, $stored->$key); } @@ -495,16 +495,16 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase public function testCreateBrokenAttachmentUpload() { $this->reset(); - $options = parse_ini_file(CONF, true); - $options['traffic']['limit'] = 0; + $options = parse_ini_file(CONF, true); + $options['traffic']['limit'] = 0; $options['main']['fileupload'] = true; Helper::confBackup(); Helper::createIniFile(CONF, $options); $_POST = Helper::getPasteWithAttachment(); unset($_POST['attachment']); $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; - $_SERVER['REQUEST_METHOD'] = 'POST'; - $_SERVER['REMOTE_ADDR'] = '::1'; + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_SERVER['REMOTE_ADDR'] = '::1'; $this->assertFalse($this->_model->exists(Helper::getPasteId()), 'paste does not exists before posting data'); ob_start(); new PrivateBin; @@ -521,10 +521,10 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase public function testCreateTooSoon() { $this->reset(); - $_POST = Helper::getPaste(); + $_POST = Helper::getPaste(); $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; - $_SERVER['REQUEST_METHOD'] = 'POST'; - $_SERVER['REMOTE_ADDR'] = '::1'; + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_SERVER['REMOTE_ADDR'] = '::1'; ob_start(); new PrivateBin; ob_end_clean(); @@ -544,15 +544,15 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase public function testCreateValidNick() { $this->reset(); - $options = parse_ini_file(CONF, true); + $options = parse_ini_file(CONF, true); $options['traffic']['limit'] = 0; Helper::confBackup(); Helper::createIniFile(CONF, $options); - $_POST = Helper::getPaste(); - $_POST['nickname'] = Helper::getComment()['meta']['nickname']; + $_POST = Helper::getPaste(); + $_POST['nickname'] = Helper::getComment()['meta']['nickname']; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; - $_SERVER['REQUEST_METHOD'] = 'POST'; - $_SERVER['REMOTE_ADDR'] = '::1'; + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_SERVER['REMOTE_ADDR'] = '::1'; ob_start(); new PrivateBin; $content = ob_get_contents(); @@ -574,17 +574,17 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase public function testCreateInvalidNick() { $this->reset(); - $options = parse_ini_file(CONF, true); + $options = parse_ini_file(CONF, true); $options['traffic']['limit'] = 0; Helper::confBackup(); Helper::createIniFile(CONF, $options); - $_POST = Helper::getCommentPost(); - $_POST['pasteid'] = Helper::getPasteId(); - $_POST['parentid'] = Helper::getPasteId(); - $_POST['nickname'] = 'foo'; + $_POST = Helper::getCommentPost(); + $_POST['pasteid'] = Helper::getPasteId(); + $_POST['parentid'] = Helper::getPasteId(); + $_POST['nickname'] = 'foo'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; - $_SERVER['REQUEST_METHOD'] = 'POST'; - $_SERVER['REMOTE_ADDR'] = '::1'; + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_SERVER['REMOTE_ADDR'] = '::1'; $this->_model->create(Helper::getPasteId(), Helper::getPaste()); ob_start(); new PrivateBin; @@ -601,16 +601,16 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase public function testCreateComment() { $this->reset(); - $options = parse_ini_file(CONF, true); + $options = parse_ini_file(CONF, true); $options['traffic']['limit'] = 0; Helper::confBackup(); Helper::createIniFile(CONF, $options); - $_POST = Helper::getCommentPost(); - $_POST['pasteid'] = Helper::getPasteId(); - $_POST['parentid'] = Helper::getPasteId(); + $_POST = Helper::getCommentPost(); + $_POST['pasteid'] = Helper::getPasteId(); + $_POST['parentid'] = Helper::getPasteId(); $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; - $_SERVER['REQUEST_METHOD'] = 'POST'; - $_SERVER['REMOTE_ADDR'] = '::1'; + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_SERVER['REMOTE_ADDR'] = '::1'; $this->_model->create(Helper::getPasteId(), Helper::getPaste()); ob_start(); new PrivateBin; @@ -627,16 +627,16 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase public function testCreateInvalidComment() { $this->reset(); - $options = parse_ini_file(CONF, true); + $options = parse_ini_file(CONF, true); $options['traffic']['limit'] = 0; Helper::confBackup(); Helper::createIniFile(CONF, $options); - $_POST = Helper::getCommentPost(); - $_POST['pasteid'] = Helper::getPasteId(); - $_POST['parentid'] = 'foo'; + $_POST = Helper::getCommentPost(); + $_POST['pasteid'] = Helper::getPasteId(); + $_POST['parentid'] = 'foo'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; - $_SERVER['REQUEST_METHOD'] = 'POST'; - $_SERVER['REMOTE_ADDR'] = '::1'; + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_SERVER['REMOTE_ADDR'] = '::1'; $this->_model->create(Helper::getPasteId(), Helper::getPaste()); ob_start(); new PrivateBin; @@ -653,17 +653,17 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase public function testCreateCommentDiscussionDisabled() { $this->reset(); - $options = parse_ini_file(CONF, true); + $options = parse_ini_file(CONF, true); $options['traffic']['limit'] = 0; Helper::confBackup(); Helper::createIniFile(CONF, $options); - $_POST = Helper::getCommentPost(); - $_POST['pasteid'] = Helper::getPasteId(); - $_POST['parentid'] = Helper::getPasteId(); + $_POST = Helper::getCommentPost(); + $_POST['pasteid'] = Helper::getPasteId(); + $_POST['parentid'] = Helper::getPasteId(); $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; - $_SERVER['REQUEST_METHOD'] = 'POST'; - $_SERVER['REMOTE_ADDR'] = '::1'; - $paste = Helper::getPaste(array('opendiscussion' => false)); + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_SERVER['REMOTE_ADDR'] = '::1'; + $paste = Helper::getPaste(array('opendiscussion' => false)); $this->_model->create(Helper::getPasteId(), $paste); ob_start(); new PrivateBin; @@ -680,16 +680,16 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase public function testCreateCommentInvalidPaste() { $this->reset(); - $options = parse_ini_file(CONF, true); + $options = parse_ini_file(CONF, true); $options['traffic']['limit'] = 0; Helper::confBackup(); Helper::createIniFile(CONF, $options); - $_POST = Helper::getCommentPost(); - $_POST['pasteid'] = Helper::getPasteId(); - $_POST['parentid'] = Helper::getPasteId(); + $_POST = Helper::getCommentPost(); + $_POST['pasteid'] = Helper::getPasteId(); + $_POST['parentid'] = Helper::getPasteId(); $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; - $_SERVER['REQUEST_METHOD'] = 'POST'; - $_SERVER['REMOTE_ADDR'] = '::1'; + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_SERVER['REMOTE_ADDR'] = '::1'; ob_start(); new PrivateBin; $content = ob_get_contents(); @@ -705,19 +705,19 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase public function testCreateDuplicateComment() { $this->reset(); - $options = parse_ini_file(CONF, true); + $options = parse_ini_file(CONF, true); $options['traffic']['limit'] = 0; Helper::confBackup(); Helper::createIniFile(CONF, $options); $this->_model->create(Helper::getPasteId(), Helper::getPaste()); $this->_model->createComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId(), Helper::getComment()); $this->assertTrue($this->_model->existsComment(Helper::getPasteId(), Helper::getPasteId(), Helper::getCommentId()), 'comment exists before posting data'); - $_POST = Helper::getCommentPost(); - $_POST['pasteid'] = Helper::getPasteId(); - $_POST['parentid'] = Helper::getPasteId(); + $_POST = Helper::getCommentPost(); + $_POST['pasteid'] = Helper::getPasteId(); + $_POST['parentid'] = Helper::getPasteId(); $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; - $_SERVER['REQUEST_METHOD'] = 'POST'; - $_SERVER['REMOTE_ADDR'] = '::1'; + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_SERVER['REMOTE_ADDR'] = '::1'; ob_start(); new PrivateBin; $content = ob_get_contents(); @@ -835,7 +835,7 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase $this->reset(); $paste = Helper::getPaste(); $this->_model->create(Helper::getPasteId(), $paste); - $_SERVER['QUERY_STRING'] = Helper::getPasteId(); + $_SERVER['QUERY_STRING'] = Helper::getPasteId(); $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; ob_start(); new PrivateBin; @@ -859,7 +859,7 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase public function testReadInvalidJson() { $this->reset(); - $_SERVER['QUERY_STRING'] = Helper::getPasteId(); + $_SERVER['QUERY_STRING'] = Helper::getPasteId(); $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; ob_start(); new PrivateBin; @@ -876,9 +876,9 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase { $this->reset(); $oldPaste = Helper::getPaste(); - $meta = array( + $meta = array( 'syntaxcoloring' => true, - 'postdate' => $oldPaste['meta']['postdate'], + 'postdate' => $oldPaste['meta']['postdate'], 'opendiscussion' => $oldPaste['meta']['opendiscussion'], ); $oldPaste['meta'] = $meta; @@ -931,8 +931,8 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase $this->reset(); $this->_model->create(Helper::getPasteId(), Helper::getPaste()); $this->assertTrue($this->_model->exists(Helper::getPasteId()), 'paste exists before deleting data'); - $paste = $this->_model->read(Helper::getPasteId()); - $_GET['pasteid'] = Helper::getPasteId(); + $paste = $this->_model->read(Helper::getPasteId()); + $_GET['pasteid'] = Helper::getPasteId(); $_GET['deletetoken'] = hash_hmac('sha256', Helper::getPasteId(), $paste->meta->salt); ob_start(); new PrivateBin; @@ -953,7 +953,7 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase { $this->reset(); $this->_model->create(Helper::getPasteId(), Helper::getPaste()); - $_GET['pasteid'] = 'foo'; + $_GET['pasteid'] = 'foo'; $_GET['deletetoken'] = 'bar'; ob_start(); new PrivateBin; @@ -973,7 +973,7 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase public function testDeleteInexistantId() { $this->reset(); - $_GET['pasteid'] = Helper::getPasteId(); + $_GET['pasteid'] = Helper::getPasteId(); $_GET['deletetoken'] = 'bar'; ob_start(); new PrivateBin; @@ -993,7 +993,7 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase { $this->reset(); $this->_model->create(Helper::getPasteId(), Helper::getPaste()); - $_GET['pasteid'] = Helper::getPasteId(); + $_GET['pasteid'] = Helper::getPasteId(); $_GET['deletetoken'] = 'bar'; ob_start(); new PrivateBin; @@ -1016,10 +1016,10 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase $burnPaste = Helper::getPaste(array('burnafterreading' => true)); $this->_model->create(Helper::getPasteId(), $burnPaste); $this->assertTrue($this->_model->exists(Helper::getPasteId()), 'paste exists before deleting data'); - $_POST['deletetoken'] = 'burnafterreading'; - $_SERVER['QUERY_STRING'] = Helper::getPasteId(); + $_POST['deletetoken'] = 'burnafterreading'; + $_SERVER['QUERY_STRING'] = Helper::getPasteId(); $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; - $_SERVER['REQUEST_METHOD'] = 'POST'; + $_SERVER['REQUEST_METHOD'] = 'POST'; ob_start(); new PrivateBin; $content = ob_get_contents(); @@ -1037,10 +1037,10 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase $this->reset(); $this->_model->create(Helper::getPasteId(), Helper::getPaste()); $this->assertTrue($this->_model->exists(Helper::getPasteId()), 'paste exists before deleting data'); - $_POST['deletetoken'] = 'burnafterreading'; - $_SERVER['QUERY_STRING'] = Helper::getPasteId(); + $_POST['deletetoken'] = 'burnafterreading'; + $_SERVER['QUERY_STRING'] = Helper::getPasteId(); $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; - $_SERVER['REQUEST_METHOD'] = 'POST'; + $_SERVER['REQUEST_METHOD'] = 'POST'; ob_start(); new PrivateBin; $content = ob_get_contents(); @@ -1060,7 +1060,7 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase $this->assertFalse($this->_model->exists(Helper::getPasteId()), 'paste does not exist before being created'); $this->_model->create(Helper::getPasteId(), $expiredPaste); $this->assertTrue($this->_model->exists(Helper::getPasteId()), 'paste exists before deleting data'); - $_GET['pasteid'] = Helper::getPasteId(); + $_GET['pasteid'] = Helper::getPasteId(); $_GET['deletetoken'] = 'does not matter in this context, but has to be set'; ob_start(); new PrivateBin; @@ -1084,7 +1084,7 @@ class PrivateBinTest extends PHPUnit_Framework_TestCase unset($paste['meta']['salt']); $this->_model->create(Helper::getPasteId(), $paste); $this->assertTrue($this->_model->exists(Helper::getPasteId()), 'paste exists before deleting data'); - $_GET['pasteid'] = Helper::getPasteId(); + $_GET['pasteid'] = Helper::getPasteId(); $_GET['deletetoken'] = hash_hmac('sha256', Helper::getPasteId(), ServerSalt::get()); ob_start(); new PrivateBin; diff --git a/tst/PrivateBinWithDbTest.php b/tst/PrivateBinWithDbTest.php index 73c257ba..2ed38461 100644 --- a/tst/PrivateBinWithDbTest.php +++ b/tst/PrivateBinWithDbTest.php @@ -1,9 +1,7 @@ null, 'pwd' => null, 'opt' => array( - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, - PDO::ATTR_PERSISTENT => true + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_PERSISTENT => true, ), ); @@ -27,7 +25,7 @@ class PrivateBinWithDbTest extends PrivateBinTest } ServerSalt::setPath($this->_path); $this->_options['dsn'] = 'sqlite:' . $this->_path . DIRECTORY_SEPARATOR . 'tst.sq3'; - $this->_model = Database::getInstance($this->_options); + $this->_model = Database::getInstance($this->_options); $this->reset(); } @@ -35,13 +33,13 @@ class PrivateBinWithDbTest extends PrivateBinTest { parent::reset(); // but then inject a db config - $options = parse_ini_file(CONF, true); + $options = parse_ini_file(CONF, true); $options['model'] = array( 'class' => 'Database', ); - $options['purge']['dir'] = $this->_path; + $options['purge']['dir'] = $this->_path; $options['traffic']['dir'] = $this->_path; - $options['model_options'] = $this->_options; + $options['model_options'] = $this->_options; Helper::confBackup(); Helper::createIniFile(CONF, $options); } diff --git a/tst/RequestTest.php b/tst/RequestTest.php index a6067056..f20209f5 100644 --- a/tst/RequestTest.php +++ b/tst/RequestTest.php @@ -17,15 +17,15 @@ class RequestTest extends PHPUnit_Framework_TestCase public function reset() { $_SERVER = array(); - $_GET = array(); - $_POST = array(); + $_GET = array(); + $_POST = array(); } public function testView() { $this->reset(); $_SERVER['REQUEST_METHOD'] = 'GET'; - $request = new Request; + $request = new Request; $this->assertFalse($request->isJsonApiCall(), 'is HTML call'); $this->assertEquals('view', $request->getOperation()); } @@ -34,8 +34,8 @@ class RequestTest extends PHPUnit_Framework_TestCase { $this->reset(); $_SERVER['REQUEST_METHOD'] = 'GET'; - $_SERVER['QUERY_STRING'] = 'foo'; - $request = new Request; + $_SERVER['QUERY_STRING'] = 'foo'; + $request = new Request; $this->assertFalse($request->isJsonApiCall(), 'is HTML call'); $this->assertEquals('foo', $request->getParam('pasteid')); $this->assertEquals('read', $request->getOperation()); @@ -45,9 +45,9 @@ class RequestTest extends PHPUnit_Framework_TestCase { $this->reset(); $_SERVER['REQUEST_METHOD'] = 'GET'; - $_GET['pasteid'] = 'foo'; - $_GET['deletetoken'] = 'bar'; - $request = new Request; + $_GET['pasteid'] = 'foo'; + $_GET['deletetoken'] = 'bar'; + $request = new Request; $this->assertFalse($request->isJsonApiCall(), 'is HTML call'); $this->assertEquals('delete', $request->getOperation()); $this->assertEquals('foo', $request->getParam('pasteid')); @@ -57,9 +57,9 @@ class RequestTest extends PHPUnit_Framework_TestCase public function testApiCreate() { $this->reset(); - $_SERVER['REQUEST_METHOD'] = 'PUT'; + $_SERVER['REQUEST_METHOD'] = 'PUT'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; - $file = tempnam(sys_get_temp_dir(), 'FOO'); + $file = tempnam(sys_get_temp_dir(), 'FOO'); file_put_contents($file, 'data=foo'); Request::setInputStream($file); $request = new Request; @@ -72,9 +72,9 @@ class RequestTest extends PHPUnit_Framework_TestCase { $this->reset(); $_SERVER['REQUEST_METHOD'] = 'POST'; - $_SERVER['HTTP_ACCEPT'] = 'application/json, text/javascript, */*; q=0.01'; - $_POST['attachment'] = 'foo'; - $request = new Request; + $_SERVER['HTTP_ACCEPT'] = 'application/json, text/javascript, */*; q=0.01'; + $_POST['attachment'] = 'foo'; + $request = new Request; $this->assertTrue($request->isJsonApiCall(), 'is JSON Api call'); $this->assertEquals('create', $request->getOperation()); $this->assertEquals('foo', $request->getParam('attachment')); @@ -84,9 +84,9 @@ class RequestTest extends PHPUnit_Framework_TestCase { $this->reset(); $_SERVER['REQUEST_METHOD'] = 'GET'; - $_SERVER['HTTP_ACCEPT'] = 'application/json, text/javascript, */*; q=0.01'; - $_SERVER['QUERY_STRING'] = 'foo'; - $request = new Request; + $_SERVER['HTTP_ACCEPT'] = 'application/json, text/javascript, */*; q=0.01'; + $_SERVER['QUERY_STRING'] = 'foo'; + $request = new Request; $this->assertTrue($request->isJsonApiCall(), 'is JSON Api call'); $this->assertEquals('foo', $request->getParam('pasteid')); $this->assertEquals('read', $request->getOperation()); @@ -95,11 +95,11 @@ class RequestTest extends PHPUnit_Framework_TestCase public function testApiDelete() { $this->reset(); - $_SERVER['REQUEST_METHOD'] = 'POST'; + $_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; - $_SERVER['QUERY_STRING'] = 'foo'; - $_POST['deletetoken'] = 'bar'; - $request = new Request; + $_SERVER['QUERY_STRING'] = 'foo'; + $_POST['deletetoken'] = 'bar'; + $request = new Request; $this->assertTrue($request->isJsonApiCall(), 'is JSON Api call'); $this->assertEquals('delete', $request->getOperation()); $this->assertEquals('foo', $request->getParam('pasteid')); @@ -110,9 +110,9 @@ class RequestTest extends PHPUnit_Framework_TestCase { $this->reset(); $_SERVER['REQUEST_METHOD'] = 'GET'; - $_SERVER['HTTP_ACCEPT'] = 'text/html,text/html; charset=UTF-8,application/xhtml+xml, application/xml;q=0.9,*/*;q=0.8, text/csv,application/json'; - $_SERVER['QUERY_STRING'] = 'foo'; - $request = new Request; + $_SERVER['HTTP_ACCEPT'] = 'text/html,text/html; charset=UTF-8,application/xhtml+xml, application/xml;q=0.9,*/*;q=0.8, text/csv,application/json'; + $_SERVER['QUERY_STRING'] = 'foo'; + $request = new Request; $this->assertFalse($request->isJsonApiCall(), 'is HTML call'); $this->assertEquals('foo', $request->getParam('pasteid')); $this->assertEquals('read', $request->getOperation()); @@ -122,9 +122,9 @@ class RequestTest extends PHPUnit_Framework_TestCase { $this->reset(); $_SERVER['REQUEST_METHOD'] = 'GET'; - $_SERVER['HTTP_ACCEPT'] = 'application/xhtml+xml,text/html,text/html; charset=UTF-8, application/xml;q=0.9,*/*;q=0.8, text/csv,application/json'; - $_SERVER['QUERY_STRING'] = 'foo'; - $request = new Request; + $_SERVER['HTTP_ACCEPT'] = 'application/xhtml+xml,text/html,text/html; charset=UTF-8, application/xml;q=0.9,*/*;q=0.8, text/csv,application/json'; + $_SERVER['QUERY_STRING'] = 'foo'; + $request = new Request; $this->assertFalse($request->isJsonApiCall(), 'is HTML call'); $this->assertEquals('foo', $request->getParam('pasteid')); $this->assertEquals('read', $request->getOperation()); @@ -134,9 +134,9 @@ class RequestTest extends PHPUnit_Framework_TestCase { $this->reset(); $_SERVER['REQUEST_METHOD'] = 'GET'; - $_SERVER['HTTP_ACCEPT'] = 'text/plain,text/csv, application/xml;q=0.9, application/json, text/html,text/html; charset=UTF-8,application/xhtml+xml, */*;q=0.8'; - $_SERVER['QUERY_STRING'] = 'foo'; - $request = new Request; + $_SERVER['HTTP_ACCEPT'] = 'text/plain,text/csv, application/xml;q=0.9, application/json, text/html,text/html; charset=UTF-8,application/xhtml+xml, */*;q=0.8'; + $_SERVER['QUERY_STRING'] = 'foo'; + $request = new Request; $this->assertTrue($request->isJsonApiCall(), 'is JSON Api call'); $this->assertEquals('foo', $request->getParam('pasteid')); $this->assertEquals('read', $request->getOperation()); @@ -146,9 +146,9 @@ class RequestTest extends PHPUnit_Framework_TestCase { $this->reset(); $_SERVER['REQUEST_METHOD'] = 'GET'; - $_SERVER['HTTP_ACCEPT'] = 'text/plain,text/csv, application/xml;q=0.9, */*;q=0.8'; - $_SERVER['QUERY_STRING'] = 'foo'; - $request = new Request; + $_SERVER['HTTP_ACCEPT'] = 'text/plain,text/csv, application/xml;q=0.9, */*;q=0.8'; + $_SERVER['QUERY_STRING'] = 'foo'; + $request = new Request; $this->assertFalse($request->isJsonApiCall(), 'is HTML call'); $this->assertEquals('foo', $request->getParam('pasteid')); $this->assertEquals('read', $request->getOperation()); diff --git a/tst/ViewTest.php b/tst/ViewTest.php index 4b8f0cb6..965f7814 100644 --- a/tst/ViewTest.php +++ b/tst/ViewTest.php @@ -10,15 +10,15 @@ class ViewTest extends PHPUnit_Framework_TestCase private static $status = '!*#@?$+'; private static $formatters = array( - 'plaintext' => 'Plain Text', + 'plaintext' => 'Plain Text', 'syntaxhighlighting' => 'Source Code', - 'markdown' => 'Markdown', + 'markdown' => 'Markdown', ); private static $formatter_default = 'plaintext'; private static $expire = array( - '5min' => '5 minutes', + '5min' => '5 minutes', '1hour' => '1 hour', 'never' => 'Never', ); diff --git a/tst/Vizhash16x16Test.php b/tst/Vizhash16x16Test.php index 76d2f95a..afcda562 100644 --- a/tst/Vizhash16x16Test.php +++ b/tst/Vizhash16x16Test.php @@ -29,7 +29,7 @@ class Vizhash16x16Test extends PHPUnit_Framework_TestCase public function testVizhashGeneratesUniquePngsPerIp() { - $vz = new Vizhash16x16(); + $vz = new Vizhash16x16(); $pngdata = $vz->generate(hash('sha512', '127.0.0.1')); file_put_contents($this->_file, $pngdata); $finfo = new finfo(FILEINFO_MIME_TYPE); From b4293f54678ad692b591edb71a00f066325cd68e Mon Sep 17 00:00:00 2001 From: rugk Date: Mon, 31 Oct 2016 11:29:25 +0100 Subject: [PATCH 3/4] Add missing fixers from PHP CS Also adjust editorconfig and order php-cs. --- .editorconfig | 4 ++-- .php_cs | 6 +++--- .styleci.yml | 2 ++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.editorconfig b/.editorconfig index fd0c5b1d..2c9ddc3c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -38,6 +38,6 @@ indent_style = space indent_size = 2 trim_trailing_whitespace = false -[.travis.yml] +[*.yml] indent_style = space -indent_size = 4 +indent_size = 2 diff --git a/.php_cs b/.php_cs index 9dc9322e..560e2512 100644 --- a/.php_cs +++ b/.php_cs @@ -15,9 +15,9 @@ return Symfony\CS\Config\Config::create() ->fixers(['concat_with_spaces', 'long_array_syntax', 'standardize_not_equal', 'operators_spaces', 'duplicate_semicolon', 'remove_leading_slash_use', 'align_equals', - 'single_array_no_trailing_comma', 'phpdoc_indent', 'phpdoc_scalar', - 'phpdoc_to_comment', 'phpdoc_trim', + 'single_array_no_trailing_comma', 'phpdoc_indent', 'phpdoc_order', + 'phpdoc_scalar', 'phpdoc_to_comment', 'phpdoc_trim', 'phpdoc_types', 'print_to_echo', 'self_accessor', 'single_quote', - 'spaces_cast', 'ternary_spaces', 'phpdoc_order']) + 'spaces_cast', 'ternary_spaces']) ->finder($finder) ; diff --git a/.styleci.yml b/.styleci.yml index eac39fb8..002616bd 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -5,6 +5,8 @@ risky: false enabled: - no_empty_comment - align_equals + - long_array_syntax + - concat_with_spaces disabled: - blank_line_after_opening_tag From f628ac78f84b38ff3fe80c886459397d3ac191eb Mon Sep 17 00:00:00 2001 From: rugk Date: Mon, 31 Oct 2016 11:32:12 +0100 Subject: [PATCH 4/4] Fix style of operator spaces --- tst/ConfigurationTestGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tst/ConfigurationTestGenerator.php b/tst/ConfigurationTestGenerator.php index 1c39d7d5..a011bed3 100755 --- a/tst/ConfigurationTestGenerator.php +++ b/tst/ConfigurationTestGenerator.php @@ -469,7 +469,7 @@ EOT; private function _getFunction($step, $key, &$options, $preCode, $testCode) { if (count($testCode) == 0) { - echo "skipping creation of test$step$key, no valid tests found for configuration: $options". PHP_EOL; + echo "skipping creation of test$step$key, no valid tests found for configuration: $options" . PHP_EOL; return ''; }