[BUGFIX] IconViewHelper use wrong class for constant 31/42331/3
authorFrank Nägler <frank.naegler@typo3.org>
Thu, 6 Aug 2015 18:23:31 +0000 (20:23 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Fri, 7 Aug 2015 07:50:38 +0000 (09:50 +0200)
Resolves: #68809
Releases: master
Change-Id: Idb681b363ecfff686083db77c505696f363b17fa
Reviewed-on: http://review.typo3.org/42331
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/core/Classes/Imaging/IconRegistry.php
typo3/sysext/core/Classes/ViewHelpers/IconViewHelper.php
typo3/sysext/core/Documentation/Changelog/master/Feature-68741-IntroduceNewIconFactoryAsBaseForReplaceTheIconSkinningAPI.rst
typo3/sysext/core/Tests/Unit/ViewHelpers/IconViewHelperTest.php [new file with mode: 0644]

index 14a29a8..c6b3ac1 100644 (file)
@@ -29,13 +29,11 @@ class IconRegistry implements \TYPO3\CMS\Core\SingletonInterface {
         * @var array
         */
        protected $icons = array(
-               // @TODO: replace default icon before merge!
-               // default icon, fallback
+               // Default icon, fallback
                'default-not-found' => array(
                        'provider' => FontawesomeIconProvider::class,
                        'options' => array(
                                'name' => 'times-circle',
-                               'additionalClasses' => 'fa-fw'
                        )
                ),
 
@@ -44,35 +42,30 @@ class IconRegistry implements \TYPO3\CMS\Core\SingletonInterface {
                        'provider' => FontawesomeIconProvider::class,
                        'options' => array(
                                'name' => 'times',
-                               'additionalClasses' => 'fa-fw'
                        )
                ),
                'actions-document-export-csv' => array(
                        'provider' => FontawesomeIconProvider::class,
                        'options' => array(
                                'name' => 'download',
-                               'additionalClasses' => 'fa-fw'
                        )
                ),
                'actions-document-export-t3d' => array(
                        'provider' => FontawesomeIconProvider::class,
                        'options' => array(
                                'name' => 'download',
-                               'additionalClasses' => 'fa-fw'
                        )
                ),
                'actions-document-import-t3d' => array(
                        'provider' => FontawesomeIconProvider::class,
                        'options' => array(
                                'name' => 'upload',
-                               'additionalClasses' => 'fa-fw'
                        )
                ),
                'actions-document-open' => array(
                        'provider' => FontawesomeIconProvider::class,
                        'options' => array(
                                'name' => 'pencil',
-                               'additionalClasses' => 'fa-fw'
                        )
                ),
 
@@ -81,7 +74,6 @@ class IconRegistry implements \TYPO3\CMS\Core\SingletonInterface {
                        'provider' => FontawesomeIconProvider::class,
                        'options' => array(
                                'name' => 'minus-circle',
-                               'additionalClasses' => ''
                        )
                ),
        );
index c956733..7032c06 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Core\ViewHelpers;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Imaging\IconFactory;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
@@ -22,7 +23,6 @@ use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
 
 /**
  * Displays sprite icon identified by iconName key
- * @internal
  */
 class IconViewHelper extends AbstractViewHelper implements CompilableInterface {
 
@@ -34,7 +34,7 @@ class IconViewHelper extends AbstractViewHelper implements CompilableInterface {
         * @param string $overlay
         * @return string
         */
-       public function render($identifier, $size = IconFactory::SIZE_SMALL, $overlay = NULL) {
+       public function render($identifier, $size = Icon::SIZE_SMALL, $overlay = NULL) {
                return static::renderStatic(
                        array(
                                'identifier' => $identifier,
@@ -58,9 +58,9 @@ class IconViewHelper extends AbstractViewHelper implements CompilableInterface {
                $identifier = $arguments['identifier'];
                $size = $arguments['size'];
                $overlay = $arguments['overlay'];
-               /** @var IconFactory $iconApi */
-               $iconApi = GeneralUtility::makeInstance(IconFactory::class);
-               return $iconApi->getIcon($identifier, $size, $overlay)->render();
+               /** @var IconFactory $iconFactory */
+               $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
+               return $iconFactory->getIcon($identifier, $size, $overlay)->render();
        }
 
 }
index fe37456..4899f8b 100644 (file)
@@ -47,18 +47,18 @@ Use an icon
 To use an icon, you need at least the icon identifier. The default size is small which currently means an icon with 16x16px.
 The third parameter can be used to add an additional icon as overlay, which can be any registered icon.
 
-The ``IconFactory`` provides only the following constants for Icon sizes:
+The ``Icon`` class provides only the following constants for Icon sizes:
 
-* ``IconFactory::SIZE_SMALL`` which currently means 16x16 px
-* ``IconFactory::SIZE_DEFAULT`` which currently means 32x32 px
-* ``IconFactory::SIZE_LARGE`` which currently means 48x48 px
+* ``Icon::SIZE_SMALL`` which currently means 16x16 px
+* ``Icon::SIZE_DEFAULT`` which currently means 32x32 px
+* ``Icon::SIZE_LARGE`` which currently means 48x48 px
 
 All the sizes can change in future, so please make use of the constants for an unified layout.
 
 .. code-block:: php
 
-       $iconApi = GeneralUtility::makeInstance(IconFactory::class);
-       $iconApi->getIcon($identifier, IconFactory::SIZE_SMALL, $overlay)->render();
+       $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
+       $iconFactory->getIcon($identifier, Icon::SIZE_SMALL, $overlay)->render();
 
 
 ViewHelper
diff --git a/typo3/sysext/core/Tests/Unit/ViewHelpers/IconViewHelperTest.php b/typo3/sysext/core/Tests/Unit/ViewHelpers/IconViewHelperTest.php
new file mode 100644 (file)
index 0000000..5e131c0
--- /dev/null
@@ -0,0 +1,83 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\ViewHelpers;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use Prophecy\Argument;
+use TYPO3\CMS\Core\Imaging\Icon;
+use TYPO3\CMS\Core\Imaging\IconFactory;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\ViewHelpers\IconViewHelper;
+use TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase;
+
+/**
+ * Test case
+ */
+class IconViewHelperTest extends ViewHelperBaseTestcase {
+
+       /**
+        * @var IconViewHelper
+        */
+       protected $viewHelper;
+
+       protected function setUp() {
+               parent::setUp();
+               $this->viewHelper = $this->getAccessibleMock(IconViewHelper::class, array('renderChildren'));
+               $this->injectDependenciesIntoViewHelper($this->viewHelper);
+               $this->viewHelper->initializeArguments();
+       }
+
+       /**
+        * @test
+        */
+       public function renderCallsIconFactoryWithDefaultSizeAndReturnsResult() {
+               $iconFactoryProphecy = $this->prophesize(IconFactory::class);
+               GeneralUtility::addInstance(IconFactory::class, $iconFactoryProphecy->reveal());
+               $iconProphecy = $this->prophesize(Icon::class);
+
+               $iconFactoryProphecy->getIcon('myIdentifier', Icon::SIZE_SMALL, NULL)->shouldBeCalled()->willReturn($iconProphecy->reveal());
+               $iconProphecy->render()->shouldBeCalled()->willReturn('htmlFoo');
+
+               $this->assertSame('htmlFoo', $this->viewHelper->render('myIdentifier'));
+       }
+
+       /**
+        * @test
+        */
+       public function renderCallsIconFactoryWithGivenSizeAndReturnsResult() {
+               $iconFactoryProphecy = $this->prophesize(IconFactory::class);
+               GeneralUtility::addInstance(IconFactory::class, $iconFactoryProphecy->reveal());
+               $iconProphecy = $this->prophesize(Icon::class);
+
+               $iconFactoryProphecy->getIcon('myIdentifier', Icon::SIZE_LARGE, NULL)->shouldBeCalled()->willReturn($iconProphecy->reveal());
+               $iconProphecy->render()->shouldBeCalled()->willReturn('htmlFoo');
+
+               $this->assertSame('htmlFoo', $this->viewHelper->render('myIdentifier', Icon::SIZE_LARGE));
+       }
+
+       /**
+        * @test
+        */
+       public function renderCallsIconFactoryWithGivenOverlayAndReturnsResult() {
+               $iconFactoryProphecy = $this->prophesize(IconFactory::class);
+               GeneralUtility::addInstance(IconFactory::class, $iconFactoryProphecy->reveal());
+               $iconProphecy = $this->prophesize(Icon::class);
+
+               $iconFactoryProphecy->getIcon('myIdentifier', Argument::any(), 'overlayString')->shouldBeCalled()->willReturn($iconProphecy->reveal());
+               $iconProphecy->render()->shouldBeCalled()->willReturn('htmlFoo');
+
+               $this->assertSame('htmlFoo', $this->viewHelper->render('myIdentifier', Icon::SIZE_LARGE, 'overlayString'));
+       }
+
+}
\ No newline at end of file