Mwjames has uploaded a new change for review. https://gerrit.wikimedia.org/r/124798
Change subject: NS-Usage + MainContentTest ...................................................................... NS-Usage + MainContentTest - Make the NS usage a bit more PSR-2 conform [0] - Adds a simple MainContentTest [0] http://www.php-fig.org/psr/psr-2/ Change-Id: I0a11bebaf5230a48a09fde2cea0b8eaf13288f24 --- M Chameleon.php M includes/ChameleonTemplate.php R includes/Components/Cell.php R includes/Components/Component.php R includes/Components/Container.php R includes/Components/FooterIcons.php R includes/Components/FooterInfo.php R includes/Components/FooterPlaces.php R includes/Components/Grid.php R includes/Components/Html.php R includes/Components/Logo.php R includes/Components/MainContent.php R includes/Components/NavMenu.php R includes/Components/NavbarHorizontal.php R includes/Components/NewtalkNotifier.php R includes/Components/PageTools.php R includes/Components/PersonalTools.php R includes/Components/Row.php R includes/Components/SearchBar.php R includes/Components/SiteNotice.php R includes/Components/Structure.php R includes/Components/ToolbarHorizontal.php M includes/Hooks/SetupAfterCache.php M includes/IdRegistry.php M includes/SkinChameleon.php M tests/phpunit/ChameleonTemplateTest.php A tests/phpunit/Components/MainContentTest.php M tests/phpunit/Hooks/SetupAfterCacheTest.php 28 files changed, 178 insertions(+), 115 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/skins/chameleon refs/changes/98/124798/1 diff --git a/Chameleon.php b/Chameleon.php index ebc96d6..3139474 100644 --- a/Chameleon.php +++ b/Chameleon.php @@ -8,7 +8,6 @@ * @version 1.0-alpha * */ -use Bootstrap\BootstrapManager; /** * The main file of the Chameleon skin @@ -87,16 +86,14 @@ ); foreach ( $chameleonComponents as $component ) { - $GLOBALS[ 'wgAutoloadClasses' ][ 'skins\\chameleon\\components\\' . $component ] = __DIR__ . '/includes/components/' . $component . '.php'; + $GLOBALS[ 'wgAutoloadClasses' ][ 'Skins\\Chameleon\\Components\\' . $component ] = __DIR__ . '/includes/Components/' . $component . '.php'; } $GLOBALS[ 'wgAutoloadClasses' ][ 'SkinChameleon' ] = dirname( __FILE__ ) . '/includes/SkinChameleon.php'; // register skin class (must be 'Skin' . SkinName) - $GLOBALS[ 'wgAutoloadClasses' ][ 'skins\chameleon\ChameleonTemplate' ] = dirname( __FILE__ ) . '/includes/ChameleonTemplate.php'; - $GLOBALS[ 'wgAutoloadClasses' ][ 'skins\chameleon\IdRegistry' ] = dirname( __FILE__ ) . '/includes/IdRegistry.php'; - - // FIXME Ought to fix the namespace usage here - $GLOBALS[ 'wgAutoloadClasses' ][ 'skins\chameleon\hooks\SetupAfterCache' ] = __DIR__ . '/includes/Hooks/SetupAfterCache.php'; + $GLOBALS[ 'wgAutoloadClasses' ][ 'Skins\Chameleon\ChameleonTemplate' ] = dirname( __FILE__ ) . '/includes/ChameleonTemplate.php'; + $GLOBALS[ 'wgAutoloadClasses' ][ 'Skins\Chameleon\IdRegistry' ] = dirname( __FILE__ ) . '/includes/IdRegistry.php'; + $GLOBALS[ 'wgAutoloadClasses' ][ 'Skins\Chameleon\Hooks\SetupAfterCache' ] = __DIR__ . '/includes/Hooks/SetupAfterCache.php'; /** * Using callbacks for hook registration @@ -121,7 +118,7 @@ 'wgStylePath' => $GLOBALS['wgStylePath'] ); - $setupAfterCache = new \skins\chameleon\hooks\SetupAfterCache( + $setupAfterCache = new \Skins\Chameleon\Hooks\SetupAfterCache( \bootstrap\BootstrapManager::getBootstrapManager(), $configuration ); diff --git a/includes/ChameleonTemplate.php b/includes/ChameleonTemplate.php index 3105c75..fce3005 100644 --- a/includes/ChameleonTemplate.php +++ b/includes/ChameleonTemplate.php @@ -1,4 +1,12 @@ <?php + +namespace Skins\Chameleon; + +use BaseTemplate; +use DOMDocument; +use Skins\Chameleon\Components\Container; +use RuntimeException; + /** * File holding the ChameleonTemplate class * @@ -22,13 +30,6 @@ * @file * @ingroup Skins */ - -namespace skins\chameleon; - -use BaseTemplate; -use DOMDocument; -use skins\chameleon\components\Container; -use RuntimeException; /** * BaseTemplate class for the Chameleon skin @@ -91,11 +92,11 @@ * @param int $indent * @param string $htmlClassAttribute * - * @return \skins\chameleon\components\Container + * @return \Skins\Chameleon\Components\Container */ public function getComponent( \DOMElement $description, $indent = 0, $htmlClassAttribute = '' ) { - $class = 'skins\\chameleon\\components\\'; + $class = 'Skins\\Chameleon\\Components\\'; switch ( $description->nodeName ) { case 'structure': @@ -118,7 +119,7 @@ } } - if ( class_exists( $class ) && is_subclass_of( $class, 'skins\\chameleon\\components\\Component' ) ) { + if ( class_exists( $class ) && is_subclass_of( $class, 'Skins\\Chameleon\\Components\\Component' ) ) { return new $class( $this, $description, $indent, $htmlClassAttribute ); } else { return new Container( $this, $description, $indent, $htmlClassAttribute ); diff --git a/includes/components/Cell.php b/includes/Components/Cell.php similarity index 94% rename from includes/components/Cell.php rename to includes/Components/Cell.php index 6c78ed8..ec4bef0 100644 --- a/includes/components/Cell.php +++ b/includes/Components/Cell.php @@ -1,4 +1,9 @@ <?php + +namespace Skins\Chameleon\Components; + +use Skins\Chameleon\ChameleonTemplate; + /** * File holding the Cell class * @@ -22,12 +27,6 @@ * @file * @ingroup Skins */ - - -namespace skins\chameleon\components; - -use skins\chameleon\ChameleonTemplate; - /** * The Cell class. diff --git a/includes/components/Component.php b/includes/Components/Component.php similarity index 98% rename from includes/components/Component.php rename to includes/Components/Component.php index 431c14d..53fc2e2 100644 --- a/includes/components/Component.php +++ b/includes/Components/Component.php @@ -1,4 +1,9 @@ <?php + +namespace Skins\Chameleon\Components; + +use Skins\Chameleon\ChameleonTemplate; + /** * File containing the Component class * @@ -22,10 +27,6 @@ * @file * @ingroup Skins */ - -namespace skins\chameleon\components; - -use skins\chameleon\ChameleonTemplate; /** * Component class diff --git a/includes/components/Container.php b/includes/Components/Container.php similarity index 97% rename from includes/components/Container.php rename to includes/Components/Container.php index d49c0a0..93bc541 100644 --- a/includes/components/Container.php +++ b/includes/Components/Container.php @@ -1,4 +1,7 @@ <?php + +namespace Skins\Chameleon\Components; + /** * File holding the Container class * @@ -22,10 +25,6 @@ * @file * @ingroup Skins */ - - -namespace skins\chameleon\components; - /** * The Container class. diff --git a/includes/components/FooterIcons.php b/includes/Components/FooterIcons.php similarity index 97% rename from includes/components/FooterIcons.php rename to includes/Components/FooterIcons.php index fd39256..c321504 100644 --- a/includes/components/FooterIcons.php +++ b/includes/Components/FooterIcons.php @@ -1,4 +1,7 @@ <?php + +namespace Skins\Chameleon\Components; + /** * File holding the FooterIcons class * @@ -30,9 +33,6 @@ * * @ingroup Chameleon */ -namespace skins\chameleon\components; - - class FooterIcons extends Component { /** diff --git a/includes/components/FooterInfo.php b/includes/Components/FooterInfo.php similarity index 95% rename from includes/components/FooterInfo.php rename to includes/Components/FooterInfo.php index 508fa2a..d189476 100644 --- a/includes/components/FooterInfo.php +++ b/includes/Components/FooterInfo.php @@ -1,4 +1,10 @@ <?php + +namespace Skins\Chameleon\Components; + +use Skins\Chameleon\ChameleonTemplate; +use Skins\Chameleon\IdRegistry; + /** * File holding the FooterInfo class * @@ -22,11 +28,6 @@ * @file * @ingroup Chameleon */ - -namespace skins\chameleon\components; -use skins\chameleon\ChameleonTemplate; -use skins\chameleon\IdRegistry; - /** * The FooterInfo class. diff --git a/includes/components/FooterPlaces.php b/includes/Components/FooterPlaces.php similarity index 97% rename from includes/components/FooterPlaces.php rename to includes/Components/FooterPlaces.php index 216cbac..53cb6c5 100644 --- a/includes/components/FooterPlaces.php +++ b/includes/Components/FooterPlaces.php @@ -1,4 +1,7 @@ <?php + +namespace Skins\Chameleon\Components; + /** * File holding the FooterPlaces class * @@ -22,9 +25,6 @@ * @file * @ingroup Skins */ - -namespace skins\chameleon\components; - /** * The FooterInfo class. diff --git a/includes/components/Grid.php b/includes/Components/Grid.php similarity index 93% rename from includes/components/Grid.php rename to includes/Components/Grid.php index 306a558..ceaa624 100644 --- a/includes/components/Grid.php +++ b/includes/Components/Grid.php @@ -1,4 +1,9 @@ <?php + +namespace Skins\Chameleon\Components; + +use Skins\Chameleon\ChameleonTemplate; + /** * File holding the Grid class * @@ -22,12 +27,6 @@ * @file * @ingroup Skins */ - - -namespace skins\chameleon\components; - -use skins\chameleon\ChameleonTemplate; - /** * The Grid class. diff --git a/includes/components/Html.php b/includes/Components/Html.php similarity index 97% rename from includes/components/Html.php rename to includes/Components/Html.php index e2a3227..cecf91f 100644 --- a/includes/components/Html.php +++ b/includes/Components/Html.php @@ -1,4 +1,7 @@ <?php + +namespace Skins\Chameleon\Components; + /** * File holding the Html class * @@ -22,10 +25,6 @@ * @file * @ingroup Skins */ - - -namespace skins\chameleon\components; - /** * The Html class. diff --git a/includes/components/Logo.php b/includes/Components/Logo.php similarity index 96% rename from includes/components/Logo.php rename to includes/Components/Logo.php index 0704304..c1d369e 100644 --- a/includes/components/Logo.php +++ b/includes/Components/Logo.php @@ -1,4 +1,10 @@ <?php + +namespace Skins\Chameleon\Components; + +use Linker; +use Skins\Chameleon\IdRegistry; + /** * File holding the Logo class * @@ -22,11 +28,6 @@ * @file * @ingroup Skins */ - -namespace skins\chameleon\components; - -use Linker; -use skins\chameleon\IdRegistry; /** * The Logo class. diff --git a/includes/components/MainContent.php b/includes/Components/MainContent.php similarity index 98% rename from includes/components/MainContent.php rename to includes/Components/MainContent.php index a0060ba..de3dcb7 100644 --- a/includes/components/MainContent.php +++ b/includes/Components/MainContent.php @@ -1,4 +1,9 @@ <?php + +namespace Skins\Chameleon\Components; + +use Skins\Chameleon\IdRegistry; + /** * File holding the MainContent class * @@ -22,9 +27,6 @@ * @file * @ingroup Skins */ - -namespace skins\chameleon\components; -use skins\chameleon\IdRegistry; /** * The NavbarHorizontal class. diff --git a/includes/components/NavMenu.php b/includes/Components/NavMenu.php similarity index 98% rename from includes/components/NavMenu.php rename to includes/Components/NavMenu.php index 2a10995..f247c21 100644 --- a/includes/components/NavMenu.php +++ b/includes/Components/NavMenu.php @@ -1,4 +1,10 @@ <?php + +namespace Skins\Chameleon\Components; + +use Linker; +use Skins\Chameleon\IdRegistry; + /** * File holding the NavMenu class * @@ -22,11 +28,6 @@ * @file * @ingroup Skins */ - -namespace skins\chameleon\components; - -use Linker; -use skins\chameleon\IdRegistry; /** * The NavMenu class. diff --git a/includes/components/NavbarHorizontal.php b/includes/Components/NavbarHorizontal.php similarity index 98% rename from includes/components/NavbarHorizontal.php rename to includes/Components/NavbarHorizontal.php index 556915e..fc23966 100644 --- a/includes/components/NavbarHorizontal.php +++ b/includes/Components/NavbarHorizontal.php @@ -1,4 +1,10 @@ <?php + +namespace Skins\Chameleon\Components; + +use Linker; +use Skins\Chameleon\IdRegistry; + /** * File holding the NavbarHorizontal class * @@ -22,11 +28,6 @@ * @file * @ingroup Skins */ - -namespace skins\chameleon\components; - -use Linker; -use skins\chameleon\IdRegistry; /** * The NavbarHorizontal class. diff --git a/includes/components/NewtalkNotifier.php b/includes/Components/NewtalkNotifier.php similarity index 97% rename from includes/components/NewtalkNotifier.php rename to includes/Components/NewtalkNotifier.php index 59989f0..aa1d569 100644 --- a/includes/components/NewtalkNotifier.php +++ b/includes/Components/NewtalkNotifier.php @@ -1,4 +1,7 @@ <?php + +namespace Skins\Chameleon\Components; + /** * File holding the NewtalkNotifier class * @@ -22,8 +25,6 @@ * @file * @ingroup Skins */ - -namespace skins\chameleon\components; /** * The NewtalkNotifier class. diff --git a/includes/components/PageTools.php b/includes/Components/PageTools.php similarity index 97% rename from includes/components/PageTools.php rename to includes/Components/PageTools.php index cf7b6aa..1d4bd5d 100644 --- a/includes/components/PageTools.php +++ b/includes/Components/PageTools.php @@ -1,4 +1,11 @@ <?php + +namespace Skins\Chameleon\Components; + +use MWNamespace; +use Skins\Chameleon\ChameleonTemplate; +use Skins\Chameleon\IdRegistry; + /** * File holding the PageTools class * @@ -22,12 +29,6 @@ * @file * @ingroup Skins */ - -namespace skins\chameleon\components; - -use MWNamespace; -use skins\chameleon\ChameleonTemplate; -use skins\chameleon\IdRegistry; /** * The PageTools class. diff --git a/includes/components/PersonalTools.php b/includes/Components/PersonalTools.php similarity index 98% rename from includes/components/PersonalTools.php rename to includes/Components/PersonalTools.php index ef5a847..cee8d46 100644 --- a/includes/components/PersonalTools.php +++ b/includes/Components/PersonalTools.php @@ -1,4 +1,7 @@ <?php + +namespace Skins\Chameleon\Components; + /** * File holding the PersonalTools class * @@ -22,8 +25,6 @@ * @file * @ingroup Skins */ - -namespace skins\chameleon\components; /** * The PersonalTools class. diff --git a/includes/components/Row.php b/includes/Components/Row.php similarity index 93% rename from includes/components/Row.php rename to includes/Components/Row.php index 1d2aa31..e8c00e6 100644 --- a/includes/components/Row.php +++ b/includes/Components/Row.php @@ -1,4 +1,9 @@ <?php + +namespace Skins\Chameleon\Components; + +use Skins\Chameleon\ChameleonTemplate; + /** * File holding the Row class * @@ -22,12 +27,6 @@ * @file * @ingroup Skins */ - - -namespace skins\chameleon\components; - -use skins\chameleon\ChameleonTemplate; - /** * The Row class. diff --git a/includes/components/SearchBar.php b/includes/Components/SearchBar.php similarity index 97% rename from includes/components/SearchBar.php rename to includes/Components/SearchBar.php index 60b12ef..1cd80a9 100644 --- a/includes/components/SearchBar.php +++ b/includes/Components/SearchBar.php @@ -1,4 +1,10 @@ <?php + +namespace Skins\Chameleon\Components; + +use \Linker; +use Skins\Chameleon\IdRegistry; + /** * File holding the SearchBar class * @@ -22,11 +28,6 @@ * @file * @ingroup Skins */ - -namespace skins\chameleon\components; - -use \Linker; -use skins\chameleon\IdRegistry; /** * The SearchBar class. diff --git a/includes/components/SiteNotice.php b/includes/Components/SiteNotice.php similarity index 97% rename from includes/components/SiteNotice.php rename to includes/Components/SiteNotice.php index dc5b3dd..48ad51d 100644 --- a/includes/components/SiteNotice.php +++ b/includes/Components/SiteNotice.php @@ -1,4 +1,7 @@ <?php + +namespace Skins\Chameleon\Components; + /** * File holding the SiteNotice class * @@ -22,8 +25,6 @@ * @file * @ingroup Skins */ - -namespace skins\chameleon\components; /** * The SiteNotice class. diff --git a/includes/components/Structure.php b/includes/Components/Structure.php similarity index 97% rename from includes/components/Structure.php rename to includes/Components/Structure.php index 7543fe3..c2e53f5 100644 --- a/includes/components/Structure.php +++ b/includes/Components/Structure.php @@ -1,4 +1,7 @@ <?php + +namespace Skins\Chameleon\Components; + /** * File holding the Structure class * @@ -22,10 +25,6 @@ * @file * @ingroup Skins */ - - -namespace skins\chameleon\components; - /** * The Structure class. diff --git a/includes/components/ToolbarHorizontal.php b/includes/Components/ToolbarHorizontal.php similarity index 98% rename from includes/components/ToolbarHorizontal.php rename to includes/Components/ToolbarHorizontal.php index d88e352..ca48801 100644 --- a/includes/components/ToolbarHorizontal.php +++ b/includes/Components/ToolbarHorizontal.php @@ -1,4 +1,9 @@ <?php + +namespace Skins\Chameleon\Components; + +use Linker; + /** * File containing the ToolbarHorizontal class * @@ -22,10 +27,6 @@ * @file * @ingroup Skins */ - -namespace skins\chameleon\components; - -use Linker; /** * ToolbarHorizontal class diff --git a/includes/Hooks/SetupAfterCache.php b/includes/Hooks/SetupAfterCache.php index f53065b..64c6024 100644 --- a/includes/Hooks/SetupAfterCache.php +++ b/includes/Hooks/SetupAfterCache.php @@ -1,6 +1,6 @@ <?php -namespace skins\chameleon\hooks; +namespace Skins\Chameleon\Hooks; use bootstrap\BootstrapManager; use RuntimeException; diff --git a/includes/IdRegistry.php b/includes/IdRegistry.php index 5870a64..355c48b 100644 --- a/includes/IdRegistry.php +++ b/includes/IdRegistry.php @@ -1,4 +1,7 @@ <?php + +namespace Skins\Chameleon; + /** * File holding the IdRegistry class * @@ -23,13 +26,10 @@ * @ingroup Skins */ - -namespace skins\chameleon; - /** * Class IdRegistry provides a registry and access methods to ensure each id is only used once per HTML page. * - * @package skins\chameleon + * @package Skins\Chameleon */ class IdRegistry { diff --git a/includes/SkinChameleon.php b/includes/SkinChameleon.php index d09eaf7..0157cec 100644 --- a/includes/SkinChameleon.php +++ b/includes/SkinChameleon.php @@ -33,7 +33,7 @@ var $skinname = 'chameleon'; var $stylename = 'chameleon'; - var $template = '\skins\chameleon\ChameleonTemplate'; + var $template = '\Skins\Chameleon\ChameleonTemplate'; var $useHeadElement = true; /** diff --git a/tests/phpunit/ChameleonTemplateTest.php b/tests/phpunit/ChameleonTemplateTest.php index af337e5..1f810f3 100644 --- a/tests/phpunit/ChameleonTemplateTest.php +++ b/tests/phpunit/ChameleonTemplateTest.php @@ -2,7 +2,7 @@ namespace Skins\Tests\Chameleon; -use skins\chameleon\ChameleonTemplate; +use Skins\Chameleon\ChameleonTemplate; /** * @covers \Skins\Chameleon\ChameleonTemplate @@ -12,7 +12,7 @@ * @group skins-chameleon * @group mediawiki-databaseless * - * @licence GNU GPL v2+ + * @licence GNU GPL v3+ * @since 1.0 * * @author mwjames diff --git a/tests/phpunit/Components/MainContentTest.php b/tests/phpunit/Components/MainContentTest.php new file mode 100644 index 0000000..2365208 --- /dev/null +++ b/tests/phpunit/Components/MainContentTest.php @@ -0,0 +1,59 @@ +<?php + +namespace skins\tests\chameleon\Components; + +use Skins\Chameleon\Components\MainContent; + +/** + * @covers \Skins\Chameleon\Components\MainContent + * + * @ingroup Test + * + * @group skins-chameleon + * @group mediawiki-databaseless + * + * @licence GNU GPL v3+ + * @since 1.0 + * + * @author mwjames + */ +class MainContentTest extends \PHPUnit_Framework_TestCase { + + public function testCanConstruct() { + + $chameleonTemplate = $this->getMockBuilder( '\Skins\Chameleon\ChameleonTemplate' ) + ->disableOriginalConstructor() + ->getMock(); + + $this->assertInstanceOf( + '\Skins\Chameleon\Components\MainContent', + new MainContent( $chameleonTemplate ) + ); + } + + public function testGetHtmlOnEmptyDataProperty() { + + $message = $this->getMockBuilder( '\Message' ) + ->disableOriginalConstructor() + ->getMock(); + + $chameleonTemplate = $this->getMockBuilder( '\Skins\Chameleon\ChameleonTemplate' ) + ->disableOriginalConstructor() + ->getMock(); + + $chameleonTemplate->expects( $this->atLeastOnce() ) + ->method( 'getMsg' ) + ->will( $this->returnValue( $message ) ); + + $chameleonTemplate->data = array( + 'subtitle' => '', + 'undelete' => '', + 'printfooter' => '', + 'dataAfterContent' => '' + ); + + $instance = new MainContent( $chameleonTemplate ); + $this->assertInternalType( 'string', $instance->getHtml() ); + } + +} diff --git a/tests/phpunit/Hooks/SetupAfterCacheTest.php b/tests/phpunit/Hooks/SetupAfterCacheTest.php index d55d60e..b60159d 100644 --- a/tests/phpunit/Hooks/SetupAfterCacheTest.php +++ b/tests/phpunit/Hooks/SetupAfterCacheTest.php @@ -1,11 +1,11 @@ <?php -namespace skins\tests\chameleon\hooks; +namespace Skins\Tests\Chameleon\Hooks; -use skins\chameleon\hooks\SetupAfterCache; +use Skins\Chameleon\Hooks\SetupAfterCache; /** - * @covers \skins\chameleon\hooks\SetupAfterCache + * @covers \Skins\Chameleon\Hooks\SetupAfterCache * * @ingroup Test * @@ -28,7 +28,7 @@ $configuration = array(); $this->assertInstanceOf( - '\skins\chameleon\hooks\SetupAfterCache', + '\Skins\Chameleon\Hooks\SetupAfterCache', new SetupAfterCache( $bootstrapManager, $configuration ) ); } @@ -139,6 +139,5 @@ $instance->process(); } - } -- To view, visit https://gerrit.wikimedia.org/r/124798 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0a11bebaf5230a48a09fde2cea0b8eaf13288f24 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/skins/chameleon Gerrit-Branch: master Gerrit-Owner: Mwjames <jamesin.hongkon...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits