summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Integration/JSONScript/ApiTestCaseProcessor.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Integration/JSONScript/ApiTestCaseProcessor.php')
-rw-r--r--www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Integration/JSONScript/ApiTestCaseProcessor.php122
1 files changed, 122 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Integration/JSONScript/ApiTestCaseProcessor.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Integration/JSONScript/ApiTestCaseProcessor.php
new file mode 100644
index 00000000..6ecc4c7c
--- /dev/null
+++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Integration/JSONScript/ApiTestCaseProcessor.php
@@ -0,0 +1,122 @@
+<?php
+
+namespace SMW\Tests\Integration\JSONScript;
+
+use SMW\Tests\Utils\File\ContentsReader;
+
+/**
+ * @group semantic-mediawiki
+ * @group medium
+ *
+ * @license GNU GPL v2+
+ * @since 3.0
+ *
+ * @author mwjames
+ */
+class ApiTestCaseProcessor extends \PHPUnit_Framework_TestCase {
+
+ /**
+ * @var MwApiFactory
+ */
+ private $mwApiFactory;
+
+ /**
+ * @var StringValidator
+ */
+ private $stringValidator;
+
+ /**
+ * @var boolean
+ */
+ private $debug = false;
+
+ /**
+ * @param MwApiFactory mwApiFactory
+ * @param StringValidator
+ */
+ public function __construct( $mwApiFactory, $stringValidator ) {
+ $this->mwApiFactory = $mwApiFactory;
+ $this->stringValidator = $stringValidator;
+ }
+
+ /**
+ * @since 3.0
+ */
+ public function setDebugMode( $debugMode ) {
+ $this->debug = $debugMode;
+ }
+
+ /**
+ * @since 3.0
+ *
+ * @param string $testCaseLocation
+ */
+ public function setTestCaseLocation( $testCaseLocation ) {
+ $this->testCaseLocation = $testCaseLocation;
+ }
+
+ /**
+ * @since 3.0
+ *
+ * @param array $case
+ */
+ public function process( array $case ) {
+
+ if ( !isset( $case['api'] ) ) {
+ return;
+ }
+
+ $parameters = [];
+
+ if ( isset( $case['api']['parameters'] ) ) {
+ $parameters = $case['api']['parameters'];
+ }
+
+ $res = $this->mwApiFactory->doApiRequest(
+ $parameters
+ );
+
+ $this->assertOutputForCase( $case, json_encode( $res ) );
+ }
+
+ private function assertOutputForCase( $case, $text ) {
+
+ // Avoid issue with \r carriage return and \n new line
+ $text = str_replace( "\r\n", "\n", $text );
+
+ if ( isset( $case['assert-output']['to-contain'] ) ) {
+
+ if ( isset( $case['assert-output']['to-contain']['contents-file'] ) ) {
+ $contents = ContentsReader::readContentsFrom(
+ $this->testCaseLocation . $case['assert-output']['to-contain']['contents-file']
+ );
+ } else {
+ $contents = $case['assert-output']['to-contain'];
+ }
+
+ $this->stringValidator->assertThatStringContains(
+ $contents,
+ $text,
+ $case['about']
+ );
+ }
+
+ if ( isset( $case['assert-output']['not-contain'] ) ) {
+
+ if ( isset( $case['assert-output']['not-contain']['contents-file'] ) ) {
+ $contents = ContentsReader::readContentsFrom(
+ $this->testCaseLocation . $case['assert-output']['not-contain']['contents-file']
+ );
+ } else {
+ $contents = $case['assert-output']['not-contain'];
+ }
+
+ $this->stringValidator->assertThatStringNotContains(
+ $contents,
+ $text,
+ $case['about']
+ );
+ }
+ }
+
+}