浏览代码

Merge remote-tracking branch 'origin/cake3'

# Conflicts:
#	README.md
#	docs/README.md
#	docs/Utility/FileLog.md
#	src/Utility/FileLog.php
#	src/View/Helper/HtmlHelper.php
#	tests/TestCase/Utility/FileLogTest.php
#	tests/bootstrap.php
mscherer 5 年之前
父节点
当前提交
dd9aee7f54

+ 1 - 1
composer.json

@@ -45,7 +45,7 @@
 		"issues": "https://github.com/dereuromark/cakephp-tools/issues"
 		"issues": "https://github.com/dereuromark/cakephp-tools/issues"
 	},
 	},
 	"scripts": {
 	"scripts": {
-		"stan": "phpstan analyse -c tests/phpstan.neon -l 5 src/",
+		"stan": "phpstan analyse -c tests/phpstan.neon -l 6 src/",
 		"stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:^0.12.1 && mv composer.backup composer.json",
 		"stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:^0.12.1 && mv composer.backup composer.json",
 		"test": "php phpunit.phar",
 		"test": "php phpunit.phar",
 		"test-setup": "[ ! -f phpunit.phar ] && wget https://phar.phpunit.de/phpunit-8.5.1.phar && mv phpunit-8.5.1.phar phpunit.phar || true",
 		"test-setup": "[ ! -f phpunit.phar ] && wget https://phar.phpunit.de/phpunit-8.5.1.phar && mv phpunit-8.5.1.phar phpunit.phar || true",

+ 1 - 1
docs/Contributing.md

@@ -15,7 +15,7 @@ There are a few guidelines that I need contributors to follow:
 * Coding standards (`composer cs-check` to check and `composer cs-fix` to fix)
 * Coding standards (`composer cs-check` to check and `composer cs-fix` to fix)
 * Passing tests (you can enable travis to assert your changes pass) for Windows and Unix (`php phpunit.phar`)
 * Passing tests (you can enable travis to assert your changes pass) for Windows and Unix (`php phpunit.phar`)
 
 
-## i18n 
+## i18n
 Check if translations via pot file need to be changed.
 Check if translations via pot file need to be changed.
 Run
 Run
 ```
 ```

+ 3 - 0
docs/Utility/FileLog.md

@@ -9,6 +9,7 @@ To write log data into custom file with default CakePHP `Cake\Log\Log` class fee
 1. Configure FileLog Adapter:
 1. Configure FileLog Adapter:
 ```php
 ```php
 use Cake\Log\Log;
 use Cake\Log\Log;
+
 Log::config('custom_file', [
 Log::config('custom_file', [
     'className' => 'File',
     'className' => 'File',
     'path' => LOGS,
     'path' => LOGS,
@@ -36,7 +37,9 @@ You can directly pass data to log and filename to write the data into.
 
 
 ```php
 ```php
 use Tools\Utility\FileLog;
 use Tools\Utility\FileLog;
+
 FileLog::write("Something didn't work!", 'my_file');
 FileLog::write("Something didn't work!", 'my_file');
+
 // Somewhere else in any file
 // Somewhere else in any file
 FileLog::write([
 FileLog::write([
     'user' => [
     'user' => [

+ 17 - 12
src/View/Helper/FormatHelper.php

@@ -174,17 +174,19 @@ class FormatHelper extends Helper {
 	/**
 	/**
 	 * Displays gender icon
 	 * Displays gender icon
 	 *
 	 *
-	 * @param mixed $value
+	 * @param int|string $value
+	 * @param array $options
+	 * @param array $attributes
 	 * @return string
 	 * @return string
 	 */
 	 */
-	public function genderIcon($value) {
+	public function genderIcon($value, array $options = [], array $attributes = []) {
 		$value = (int)$value;
 		$value = (int)$value;
 		if ($value == static::GENDER_FEMALE) {
 		if ($value == static::GENDER_FEMALE) {
-			$icon = $this->icon('female');
+			$icon = $this->icon('female', $options, $attributes);
 		} elseif ($value == static::GENDER_MALE) {
 		} elseif ($value == static::GENDER_MALE) {
-			$icon = $this->icon('male');
+			$icon = $this->icon('male', $options, $attributes);
 		} else {
 		} else {
-			$icon = $this->icon('genderless', [], ['title' => __d('tools', 'Unknown')]);
+			$icon = $this->icon('genderless', $options, $attributes + ['title' => __d('tools', 'Unknown')]);
 		}
 		}
 
 
 		return $icon;
 		return $icon;
@@ -376,10 +378,11 @@ class FormatHelper extends Helper {
 
 
 		if (!isset($attributes['title'])) {
 		if (!isset($attributes['title'])) {
 			$attributes['title'] = ucfirst($type);
 			$attributes['title'] = ucfirst($type);
-			if (!isset($options['translate']) || $options['translate'] !== false) {
-				$attributes['title'] = __($attributes['title']);
-			}
 		}
 		}
+		if (!isset($options['translate']) || $options['translate'] !== false) {
+			$attributes['title'] = __($attributes['title']);
+		}
+
 		if (isset($attributes['class'])) {
 		if (isset($attributes['class'])) {
 			$options['class'] .= ' ' . $attributes['class'];
 			$options['class'] .= ' ' . $attributes['class'];
 			unset($attributes['class']);
 			unset($attributes['class']);
@@ -501,14 +504,16 @@ class FormatHelper extends Helper {
 		$currentPage = $paginator['page'];
 		$currentPage = $paginator['page'];
 		$pageCount = $paginator['pageCount'];
 		$pageCount = $paginator['pageCount'];
 		$totalCount = $paginator['count'];
 		$totalCount = $paginator['count'];
-		$limit = $paginator['limit'];
+		$limit = $paginator['perPage'];
 		$step = isset($paginator['step']) ? $paginator['step'] : 1;
 		$step = isset($paginator['step']) ? $paginator['step'] : 1;
 
 
 		if ($dir === 'DESC') {
 		if ($dir === 'DESC') {
+			$count = $limit - $count + 1;
+		}
+
+		if ($dir === 'DESC') {
 			$currentCount = $count + ($pageCount - $currentPage) * $limit * $step;
 			$currentCount = $count + ($pageCount - $currentPage) * $limit * $step;
-			if ($currentPage != $pageCount && $pageCount > 1) {
-				$currentCount -= $pageCount * $limit * $step - $totalCount;
-			}
+			$currentCount -= $pageCount * $limit * $step - $totalCount;
 		} else {
 		} else {
 			$currentCount = $count + ($currentPage - 1) * $limit * $step;
 			$currentCount = $count + ($currentPage - 1) * $limit * $step;
 		}
 		}

+ 3 - 0
src/View/Helper/HtmlHelper.php

@@ -97,6 +97,9 @@ class HtmlHelper extends CoreHtmlHelper {
 				$url['?'] = [];
 				$url['?'] = [];
 			}
 			}
 			$url['?'] += $this->_View->getRequest()->getQuery();
 			$url['?'] += $this->_View->getRequest()->getQuery();
+
+			$pass = $this->_View->getRequest()->getParam('pass');
+			$url = array_merge($url, $pass);
 		}
 		}
 
 
 		return parent::link($title, $url, $options);
 		return parent::link($title, $url, $options);

+ 13 - 0
src/View/Helper/UrlHelper.php

@@ -41,6 +41,7 @@ class UrlHelper extends CoreUrlHelper {
 	 */
 	 */
 	public function completeArray(array $url): array {
 	public function completeArray(array $url): array {
 		$url = $this->addQueryStrings($url);
 		$url = $this->addQueryStrings($url);
+		$url = $this->addPassed($url);
 
 
 		return $url;
 		return $url;
 	}
 	}
@@ -104,4 +105,16 @@ class UrlHelper extends CoreUrlHelper {
 		return $url;
 		return $url;
 	}
 	}
 
 
+	/**
+	 * @param array $url
+	 *
+	 * @return array
+	 */
+	protected function addPassed(array $url) {
+		$pass = $this->_View->getRequest()->getParam('pass');
+		$url = array_merge($url, $pass);
+
+		return $url;
+	}
+
 }
 }

+ 37 - 6
tests/TestCase/View/Helper/FormatHelperTest.php

@@ -224,8 +224,6 @@ class FormatHelperTest extends TestCase {
 	}
 	}
 
 
 	/**
 	/**
-	 * FormatHelperTest::testPad()
-	 *
 	 * @return void
 	 * @return void
 	 */
 	 */
 	public function testPad() {
 	public function testPad() {
@@ -239,8 +237,6 @@ class FormatHelperTest extends TestCase {
 	}
 	}
 
 
 	/**
 	/**
-	 * FormatHelperTest::testAbsolutePaginateCount()
-	 *
 	 * @return void
 	 * @return void
 	 */
 	 */
 	public function testAbsolutePaginateCount() {
 	public function testAbsolutePaginateCount() {
@@ -248,10 +244,45 @@ class FormatHelperTest extends TestCase {
 			'page' => 1,
 			'page' => 1,
 			'pageCount' => 3,
 			'pageCount' => 3,
 			'count' => 25,
 			'count' => 25,
-			'limit' => 10,
+			'perPage' => 10,
 		];
 		];
 		$result = $this->Format->absolutePaginateCount($paginator, 2);
 		$result = $this->Format->absolutePaginateCount($paginator, 2);
-		$this->assertEquals(2, $result);
+		$this->assertSame(2, $result);
+	}
+
+	/**
+	 * @return void
+	 */
+	public function testAbsolutePaginateCountDesc() {
+		// 2nd element on page 1/3
+		$paginator = [
+			'page' => 1,
+			'pageCount' => 3,
+			'count' => 25,
+			'perPage' => 10,
+		];
+		$result = $this->Format->absolutePaginateCount($paginator, 2, 'DESC');
+		$this->assertSame(24, $result);
+
+		// 3rd element on page 3/3
+		$paginator = [
+			'page' => 3,
+			'pageCount' => 3,
+			'count' => 25,
+			'perPage' => 10,
+		];
+		$result = $this->Format->absolutePaginateCount($paginator, 3, 'DESC');
+		$this->assertSame(3, $result);
+
+		// 2nd element on page 1/1
+		$paginator = [
+			'page' => 1,
+			'pageCount' => 1,
+			'count' => 9,
+			'perPage' => 10,
+		];
+		$result = $this->Format->absolutePaginateCount($paginator, 2, 'DESC');
+		$this->assertSame(8, $result);
 	}
 	}
 
 
 	/**
 	/**

+ 2 - 0
tests/phpstan.neon

@@ -1,4 +1,6 @@
 parameters:
 parameters:
+	checkMissingIterableValueType: false
+	checkGenericClassInNonGenericObjectType: false
 	autoload_files:
 	autoload_files:
 	- %rootDir%/../../../tests/bootstrap.php
 	- %rootDir%/../../../tests/bootstrap.php
 	excludes_analyse:
 	excludes_analyse: