Browse Source

Merge branch 'master' into 3.next

Mark Story 8 years ago
parent
commit
acb2ce9780

+ 1 - 1
VERSION.txt

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

+ 8 - 1
src/Console/Shell.php

@@ -900,7 +900,14 @@ class Shell
 
         $this->_io->out();
 
-        if (is_file($path) && empty($this->params['force']) && $this->interactive) {
+        $fileExists = is_file($path);
+        if ($fileExists && empty($this->params['force']) && !$this->interactive) {
+            $this->_io->out('<warning>File exists, skipping</warning>.');
+
+            return false;
+        }
+
+        if ($fileExists && $this->interactive && empty($this->params['force'])) {
             $this->_io->out(sprintf('<warning>File `%s` exists</warning>', $path));
             $key = $this->_io->askChoice('Do you want to overwrite?', ['y', 'n', 'a', 'q'], 'n');
 

+ 14 - 1
src/Utility/Text.php

@@ -30,6 +30,16 @@ class Text
     protected static $_defaultTransliteratorId = 'Any-Latin; Latin-ASCII; [\u0080-\u7fff] remove';
 
     /**
+     * Default html tags who must not be count for truncate text.
+     *
+     * @var array
+     */
+    protected static $_defaultHtmlNoCount = [
+        'style',
+        'script'
+    ];
+
+    /**
      * Generate a random UUID version 4
      *
      * Warning: This method should not be used as a random seed for any cryptographic operations.
@@ -609,7 +619,10 @@ class Text
 
             preg_match_all('/(<\/?([\w+]+)[^>]*>)?([^<>]*)/', $text, $tags, PREG_SET_ORDER);
             foreach ($tags as $tag) {
-                $contentLength = self::_strlen($tag[3], $options);
+                $contentLength = 0;
+                if (!in_array($tag[2], static::$_defaultHtmlNoCount, true)) {
+                    $contentLength = self::_strlen($tag[3], $options);
+                }
 
                 if ($truncate === '') {
                     if (!preg_match('/img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param/i', $tag[2])) {

+ 42 - 71
tests/TestCase/Console/ShellTest.php

@@ -20,78 +20,11 @@ use Cake\Console\Shell;
 use Cake\Core\Plugin;
 use Cake\Filesystem\Folder;
 use Cake\TestSuite\TestCase;
+use TestApp\Shell\MergeShell;
+use TestApp\Shell\ShellTestShell;
 use TestApp\Shell\TestingDispatchShell;
 
 /**
- * for testing merging vars
- */
-class MergeShell extends Shell
-{
-
-    public $tasks = ['Command', 'Extract'];
-
-    public $modelClass = 'Articles';
-}
-
-/**
- * ShellTestShell class
- */
-class ShellTestShell extends Shell
-{
-
-    /**
-     * name property
-     *
-     * @var string
-     */
-    public $name = 'ShellTestShell';
-
-    /**
-     * stopped property
-     *
-     * @var int
-     */
-    public $stopped;
-
-    /**
-     * testMessage property
-     *
-     * @var string
-     */
-    public $testMessage = 'all your base are belong to us';
-
-    /**
-     * stop method
-     *
-     * @param int $status
-     * @return void
-     */
-    protected function _stop($status = Shell::CODE_SUCCESS)
-    {
-        $this->stopped = $status;
-    }
-
-    protected function _secret()
-    {
-    }
-
-    //@codingStandardsIgnoreStart
-    public function doSomething()
-    {
-    }
-
-    protected function noAccess()
-    {
-    }
-
-    public function logSomething()
-    {
-        $this->log($this->testMessage);
-    }
-    //@codingStandardsIgnoreEnd
-}
-
-/**
  * TestAppleTask class
  */
 class TestAppleTask extends Shell
@@ -129,6 +62,14 @@ class ShellTest extends TestCase
         'core.users'
     ];
 
+    /** @var \Cake\Console\Shell */
+    protected $Shell;
+
+    /**
+     * @var \Cake\Console\ConsoleIo|\PHPUnit\Framework\MockObject\MockObject
+     */
+    protected $io;
+
     /**
      * setUp method
      *
@@ -580,6 +521,8 @@ class ShellTest extends TestCase
         new Folder($path, true);
 
         $contents = "<?php{$eol}echo 'test';${eol}\$te = 'st';{$eol}";
+
+        $this->Shell->interactive = false;
         $result = $this->Shell->createFile($file, $contents);
         $this->assertTrue($result);
         $this->assertFileExists($file);
@@ -587,6 +530,30 @@ class ShellTest extends TestCase
     }
 
     /**
+     * Test that while in non interactive mode it will not overwrite files by default.
+     *
+     * @return void
+     */
+    public function testCreateFileNonInteractiveFileExists()
+    {
+        $eol = PHP_EOL;
+        $path = TMP . 'shell_test';
+        $file = $path . DS . 'file1.php';
+        if (!is_dir($path)) {
+            mkdir($path, 0770, true);
+        }
+        touch($file);
+        $this->assertFileExists($file);
+
+        new Folder($path, true);
+
+        $contents = "<?php{$eol}echo 'test';${eol}\$te = 'st';{$eol}";
+        $this->Shell->interactive = false;
+        $result = $this->Shell->createFile($file, $contents);
+        $this->assertFalse($result);
+    }
+
+    /**
      * Test that files are not changed with a 'n' reply.
      *
      * @return void
@@ -641,7 +608,8 @@ class ShellTest extends TestCase
     }
 
     /**
-     * Test that there is no user prompt in non-interactive mode while file already exists.
+     * Test that there is no user prompt in non-interactive mode while file already exists
+     * and if force mode is explicitly enabled.
      *
      * @return void
      */
@@ -657,6 +625,7 @@ class ShellTest extends TestCase
 
         $this->io->expects($this->never())->method('askChoice');
 
+        $this->Shell->params['force'] = true;
         $this->Shell->interactive = false;
         $result = $this->Shell->createFile($file, 'My content');
         $this->assertTrue($result);
@@ -1052,6 +1021,7 @@ TEXT;
      */
     public function testRunCommandWithMissingMethodInSubcommands()
     {
+        /** @var \Cake\Console\ConsoleOptionParser|\PHPUnit\Framework\MockObject\MockObject $parser */
         $parser = $this->getMockBuilder('Cake\Console\ConsoleOptionParser')
             ->setMethods(['help'])
             ->setConstructorArgs(['knife'])
@@ -1059,6 +1029,7 @@ TEXT;
         $parser->addSubCommand('slice');
 
         $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
+        /** @var \Cake\Console\Shell|\PHPUnit\Framework\MockObject\MockObject $shell */
         $shell = $this->getMockBuilder('Cake\Console\Shell')
             ->setMethods(['getOptionParser', 'startup'])
             ->setConstructorArgs([$io])
@@ -1418,7 +1389,7 @@ TEXT;
             ->method('setLoggers')
             ->with(ConsoleIo::QUIET);
 
-        $this->Shell = $this->getMockBuilder(__NAMESPACE__ . '\ShellTestShell')
+        $this->Shell = $this->getMockBuilder(ShellTestShell::class)
             ->setMethods(['welcome'])
             ->setConstructorArgs([$io])
             ->getMock();

+ 4 - 2
tests/TestCase/Event/EventManagerTest.php

@@ -941,7 +941,7 @@ class EventManagerTest extends TestCase
      *
      * @return void
      */
-    public function testDebubInfoEventList()
+    public function testDebugInfoEventList()
     {
         $eventList = new EventList();
         $eventManager = new EventManager();
@@ -956,9 +956,11 @@ class EventManagerTest extends TestCase
                     'example' => '1 listener(s)',
                 ],
                 '_isGlobal' => false,
-                '_eventList' => $eventList,
                 '_trackEvents' => true,
                 '_generalManager' => '(object) EventManager',
+                '_dispatchedEvents' => [
+                    'example with subject Cake\Event\EventManager'
+                ],
             ],
             $eventManager->__debugInfo()
         );

+ 2 - 2
tests/TestCase/Shell/CommandListShellTest.php

@@ -65,7 +65,7 @@ class CommandListShellTest extends ConsoleIntegrationTestCase
         $expected = "/\[.*CORE.*\] cache, help, i18n, orm_cache, plugin, routes, schema_cache, server/";
         $this->assertOutputRegExp($expected);
 
-        $expected = "/\[.*app.*\] demo, i18m, integration, sample/";
+        $expected = "/\[.*app.*\] demo, i18m, integration, merge, sample/";
         $this->assertOutputRegExp($expected);
         $this->assertExitCode(Shell::CODE_SUCCESS);
         $this->assertErrorEmpty();
@@ -86,7 +86,7 @@ class CommandListShellTest extends ConsoleIntegrationTestCase
         $expected = "/\[.*CORE.*\] cache, help, orm_cache, plugin, routes, schema_cache, server, version/";
         $this->assertOutputRegExp($expected);
 
-        $expected = "/\[.*app.*\] demo, i18n, integration, sample/";
+        $expected = "/\[.*app.*\] demo, i18n, integration, merge, sample/";
         $this->assertOutputRegExp($expected);
         $this->assertExitCode(Shell::CODE_SUCCESS);
         $this->assertErrorEmpty();

+ 1 - 1
tests/TestCase/Shell/CompletionShellTest.php

@@ -117,7 +117,7 @@ class CompletionShellTest extends TestCase
 
         $expected = 'TestPlugin.example TestPlugin.sample TestPluginTwo.example unique welcome ' .
             'cache help i18n orm_cache plugin routes schema_cache server version ' .
-            "demo i18m integration sample testing_dispatch\n";
+            "demo i18m integration merge sample shell_test testing_dispatch\n";
         $this->assertTextEquals($expected, $output);
     }
 

+ 5 - 0
tests/TestCase/Utility/TextTest.php

@@ -592,6 +592,11 @@ TEXT;
         ]);
         $expected = '<p><span style="font-size: medium;"><a>Iamatestwi...</a></span></p>';
         $this->assertEquals($expected, $result);
+
+        $text = '<style>text-align: center;</style><script>console.log(\'test\');</script><p>The quick brown fox jumps over the lazy dog</p>';
+        $expected = '<style>text-align: center;</style><script>console.log(\'test\');</script><p>The qu...</p>';
+        $result = $this->Text->truncate($text, 9, ['html' => true, 'ellipsis' => '...']);
+        $this->assertSame($expected, $result);
     }
 
     /**

+ 1 - 6
tests/bootstrap.php

@@ -133,12 +133,7 @@ MutableDate::setTestNow(MutableDate::now());
 ini_set('intl.default_locale', 'en_US');
 ini_set('session.gc_divisor', '1');
 
-if (class_exists('PHPUnit_Runner_Version')) {
-    class_alias('PHPUnit_Framework_TestResult', 'PHPUnit\Framework\TestResult');
-    class_alias('PHPUnit_Framework_Error', 'PHPUnit\Framework\Error\Error');
-    class_alias('PHPUnit_Framework_Error_Warning', 'PHPUnit\Framework\Error\Warning');
-    class_alias('PHPUnit_Framework_ExpectationFailedException', 'PHPUnit\Framework\ExpectationFailedException');
-}
+loadPHPUnitAliases();
 
 // Fixate sessionid early on, as php7.2+
 // does not allow the sessionid to be set after stdout

+ 5 - 1
tests/phpunit_aliases.php

@@ -1,5 +1,5 @@
 <?php
-if (class_exists('PHPUnit_Runner_Version', false)) {
+if (class_exists('PHPUnit_Runner_Version')) {
     if (version_compare(\PHPUnit_Runner_Version::id(), '5.7', '<')) {
         trigger_error(sprintf('Your PHPUnit Version must be at least 5.7.0 to use CakePHP Testsuite, found %s', \PHPUnit_Runner_Version::id()), E_USER_ERROR);
     }
@@ -7,5 +7,9 @@ if (class_exists('PHPUnit_Runner_Version', false)) {
     class_alias('PHPUnit_Framework_Test', 'PHPUnit\Framework\Test');
     class_alias('PHPUnit_Framework_AssertionFailedError', 'PHPUnit\Framework\AssertionFailedError');
     class_alias('PHPUnit_Framework_TestSuite', 'PHPUnit\Framework\TestSuite');
+    class_alias('PHPUnit_Framework_TestResult', 'PHPUnit\Framework\TestResult');
+    class_alias('PHPUnit_Framework_Error', 'PHPUnit\Framework\Error\Error');
     class_alias('PHPUnit_Framework_Error_Deprecated', 'PHPUnit\Framework\Error\Deprecated');
+    class_alias('PHPUnit_Framework_Error_Warning', 'PHPUnit\Framework\Error\Warning');
+    class_alias('PHPUnit_Framework_ExpectationFailedException', 'PHPUnit\Framework\ExpectationFailedException');
 }

+ 36 - 0
tests/test_app/TestApp/Shell/MergeShell.php

@@ -0,0 +1,36 @@
+<?php
+/**
+ * MergeShell file
+ *
+ * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
+ * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * For full copyright and license information, please see the LICENSE.txt
+ * Redistributions of files must retain the above copyright notice
+ *
+ * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
+ * @link          https://cakephp.org CakePHP(tm) Project
+ * @since         3.0.8
+ * @license       https://opensource.org/licenses/mit-license.php MIT License
+ */
+
+namespace TestApp\Shell;
+
+use Cake\Console\Shell;
+
+/**
+ * for testing merging vars
+ */
+class MergeShell extends Shell
+{
+    /**
+     * @var array
+     */
+    public $tasks = ['DbConfig', 'Fixture'];
+
+    /**
+     * @var string
+     */
+    public $modelClass = 'Articles';
+}

+ 77 - 0
tests/test_app/TestApp/Shell/ShellTestShell.php

@@ -0,0 +1,77 @@
+<?php
+/**
+ * ShellTestShell file
+ *
+ * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
+ * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * For full copyright and license information, please see the LICENSE.txt
+ * Redistributions of files must retain the above copyright notice
+ *
+ * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
+ * @link          https://cakephp.org CakePHP(tm) Project
+ * @since         3.0.8
+ * @license       https://opensource.org/licenses/mit-license.php MIT License
+ */
+
+namespace TestApp\Shell;
+
+use Cake\Console\Shell;
+
+/**
+ * ShellTestShell class
+ */
+class ShellTestShell extends Shell
+{
+    /**
+     * name property
+     *
+     * @var string
+     */
+    public $name = 'ShellTestShell';
+
+    /**
+     * stopped property
+     *
+     * @var int
+     */
+    public $stopped;
+
+    /**
+     * testMessage property
+     *
+     * @var string
+     */
+    public $testMessage = 'all your base are belong to us';
+
+    /**
+     * stop method
+     *
+     * @param int $status
+     * @return void
+     */
+    protected function _stop($status = Shell::CODE_SUCCESS)
+    {
+        $this->stopped = $status;
+    }
+
+    protected function _secret()
+    {
+    }
+
+    //@codingStandardsIgnoreStart
+    public function doSomething()
+    {
+    }
+
+    protected function noAccess()
+    {
+    }
+
+    public function logSomething()
+    {
+        $this->log($this->testMessage);
+    }
+    //@codingStandardsIgnoreEnd
+}