summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Utils/SemanticDataFactory.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Utils/SemanticDataFactory.php')
-rw-r--r--www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Utils/SemanticDataFactory.php79
1 files changed, 79 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Utils/SemanticDataFactory.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Utils/SemanticDataFactory.php
new file mode 100644
index 00000000..2b7d620b
--- /dev/null
+++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Utils/SemanticDataFactory.php
@@ -0,0 +1,79 @@
+<?php
+
+namespace SMW\Tests\Utils;
+
+use RuntimeException;
+use SMW\DIWikiPage;
+use SMW\SemanticData;
+use Title;
+
+/**
+ * @license GNU GPL v2+
+ * @since 2.0
+ *
+ * @author mwjames
+ */
+class SemanticDataFactory {
+
+ private $subject = null;
+
+ /**
+ * @since 2.0
+ *
+ * @param Title|string $title
+ */
+ public function setTitle( $title ) {
+
+ if ( is_string( $title ) ) {
+ $title = Title::newFromText( $title );
+ }
+
+ if ( $title instanceof Title ) {
+ return $this->setSubject( DIWikiPage::newFromTitle( $title ) );
+ }
+
+ throw new RuntimeException( "Something went wrong" );
+ }
+
+ /**
+ * @since 2.0
+ *
+ * @param DIWikiPage $subject
+ */
+ public function setSubject( DIWikiPage $subject ) {
+ $this->subject = $subject;
+ return $this;
+ }
+
+ /**
+ * @since 2.0
+ *
+ * @param string $title
+ *
+ * @return SemanticData
+ * @throws RuntimeException
+ */
+ public function newEmptySemanticData( $title = null ) {
+
+ if ( $title instanceof DIWikiPage ) {
+ $this->setSubject( $title );
+ } elseif ( $title !== null ) {
+ $this->setTitle( $title );
+ }
+
+ if ( $this->subject !== null ) {
+ return new SemanticData( $this->subject );
+ }
+
+ throw new RuntimeException( "Something went wrong" );
+ }
+
+ /**
+ * @since 2.0
+ */
+ public function null() {
+ $this->subject = null;
+ return this;
+ }
+
+}