From 55e5319f1931f3006a1ef4b5a73b3524e85737d9 Mon Sep 17 00:00:00 2001 From: Bartek Fabiszewski Date: Thu, 4 Jun 2020 21:08:17 +0200 Subject: [PATCH] Fix new config value in tests --- .tests/fixtures/fixture_non_admin.xml | 2 +- .tests/fixtures/ulogger_0_6.mysql | 52 +++++++++++++-------------- .tests/fixtures/ulogger_0_6.pgsql | 46 ++++++++++++------------ .tests/fixtures/ulogger_0_6.sqlite | 46 ++++++++++++------------ .tests/tests/MigrateTest.php | 2 +- helpers/config.php | 21 +++++++---- helpers/upload.php | 2 +- helpers/utils.php | 2 +- scripts/ulogger.mysql | 2 +- scripts/ulogger.pgsql | 2 +- scripts/ulogger.sqlite | 2 +- 11 files changed, 93 insertions(+), 86 deletions(-) diff --git a/.tests/fixtures/fixture_non_admin.xml b/.tests/fixtures/fixture_non_admin.xml index c4345cd..2befb82 100644 --- a/.tests/fixtures/fixture_non_admin.xml +++ b/.tests/fixtures/fixture_non_admin.xml @@ -22,6 +22,6 @@ - + diff --git a/.tests/fixtures/ulogger_0_6.mysql b/.tests/fixtures/ulogger_0_6.mysql index 1d55d89..53f47ce 100644 --- a/.tests/fixtures/ulogger_0_6.mysql +++ b/.tests/fixtures/ulogger_0_6.mysql @@ -40,9 +40,9 @@ DROP TABLE IF EXISTS `ol_layers`; -- CREATE TABLE `users` ( - `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, - `login` varchar(15) CHARACTER SET latin1 NOT NULL UNIQUE, - `password` varchar(255) CHARACTER SET latin1 NOT NULL DEFAULT '' + `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, + `login` varchar(15) CHARACTER SET latin1 NOT NULL UNIQUE, + `password` varchar(255) CHARACTER SET latin1 NOT NULL DEFAULT '' ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -------------------------------------------------------- @@ -52,12 +52,12 @@ CREATE TABLE `users` ( -- CREATE TABLE `tracks` ( - `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, - `user_id` int(11) NOT NULL, - `name` varchar(255) DEFAULT NULL, - `comment` varchar(1024) DEFAULT NULL, - INDEX `idx_user_id` (`user_id`), - FOREIGN KEY(`user_id`) REFERENCES `users`(`id`) + `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, + `user_id` int(11) NOT NULL, + `name` varchar(255) DEFAULT NULL, + `comment` varchar(1024) DEFAULT NULL, + INDEX `idx_user_id` (`user_id`), + FOREIGN KEY(`user_id`) REFERENCES `users`(`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -------------------------------------------------------- @@ -67,21 +67,21 @@ CREATE TABLE `tracks` ( -- CREATE TABLE `positions` ( - `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, - `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `user_id` int(11) NOT NULL, - `track_id` int(11) NOT NULL, - `latitude` double NOT NULL, - `longitude` double NOT NULL, - `altitude` double DEFAULT NULL, - `speed` double DEFAULT NULL, - `bearing` double DEFAULT NULL, - `accuracy` int(11) DEFAULT NULL, - `provider` varchar(100) DEFAULT NULL, - `comment` varchar(255) DEFAULT NULL, - `image_id` int(11) DEFAULT NULL, - INDEX `idx_ptrack_id` (`track_id`), - INDEX `index_puser_id` (`user_id`), - FOREIGN KEY(`user_id`) REFERENCES `users`(`id`), - FOREIGN KEY(`track_id`) REFERENCES `tracks`(`id`) + `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, + `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `user_id` int(11) NOT NULL, + `track_id` int(11) NOT NULL, + `latitude` double NOT NULL, + `longitude` double NOT NULL, + `altitude` double DEFAULT NULL, + `speed` double DEFAULT NULL, + `bearing` double DEFAULT NULL, + `accuracy` int(11) DEFAULT NULL, + `provider` varchar(100) DEFAULT NULL, + `comment` varchar(255) DEFAULT NULL, + `image_id` int(11) DEFAULT NULL, + INDEX `idx_ptrack_id` (`track_id`), + INDEX `index_puser_id` (`user_id`), + FOREIGN KEY(`user_id`) REFERENCES `users`(`id`), + FOREIGN KEY(`track_id`) REFERENCES `tracks`(`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/.tests/fixtures/ulogger_0_6.pgsql b/.tests/fixtures/ulogger_0_6.pgsql index 616ff62..91d4eb5 100644 --- a/.tests/fixtures/ulogger_0_6.pgsql +++ b/.tests/fixtures/ulogger_0_6.pgsql @@ -40,9 +40,9 @@ DROP TABLE IF EXISTS ol_layers; -- CREATE TABLE users ( - id serial PRIMARY KEY, - login varchar(15) NOT NULL UNIQUE, - password varchar(255) NOT NULL DEFAULT '' + id serial PRIMARY KEY, + login varchar(15) NOT NULL UNIQUE, + password varchar(255) NOT NULL DEFAULT '' ); -- -------------------------------------------------------- @@ -52,11 +52,11 @@ CREATE TABLE users ( -- CREATE TABLE tracks ( - id serial PRIMARY KEY, - user_id int NOT NULL, - name varchar(255) DEFAULT NULL, - comment varchar(1024) DEFAULT NULL, - FOREIGN KEY(user_id) REFERENCES users(id) + id serial PRIMARY KEY, + user_id int NOT NULL, + name varchar(255) DEFAULT NULL, + comment varchar(1024) DEFAULT NULL, + FOREIGN KEY(user_id) REFERENCES users(id) ); CREATE INDEX idx_user_id ON tracks(user_id); @@ -68,21 +68,21 @@ CREATE INDEX idx_user_id ON tracks(user_id); -- CREATE TABLE positions ( - id serial PRIMARY KEY, - time timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP, - user_id int NOT NULL, - track_id int NOT NULL, - latitude double precision NOT NULL, - longitude double precision NOT NULL, - altitude double precision DEFAULT NULL, - speed double precision DEFAULT NULL, - bearing double precision DEFAULT NULL, - accuracy int DEFAULT NULL, - provider varchar(100) DEFAULT NULL, - comment varchar(255) DEFAULT NULL, - image_id int DEFAULT NULL, - FOREIGN KEY(user_id) REFERENCES users(id), - FOREIGN KEY(track_id) REFERENCES tracks(id) + id serial PRIMARY KEY, + time timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP, + user_id int NOT NULL, + track_id int NOT NULL, + latitude double precision NOT NULL, + longitude double precision NOT NULL, + altitude double precision DEFAULT NULL, + speed double precision DEFAULT NULL, + bearing double precision DEFAULT NULL, + accuracy int DEFAULT NULL, + provider varchar(100) DEFAULT NULL, + comment varchar(255) DEFAULT NULL, + image_id int DEFAULT NULL, + FOREIGN KEY(user_id) REFERENCES users(id), + FOREIGN KEY(track_id) REFERENCES tracks(id) ); CREATE INDEX idx_ptrack_id ON positions(track_id); diff --git a/.tests/fixtures/ulogger_0_6.sqlite b/.tests/fixtures/ulogger_0_6.sqlite index 5bff253..221d118 100644 --- a/.tests/fixtures/ulogger_0_6.sqlite +++ b/.tests/fixtures/ulogger_0_6.sqlite @@ -40,9 +40,9 @@ DROP TABLE IF EXISTS `ol_layers`; -- CREATE TABLE `users` ( - `id` integer PRIMARY KEY AUTOINCREMENT, - `login` varchar(15) NOT NULL UNIQUE, - `password` varchar(255) NOT NULL DEFAULT '' + `id` integer PRIMARY KEY AUTOINCREMENT, + `login` varchar(15) NOT NULL UNIQUE, + `password` varchar(255) NOT NULL DEFAULT '' ); -- -------------------------------------------------------- @@ -52,11 +52,11 @@ CREATE TABLE `users` ( -- CREATE TABLE `tracks` ( - `id` integer PRIMARY KEY AUTOINCREMENT, - `user_id` integer NOT NULL, - `name` varchar(255) DEFAULT NULL, - `comment` varchar(1024) DEFAULT NULL, - FOREIGN KEY(`user_id`) REFERENCES `users`(`id`) + `id` integer PRIMARY KEY AUTOINCREMENT, + `user_id` integer NOT NULL, + `name` varchar(255) DEFAULT NULL, + `comment` varchar(1024) DEFAULT NULL, + FOREIGN KEY(`user_id`) REFERENCES `users`(`id`) ); CREATE INDEX `idx_user_id` ON `tracks`(`user_id`); @@ -67,21 +67,21 @@ CREATE INDEX `idx_user_id` ON `tracks`(`user_id`); -- CREATE TABLE `positions` ( - `id` integer PRIMARY KEY AUTOINCREMENT, - `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `user_id` integer NOT NULL, - `track_id` integer NOT NULL, - `latitude` double NOT NULL, - `longitude` double NOT NULL, - `altitude` double DEFAULT NULL, - `speed` double DEFAULT NULL, - `bearing` double DEFAULT NULL, - `accuracy` integer DEFAULT NULL, - `provider` varchar(100) DEFAULT NULL, - `comment` varchar(255) DEFAULT NULL, - `image_id` integer DEFAULT NULL, - FOREIGN KEY(`user_id`) REFERENCES `users`(`id`), - FOREIGN KEY(`track_id`) REFERENCES `tracks`(`id`) + `id` integer PRIMARY KEY AUTOINCREMENT, + `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `user_id` integer NOT NULL, + `track_id` integer NOT NULL, + `latitude` double NOT NULL, + `longitude` double NOT NULL, + `altitude` double DEFAULT NULL, + `speed` double DEFAULT NULL, + `bearing` double DEFAULT NULL, + `accuracy` integer DEFAULT NULL, + `provider` varchar(100) DEFAULT NULL, + `comment` varchar(255) DEFAULT NULL, + `image_id` integer DEFAULT NULL, + FOREIGN KEY(`user_id`) REFERENCES `users`(`id`), + FOREIGN KEY(`track_id`) REFERENCES `tracks`(`id`) ); CREATE INDEX `idx_ptrack_id` ON `positions`(`track_id`); CREATE INDEX `idx_puser_id` ON `positions`(`user_id`); diff --git a/.tests/tests/MigrateTest.php b/.tests/tests/MigrateTest.php index daaa549..9873d56 100644 --- a/.tests/tests/MigrateTest.php +++ b/.tests/tests/MigrateTest.php @@ -81,7 +81,7 @@ class MigrateTest extends UloggerDatabaseTestCase { ["name" => "stroke_opacity", "value" => "i:1;"], ["name" => "stroke_weight", "value" => "i:22;"], ["name" => "units", "value" => "s:8:\"imperial\";"], - ["name" => "upload_maxsize", "value" => "i:0;"] + ["name" => "upload_maxsize", "value" => "i:5242880;"] ]]; $actual = $this->getConnection()->createQueryTable( "config", diff --git a/helpers/config.php b/helpers/config.php index d13c2c8..f87a1c8 100644 --- a/helpers/config.php +++ b/helpers/config.php @@ -135,10 +135,9 @@ class uConfig { * @var int Maximum size of uploaded files in bytes. * Will be adjusted to system maximum upload size */ - public $uploadMaxSize; + public $uploadMaxSize = 5242880; public function __construct($useDatabase = true) { - $this->uploadMaxSize = uUtils::getUploadMaxSize(); if ($useDatabase) { $this->setFromDatabase(); } @@ -227,10 +226,10 @@ class uConfig { WHEN 'color_start' THEN $placeholder WHEN 'color_stop' THEN $placeholder WHEN 'google_key' THEN $placeholder - WHEN 'interval_seconds' THEN $placeholder - WHEN 'lang' THEN $placeholder WHEN 'latitude' THEN $placeholder WHEN 'longitude' THEN $placeholder + WHEN 'interval_seconds' THEN $placeholder + WHEN 'lang' THEN $placeholder WHEN 'map_api' THEN $placeholder WHEN 'pass_lenmin' THEN $placeholder WHEN 'pass_strength' THEN $placeholder @@ -429,9 +428,17 @@ class uConfig { } if (isset($arr['upload_maxsize']) && is_numeric($arr['upload_maxsize'])) { $this->uploadMaxSize = (int) $arr['upload_maxsize']; - if ($this->uploadMaxSize === 0 || $this->uploadMaxSize > uUtils::getUploadMaxSize()) { - $this->uploadMaxSize = uUtils::getUploadMaxSize(); - } + $this->setUploadLimit(); + } + } + + /** + * Adjust uploadMaxSize to system limits + */ + private function setUploadLimit() { + $limit = uUtils::getSystemUploadLimit(); + if ($this->uploadMaxSize <= 0 || $this->uploadMaxSize > $limit) { + $this->uploadMaxSize = $limit; } } } diff --git a/helpers/upload.php b/helpers/upload.php index 2fdfbf0..2fe8fde 100644 --- a/helpers/upload.php +++ b/helpers/upload.php @@ -141,7 +141,7 @@ class uUpload { $file = NULL; $fileError = isset($fileMeta[self::META_ERROR]) ? $fileMeta[self::META_ERROR] : UPLOAD_ERR_OK; - if ($fileMeta[self::META_SIZE] > uUtils::getUploadMaxSize() && $fileError == UPLOAD_ERR_OK) { + if ($fileMeta[self::META_SIZE] > uUtils::getSystemUploadLimit() && $fileError == UPLOAD_ERR_OK) { $fileError = UPLOAD_ERR_FORM_SIZE; } if ($fileError == UPLOAD_ERR_OK) { diff --git a/helpers/utils.php b/helpers/utils.php index 5dcd346..38bca7a 100644 --- a/helpers/utils.php +++ b/helpers/utils.php @@ -28,7 +28,7 @@ * * @return int Number of bytes */ - public static function getUploadMaxSize() { + public static function getSystemUploadLimit() { $upload_max_filesize = self::iniGetBytes('upload_max_filesize'); $post_max_size = self::iniGetBytes('post_max_size'); // post_max_size = 0 means unlimited size diff --git a/scripts/ulogger.mysql b/scripts/ulogger.mysql index 7fb7200..c77d3c7 100644 --- a/scripts/ulogger.mysql +++ b/scripts/ulogger.mysql @@ -106,7 +106,7 @@ INSERT INTO `config` (`name`, `value`) VALUES ('stroke_opacity', 'd:1;'), ('stroke_weight', 'i:2;'), ('units', 's:6:"metric";'), -('upload_maxsize', 'i:0;'); +('upload_maxsize', 'i:5242880;'); -- -------------------------------------------------------- diff --git a/scripts/ulogger.pgsql b/scripts/ulogger.pgsql index cf384cb..88c89e2 100644 --- a/scripts/ulogger.pgsql +++ b/scripts/ulogger.pgsql @@ -108,7 +108,7 @@ INSERT INTO config (name, value) VALUES ('stroke_opacity', 'd:1;'), ('stroke_weight', 'i:2;'), ('units', 's:6:"metric";'), -('upload_maxsize', 'i:0;'); +('upload_maxsize', 'i:5242880;'); -- -------------------------------------------------------- diff --git a/scripts/ulogger.sqlite b/scripts/ulogger.sqlite index 5888587..615d630 100644 --- a/scripts/ulogger.sqlite +++ b/scripts/ulogger.sqlite @@ -103,7 +103,7 @@ INSERT INTO `config` (`name`, `value`) VALUES ('stroke_opacity', 'd:1;'), ('stroke_weight', 'i:2;'), ('units', 's:6:"metric";'), -('upload_maxsize', 'i:0;'); +('upload_maxsize', 'i:5242880;'); -- --------------------------------------------------------