Browse Source

Merge branch 'master' into 3.next

Mark Story 8 years ago
parent
commit
487d367111

+ 10 - 1
.mailmap

@@ -1,5 +1,6 @@
 Mark Story <mark@mark-story.com>
 Mark Story <mark@mark-story.com> <mark@freshbooks.com>
+Mark Story <mark@mark-story.com> <markstory@freshbooks.com>
 José Lorenzo Rodríguez <jose.zap@gmail.com>
 José Lorenzo Rodríguez <jose.zap@gmail.com> <lorenzo@users.noreply.github.com>
 José Lorenzo Rodríguez <jose.zap@gmail.com> José Lorenzo Rodríguez Urdaneta <lorenzo@Venus-2.local>
@@ -41,9 +42,11 @@ dogmatic69 <dogmatic69@gmail.com>
 Majna <majnaggz@gmail.com>
 Robert Pustułka <robert.pustulka@gmail.com>
 Robert Pustułka <robert.pustulka@gmail.com> <r.pustulka@zano.pl>
+Robert Pustułka <robert.pustulka@gmail.com> <r.pustulka@robotusers.com>
 Thomas Ploch <t.ploch@reizwerk.com>
 Tigran Gabrielyan <tigrangab@gmail.com>
-Bryan Crowe <bryan@zapsolutions.com>
+Bryan Crowe <bryan@bryan-crowe.com>
+Bryan Crowe <bryan@bryan-crowe.com> <bryan@zapsolutions.com>
 Sam <sgpinkus@gmail.com>
 Jorge González <steinkel@gmail.com>
 Saleh Souzanchi <saleh.souzanchi@gmail.com>
@@ -102,3 +105,9 @@ Matt Alexander <alexandma@advisory.com>
 Matt Alexander <alexandma@advisory.com> <mattalexx@gmail.com>
 Mark van Driel <mvdriel@mvdriel-EP35-DS3R>
 Mark van Driel <mvdriel@mvdriel-EP35-DS3R> <mvdriel@mvdriel-UL30>
+Juan Basso <jrbasso@gmail.com>
+Juan Basso <jrbasso@gmail.com> <juan.basso@digitro.com.br>
+antograssiot <antograssiot@free.fr>
+antograssiot <antograssiot@free.fr> <agrassiot@tld-europe.com>
+Patrick Conroy <patrick.conroy@rockstargames.com>
+Patrick Conroy <patrick.conroy@rockstargames.com> <patrick@rockstargames.com>

+ 4 - 2
.travis.yml

@@ -41,7 +41,7 @@ matrix:
       env: PHPSTAN=1 DEFAULT=0
 
 before_install:
-  - if [ $TRAVIS_PHP_VERSION != 7.0 && $TRAVIS_PHP_VERSION != 'nightly' ]; then phpenv config-rm xdebug.ini; fi
+  - phpenv config-rm xdebug.ini
 
   - if [ $DB = 'mysql' ]; then mysql -u root -e 'CREATE DATABASE cakephp_test;'; fi
   - if [ $DB = 'mysql' ]; then mysql -u root -e 'CREATE DATABASE cakephp_test2;'; fi
@@ -56,16 +56,18 @@ before_install:
   - if [[ $DEFAULT = 1 || $PHPSTAN = 1 ]] ; then echo 'extension = redis.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi
   - if [[ $DEFAULT = 1 || $PHPSTAN = 1 ]] ; then echo 'extension = apcu.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi
   - if [[ $DEFAULT = 1 || $PHPSTAN = 1 ]] ; then echo 'apc.enable_cli = 1' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi
+
   - if [[ ${TRAVIS_PHP_VERSION:0:1} == "7" ]] ; then echo "yes" | pecl install channel://pecl.php.net/apcu-5.1.5 || true; fi
   - if [[ ${TRAVIS_PHP_VERSION:0:1} == "5" ]] ; then echo "yes" | pecl install apcu-4.0.11 || true; fi
   - if [[ ${TRAVIS_PHP_VERSION:0:1} == "5" && $DB = 'mysql' ]] ; then wget http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz; tar xf xcache-3.2.0.tar.gz; pushd xcache-3.2.0; phpize; ./configure; make; NO_INTERACTION=1 make test; make install; popd;printf "extension=xcache.so\nxcache.size=64M\nxcache.var_size=16M\nxcache.test=On" > ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi
+
   - sudo locale-gen da_DK
 
 before_script:
   - composer install --prefer-dist --no-interaction
 
 script:
-  - if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.0 ]]; then export CODECOVERAGE=1; vendor/bin/phpunit --coverage-clover=clover.xml; fi
+  - if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.0 ]]; then export CODECOVERAGE=1; phpdbg -qrr vendor/bin/phpunit --coverage-clover=clover.xml; fi
   - if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION != 7.0 ]]; then vendor/bin/phpunit; fi
 
   - if [[ $PHPCS = 1 ]]; then composer cs-check; fi

+ 1 - 1
VERSION.txt

@@ -16,4 +16,4 @@
 // @license       https://opensource.org/licenses/mit-license.php MIT License
 // +--------------------------------------------------------------------------------------------+ //
 ////////////////////////////////////////////////////////////////////////////////////////////////////
-3.5.7
+3.5.8

+ 10 - 6
src/Error/Middleware/ErrorHandlerMiddleware.php

@@ -19,7 +19,9 @@ use Cake\Core\Configure;
 use Cake\Core\Exception\Exception as CakeException;
 use Cake\Core\InstanceConfigTrait;
 use Cake\Error\ExceptionRenderer;
+use Cake\Error\PHP7ErrorException;
 use Cake\Log\Log;
+use Error;
 use Exception;
 use Throwable;
 
@@ -155,6 +157,11 @@ class ErrorHandlerMiddleware
             $this->exceptionRenderer = $this->getConfig('exceptionRenderer') ?: ExceptionRenderer::class;
         }
 
+        // For PHP5 backwards compatibility
+        if ($exception instanceof Error) {
+            $exception = new PHP7ErrorException($exception);
+        }
+
         if (is_string($this->exceptionRenderer)) {
             $class = App::className($this->exceptionRenderer, 'Error');
             if (!$class) {
@@ -184,12 +191,9 @@ class ErrorHandlerMiddleware
             return;
         }
 
-        $skipLog = $this->getConfig('skipLog');
-        if ($skipLog) {
-            foreach ((array)$skipLog as $class) {
-                if ($exception instanceof $class) {
-                    return;
-                }
+        foreach ((array)$this->getConfig('skipLog') as $class) {
+            if ($exception instanceof $class) {
+                return;
             }
         }
 

+ 14 - 0
src/Http/Client/Message.php

@@ -46,6 +46,20 @@ class Message
     const STATUS_ACCEPTED = 202;
 
     /**
+     * HTTP 203 code
+     *
+     * @var int
+     */
+    const STATUS_NON_AUTHORITATIVE_INFORMATION = 203;
+
+    /**
+     * HTTP 204 code
+     *
+     * @var int
+     */
+    const STATUS_NO_CONTENT = 204;
+
+    /**
      * HTTP 301 code
      *
      * @var int

+ 3 - 1
src/Http/Client/Response.php

@@ -236,7 +236,9 @@ class Response extends Message implements ResponseInterface
         $codes = [
             static::STATUS_OK,
             static::STATUS_CREATED,
-            static::STATUS_ACCEPTED
+            static::STATUS_ACCEPTED,
+            static::STATUS_NON_AUTHORITATIVE_INFORMATION,
+            static::STATUS_NO_CONTENT
         ];
 
         return in_array($this->code, $codes);

+ 60 - 1
src/Mailer/Email.php

@@ -242,6 +242,27 @@ class Email implements JsonSerializable, Serializable
     public $headerCharset;
 
     /**
+     * The email transfer encoding used.
+     * If null, the $charset property is used for determined the transfer encoding.
+     *
+     * @var string|null
+     */
+    protected $transferEncoding;
+
+    /**
+     * Available encoding to be set for transfer.
+     *
+     * @var array
+     */
+    protected $_transferEncodingAvailable = [
+        '7bit',
+        '8bit',
+        'base64',
+        'binary',
+        'quoted-printable'
+    ];
+
+    /**
      * The application wide charset, used to encode headers and body
      *
      * @var string|null
@@ -844,6 +865,38 @@ class Email implements JsonSerializable, Serializable
     }
 
     /**
+     * TransferEncoding setter.
+     *
+     * @param string|null $encoding Encoding set.
+     * @return $this
+     */
+    public function setTransferEncoding($encoding)
+    {
+        $encoding = strtolower($encoding);
+        if (!in_array($encoding, $this->_transferEncodingAvailable)) {
+            throw new InvalidArgumentException(
+                sprintf(
+                    'Transfer encoding not available. Can be : %s.',
+                    implode(', ', $this->_transferEncodingAvailable)
+                )
+            );
+        }
+        $this->transferEncoding = $encoding;
+
+        return $this;
+    }
+
+    /**
+     * TransferEncoding getter.
+     *
+     * @return string|null Encoding
+     */
+    public function getTransferEncoding()
+    {
+        return $this->transferEncoding;
+    }
+
+    /**
      * EmailPattern setter/getter
      *
      * @param string|null $regex The pattern to use for email address validation,
@@ -2268,6 +2321,7 @@ class Email implements JsonSerializable, Serializable
         $this->_priority = null;
         $this->charset = 'utf-8';
         $this->headerCharset = null;
+        $this->transferEncoding = null;
         $this->_attachments = [];
         $this->_profile = [];
         $this->_emailPattern = self::EMAIL_PATTERN;
@@ -2699,12 +2753,17 @@ class Email implements JsonSerializable, Serializable
     }
 
     /**
-     * Return the Content-Transfer Encoding value based on the set charset
+     * Return the Content-Transfer Encoding value based
+     * on the set transferEncoding or set charset.
      *
      * @return string
      */
     protected function _getContentTransferEncoding()
     {
+        if ($this->transferEncoding) {
+            return $this->transferEncoding;
+        }
+
         $charset = strtoupper($this->charset);
         if (in_array($charset, $this->_charset8bit)) {
             return '8bit';

+ 2 - 2
src/View/Helper/PaginatorHelper.php

@@ -899,7 +899,7 @@ class PaginatorHelper extends Helper
     /**
      * Generates the first number for the paginator numbers() method.
      *
-     * @param \Cake\View\StringTemplate $ellipsis StringTemplate instance.
+     * @param string $ellipsis Ellipsis character.
      * @param array $params Params from the numbers() method.
      * @param int $start Start number.
      * @param array $options Options from the numbers() method.
@@ -923,7 +923,7 @@ class PaginatorHelper extends Helper
     /**
      * Generates the last number for the paginator numbers() method.
      *
-     * @param \Cake\View\StringTemplate $ellipsis StringTemplate instance.
+     * @param string $ellipsis Ellipsis character.
      * @param array $params Params from the numbers() method.
      * @param int $end End number.
      * @param array $options Options from the numbers() method.

+ 1 - 1
tests/TestCase/Error/ErrorHandlerTest.php

@@ -153,7 +153,7 @@ class ErrorHandlerTest extends TestCase
     /**
      * provides errors for mapping tests.
      *
-     * @return void
+     * @return array
      */
     public static function errorProvider()
     {

+ 19 - 0
tests/TestCase/Error/Middleware/ErrorHandlerMiddlewareTest.php

@@ -19,6 +19,7 @@ use Cake\Http\Response;
 use Cake\Http\ServerRequestFactory;
 use Cake\Log\Log;
 use Cake\TestSuite\TestCase;
+use Error;
 use LogicException;
 use Psr\Log\LoggerInterface;
 
@@ -147,6 +148,24 @@ class ErrorHandlerMiddlewareTest extends TestCase
     }
 
     /**
+     * Test handling PHP 7's Error instance.
+     *
+     * @return void
+     */
+    public function testHandlePHP7Error()
+    {
+        $this->skipIf(version_compare(PHP_VERSION, '7.0.0', '<'), 'Error class only exists since PHP 7.');
+
+        $middleware = new ErrorHandlerMiddleware();
+        $request = ServerRequestFactory::fromGlobals();
+        $response = new Response();
+        $error = new Error();
+
+        $result = $middleware->handleException($error, $request, $response);
+        $this->assertInstanceOf(Response::class, $result);
+    }
+
+    /**
      * Test rendering an error page logs errors
      *
      * @return void

+ 14 - 0
tests/TestCase/Http/Client/ResponseTest.php

@@ -216,6 +216,20 @@ XML;
         $this->assertTrue($response->isOk());
 
         $headers = [
+            'HTTP/1.1 203 Non-Authoritative Information',
+            'Content-Type: text/html'
+        ];
+        $response = new Response($headers, 'ok');
+        $this->assertTrue($response->isOk());
+
+        $headers = [
+            'HTTP/1.1 204 No Content',
+            'Content-Type: text/html'
+        ];
+        $response = new Response($headers, 'ok');
+        $this->assertTrue($response->isOk());
+
+        $headers = [
             'HTTP/1.1 301 Moved Permanently',
             'Content-Type: text/html'
         ];

+ 34 - 0
tests/TestCase/Mailer/EmailTest.php

@@ -90,6 +90,16 @@ class TestEmail extends Email
     {
         return $this->_render($content);
     }
+
+    /**
+     * GetContentTransferEncoding to protected method
+     *
+     * @return string
+     */
+    public function getContentTransferEncoding()
+    {
+        return $this->_getContentTransferEncoding();
+    }
 }
 
 /**
@@ -2499,6 +2509,30 @@ class EmailTest extends TestCase
     }
 
     /**
+     * Test transferEncoding
+     *
+     * @return void
+     */
+    public function testTransferEncoding()
+    {
+        // Test new transfer encoding
+        $expected = 'quoted-printable';
+        $this->Email->setTransferEncoding($expected);
+        $this->assertSame($expected, $this->Email->getTransferEncoding());
+        $this->assertSame($expected, $this->Email->getContentTransferEncoding());
+
+        // Test default charset/encoding : utf8/8bit
+        $expected = '8bit';
+        $this->Email->reset();
+        $this->assertNull($this->Email->getTransferEncoding());
+        $this->assertSame($expected, $this->Email->getContentTransferEncoding());
+
+        //Test wrong encoding
+        $this->expectException(\InvalidArgumentException::class);
+        $this->Email->setTransferEncoding('invalid');
+    }
+
+    /**
      * Tests for compatible check.
      *          charset property and       charset() method.
      *    headerCharset property and headerCharset() method.