Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/YOURLS/YOURLS.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
author྅༻ Ǭɀħ ༄༆ཉ <ozh@ozh.org>2022-05-02 09:09:18 +0300
committerGitHub <noreply@github.com>2022-05-02 09:09:18 +0300
commit9def41dba83ad42232210139667528b4ac9bb3be (patch)
tree68c05e6e710a14271f14175ab361a6a578698a31 /tests
parenta2d0d2f626c7ee8fcd280eb91d08c61354578d04 (diff)
Remove warnings on PHP 8.1 (#3317)
Also, minor code styles doc & typo * Refactor yourls_filter_unique_id() to remove useless vars * Comply with phpstan level 4 * add some tests to cover newly discovered potential issues
Diffstat (limited to 'tests')
-rw-r--r--tests/data/auth/nopassword.php3
-rw-r--r--tests/data/auth/preg_replace_problem.php9
-rw-r--r--tests/tests/auth/auth.php14
-rw-r--r--tests/tests/auth/logout.php2
-rw-r--r--tests/tests/format/sanitizing.php1
-rw-r--r--tests/tests/plugins/helpers.php13
-rw-r--r--tests/tests/shorturl/crud.php7
7 files changed, 48 insertions, 1 deletions
diff --git a/tests/data/auth/nopassword.php b/tests/data/auth/nopassword.php
new file mode 100644
index 00000000..c4f37750
--- /dev/null
+++ b/tests/data/auth/nopassword.php
@@ -0,0 +1,3 @@
+<?php
+
+/** No password defined */
diff --git a/tests/data/auth/preg_replace_problem.php b/tests/data/auth/preg_replace_problem.php
new file mode 100644
index 00000000..6639f971
--- /dev/null
+++ b/tests/data/auth/preg_replace_problem.php
@@ -0,0 +1,9 @@
+<?php
+
+/** Valid PHP syntax but too complicated for our parser */
+
+$login = 'joe';
+$password = 'some_password';
+$yourls_user_passwords = [
+ $login => $password,
+];
diff --git a/tests/tests/auth/auth.php b/tests/tests/auth/auth.php
index 3cd8b0f2..703acbb1 100644
--- a/tests/tests/auth/auth.php
+++ b/tests/tests/auth/auth.php
@@ -216,6 +216,20 @@ class Auth_Func_Tests extends PHPUnit\Framework\TestCase {
}
/**
+ * Check that encrypting file with no passwords returns expected error
+ */
+ public function test_hash_passwords_now_no_pwd() {
+ $this->assertSame('no password found', yourls_hash_passwords_now( YOURLS_TESTDATA_DIR . '/auth/nopassword.php' ) );
+ }
+
+ /**
+ * Check that encrypting file with incorrect content returns expected error
+ */
+ public function test_hash_passwords_now_bad_content() {
+ $this->assertSame('preg_replace problem', yourls_hash_passwords_now( YOURLS_TESTDATA_DIR . '/auth/preg_replace_problem.php' ) );
+ }
+
+ /**
* Check that in-file password encryption works as expected with different kinds of passwords
*
* This test checks that encrypting the config file, with different kinds of pwd, results in a valid
diff --git a/tests/tests/auth/logout.php b/tests/tests/auth/logout.php
index a7153d9e..674d0097 100644
--- a/tests/tests/auth/logout.php
+++ b/tests/tests/auth/logout.php
@@ -51,7 +51,7 @@ class Logout_Func_Tests extends PHPUnit\Framework\TestCase {
$_REQUEST['nonce'] = yourls_create_nonce('admin_logout', 'logout');
$invalid = yourls_is_valid_user();
$this->assertNotTrue( $invalid );
- $this->assertSame(self::$user, null);
+ $this->assertSame(self::$user, '');
}
/**
diff --git a/tests/tests/format/sanitizing.php b/tests/tests/format/sanitizing.php
index fe48137e..31b9445a 100644
--- a/tests/tests/format/sanitizing.php
+++ b/tests/tests/format/sanitizing.php
@@ -34,6 +34,7 @@ class Format_Sanitize extends PHPUnit\Framework\TestCase {
$unsane = '<tag></tag><omg>';
$this->assertSame( $expected, yourls_sanitize_title( $unsane ) );
$this->assertSame( $fallback, yourls_sanitize_title( $unsane, $fallback ) );
+ $this->assertSame( $fallback, yourls_sanitize_title( '', $fallback ) );
}
/**
diff --git a/tests/tests/plugins/helpers.php b/tests/tests/plugins/helpers.php
index b662e849..d954c0ce 100644
--- a/tests/tests/plugins/helpers.php
+++ b/tests/tests/plugins/helpers.php
@@ -30,4 +30,17 @@ class Plugin_Helpers_Tests extends PHPUnit\Framework\TestCase {
$this->assertSame( $value, call_user_func($func) );
}
+ /**
+ * Test return values of yourls_filter_unique_id()
+ */
+ function test_yourls_filter_unique_id() {
+ $func_name = rand_str();
+
+ $this->assertSame( $func_name, yourls_filter_unique_id($func_name) );
+ $this->assertIsString( yourls_filter_unique_id( function(){return rand_str();} ) ); // unpredictable string
+ $this->assertSame('SomeClass::SomeMethod', yourls_filter_unique_id( 'SomeClass::SomeMethod' ));
+ $this->assertSame('SomeClass::SomeMethod', yourls_filter_unique_id( array( 'SomeClass', 'SomeMethod' ) ));
+ $this->assertIsString( yourls_filter_unique_id( array( $this, 'test_check_timestamp' ) )); // unpredictable string
+ }
+
}
diff --git a/tests/tests/shorturl/crud.php b/tests/tests/shorturl/crud.php
index 5335c1cd..57446738 100644
--- a/tests/tests/shorturl/crud.php
+++ b/tests/tests/shorturl/crud.php
@@ -68,10 +68,17 @@ class ShortURL_CRUD_Tests extends PHPUnit\Framework\TestCase {
$cache = yourls_get_keyword_infos( $keyword, false );
$this->assertEquals( 0, yourls_get_keyword_clicks( $keyword ) );
+ // Increment by 1
$this->assertEquals( 1, yourls_update_clicks( $keyword ) );
// purge cache
yourls_get_keyword_infos( $keyword, false );
$this->assertEquals( 1, yourls_get_keyword_clicks( $keyword ) );
+
+ // Increment by specified number
+ $this->assertEquals( 1, yourls_update_clicks( $keyword, 10 ) );
+ // purge cache
+ yourls_get_keyword_infos( $keyword, false );
+ $this->assertEquals( 10, yourls_get_keyword_clicks( $keyword ) );
}
/**