jenkins-bot has submitted this change and it was merged.
Change subject: Tests for the Handlebars form renderer
......................................................................
Tests for the Handlebars form renderer
Bug: T95951
Change-Id: Id29150335a68442bab0ef4782458cde82414c231
---
M gateway_forms/Handlebars.php
A tests/HandlebarsFormTest.php
A tests/data/handlebars/currency.handlebars
A tests/data/handlebars/empty.handlebars
A tests/data/handlebars/foo.handlebars
5 files changed, 78 insertions(+), 1 deletion(-)
Approvals:
Ssmith: Looks good to me, approved
jenkins-bot: Verified
diff --git a/gateway_forms/Handlebars.php b/gateway_forms/Handlebars.php
index f984889..b59ae18 100644
--- a/gateway_forms/Handlebars.php
+++ b/gateway_forms/Handlebars.php
@@ -31,7 +31,7 @@
$data = $this->gateway->getData_Unstaged_Escaped();
$template = file_get_contents( $this->topLevelForm );
- if ( !$template ) {
+ if ( $template === false ) {
throw new Exception( "Template file unavailable:
[{$this->topLevelForm}]" );
}
diff --git a/tests/HandlebarsFormTest.php b/tests/HandlebarsFormTest.php
new file mode 100644
index 0000000..768a765
--- /dev/null
+++ b/tests/HandlebarsFormTest.php
@@ -0,0 +1,75 @@
+<?php
+/**
+ * Wikimedia Foundation
+ *
+ * LICENSE
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+/**
+ * @group Fundraising
+ * @group DonationInterface
+ * @group GatewayPage
+ */
+class HandlebarsFormTest extends DonationInterfaceTestCase {
+ protected $form;
+ protected $adapter;
+
+ public function setUp() {
+ $this->adapter = new TestingGenericAdapter();
+ $this->adapter->addRequestData( array(
+ 'amount' => '12',
+ 'currency_code' => 'EUR'
+ ) );
+
+ parent::setUp();
+ }
+
+ public function formCases() {
+ return array(
+ array( 'empty', '/^$/' ),
+ array( 'foo', '/FOO/' ),
+ array( 'currency', '/EUR/' ),
+ );
+ }
+
+ /**
+ * Render a few simple handlebars files and match the output
+ *
+ * @dataProvider formCases
+ */
+ public function testRendering( $name, $regexp ) {
+ $this->setMwGlobals( array(
+ 'wgDonationInterfaceTemplate' => __DIR__ .
"/data/handlebars/{$name}.handlebars",
+ ) );
+ $this->form = new Gateway_Form_Handlebars( $this->adapter );
+ $html = $this->form->getForm();
+
+ $this->assertRegExp( $regexp, $html );
+ }
+
+ /**
+ * @expectedException Exception
+ * @expectedExceptionMessage Template file unavailable
+ */
+ public function testNoTemplateFile() {
+ $this->setMwGlobals( array(
+ 'wgDonationInterfaceTemplate' => __DIR__ .
"/data/handlebars/DONOTCREATE.handlebars",
+ ) );
+ $this->form = new Gateway_Form_Handlebars( $this->adapter );
+ // Suppress the error cos: we know.
+ $html = @$this->form->getForm();
+
+ $this->fail( 'I\'m not dead yet!' );
+ }
+}
diff --git a/tests/data/handlebars/currency.handlebars
b/tests/data/handlebars/currency.handlebars
new file mode 100644
index 0000000..cb58a8a
--- /dev/null
+++ b/tests/data/handlebars/currency.handlebars
@@ -0,0 +1 @@
+{{ currency_code }}
diff --git a/tests/data/handlebars/empty.handlebars
b/tests/data/handlebars/empty.handlebars
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/data/handlebars/empty.handlebars
diff --git a/tests/data/handlebars/foo.handlebars
b/tests/data/handlebars/foo.handlebars
new file mode 100644
index 0000000..b7d6715
--- /dev/null
+++ b/tests/data/handlebars/foo.handlebars
@@ -0,0 +1 @@
+FOO
--
To view, visit https://gerrit.wikimedia.org/r/204011
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id29150335a68442bab0ef4782458cde82414c231
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Awight <[email protected]>
Gerrit-Reviewer: AndyRussG <[email protected]>
Gerrit-Reviewer: Awight <[email protected]>
Gerrit-Reviewer: Ejegg <[email protected]>
Gerrit-Reviewer: Katie Horn <[email protected]>
Gerrit-Reviewer: Ssmith <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits