Foxtrott has submitted this change and it was merged.
Change subject: Throw exception for inaccessible layoutfile
......................................................................
Throw exception for inaccessible layoutfile
Change-Id: I9f068576b25f6d95874cb3446981445fa43bd82f
---
M includes/ChameleonTemplate.php
A phpunit.xml.dist
A tests/phpunit/ChameleonTemplateTest.php
3 files changed, 92 insertions(+), 3 deletions(-)
Approvals:
Foxtrott: Verified; Looks good to me, approved
diff --git a/includes/ChameleonTemplate.php b/includes/ChameleonTemplate.php
index 994ff46..3105c75 100644
--- a/includes/ChameleonTemplate.php
+++ b/includes/ChameleonTemplate.php
@@ -28,6 +28,7 @@
use BaseTemplate;
use DOMDocument;
use skins\chameleon\components\Container;
+use RuntimeException;
/**
* BaseTemplate class for the Chameleon skin
@@ -60,13 +61,11 @@
protected function getRootComponent() {
- global $egChameleonLayoutFile;
-
if ( $this->mRootComponent === null ) {
$doc = new DOMDocument();
- $doc->load( $egChameleonLayoutFile ); //TODO: error
handling (file not found, file empty)
+ $doc->load( $this->getLayoutFile() );
$doc->normalizeDocument();
@@ -153,4 +152,16 @@
return parent::makeListItem( $key, $item, $options );
}
+
+ protected function getLayoutFile() {
+
+ $file = str_replace( array( '\\', '/' ), DIRECTORY_SEPARATOR,
$GLOBALS['egChameleonLayoutFile'] );
+
+ if ( is_readable( $file ) ) {
+ return $file;
+ }
+
+ throw new RuntimeException( "Expected an accessible {$file}
layout file" );
+ }
+
}
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
new file mode 100644
index 0000000..ad69662
--- /dev/null
+++ b/phpunit.xml.dist
@@ -0,0 +1,24 @@
+<phpunit backupGlobals="false"
+ backupStaticAttributes="false"
+ cacheTokens="false"
+ colors="true"
+ convertErrorsToExceptions="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ stopOnError="false"
+ stopOnFailure="false"
+ stopOnIncomplete="false"
+ stopOnSkipped="false"
+ strict="true"
+ verbose="true">
+ <testsuites>
+ <testsuite name="skins-chameleon">
+ <directory>tests/phpunit</directory>
+ </testsuite>
+ </testsuites>
+ <filter>
+ <whitelist addUncoveredFilesFromWhitelist="true">
+ <directory suffix=".php">includes</directory>
+ </whitelist>
+ </filter>
+</phpunit>
diff --git a/tests/phpunit/ChameleonTemplateTest.php
b/tests/phpunit/ChameleonTemplateTest.php
new file mode 100644
index 0000000..af337e5
--- /dev/null
+++ b/tests/phpunit/ChameleonTemplateTest.php
@@ -0,0 +1,54 @@
+<?php
+
+namespace Skins\Tests\Chameleon;
+
+use skins\chameleon\ChameleonTemplate;
+
+/**
+ * @covers \Skins\Chameleon\ChameleonTemplate
+ *
+ * @ingroup Test
+ *
+ * @group skins-chameleon
+ * @group mediawiki-databaseless
+ *
+ * @licence GNU GPL v2+
+ * @since 1.0
+ *
+ * @author mwjames
+ */
+class ChameleonTemplateTest extends \PHPUnit_Framework_TestCase {
+
+ // This is to ensure that the original value is cached since we are
unable
+ // to inject the setting during testing
+ protected $egChameleonLayoutFile = null;
+
+ protected function setUp() {
+ $this->egChameleonLayoutFile =
$GLOBALS['egChameleonLayoutFile'];
+ parent::setUp();
+ }
+
+ protected function tearDown() {
+ parent::tearDown();
+ $GLOBALS['egChameleonLayoutFile'] =
$this->egChameleonLayoutFile;
+ }
+
+ public function testCanConstruct() {
+
+ $this->assertInstanceOf(
+ '\Skins\Chameleon\ChameleonTemplate',
+ new ChameleonTemplate()
+ );
+ }
+
+ public function testInaccessibleLayoutFileThrowsExeception() {
+
+ $this->setExpectedException( 'RuntimeException' );
+
+ $GLOBALS['egChameleonLayoutFile'] = 'setInaccessibleLayoutFile';
+
+ $instance = new ChameleonTemplate;
+ $instance->execute();
+ }
+
+}
--
To view, visit https://gerrit.wikimedia.org/r/124496
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I9f068576b25f6d95874cb3446981445fa43bd82f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/skins/chameleon
Gerrit-Branch: master
Gerrit-Owner: Mwjames <[email protected]>
Gerrit-Reviewer: Foxtrott <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits