[MediaWiki-commits] [Gerrit] mediawiki...BlueSpiceFoundation[REL1_27]: ApiUnitTests: Added simplified fixtures for users

2017-06-09 Thread Mglaser (Code Review)
Mglaser has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/358013 )

Change subject: ApiUnitTests: Added simplified fixtures for users
..


ApiUnitTests: Added simplified fixtures for users

... and pages

This should ease development of tests that require more than
one page and three users (as it is default in ApiTestCase).

Change-Id: I5af8587aac6b5f6f402b1b73203cedf24041aa03
---
M extension.json
M tests/BSApiExtJSStoreTestBase.php
M tests/BSApiTasksTestBase.php
A tests/BSApiTestCase.php
A tests/BSFixturesProvider.php
A tests/BSFixturesTest.php
A tests/BSPageFixtures.php
M tests/BSPageFixturesProvider.php
A tests/BSUserFixtures.php
A tests/BSUserFixturesProvider.php
A tests/data/users.json
11 files changed, 178 insertions(+), 4 deletions(-)

Approvals:
  Mglaser: Verified; Looks good to me, approved



diff --git a/extension.json b/extension.json
index 4f560ba..c8325da 100644
--- a/extension.json
+++ b/extension.json
@@ -562,7 +562,12 @@
"BSEntityConfig": "includes/entityconfigs/EntityConfig.php",
"BSEntityContent": "includes/content/EntityContent.php",
"BSEntityContentHandler": 
"includes/content/EntityContentHandler.php",
+   "BSApiTestCase": "tests/BSApiTestCase.php",
+   "BSFixturesProvider": "tests/BSFixturesProvider.php",
"BSPageFixturesProvider": "tests/BSPageFixturesProvider.php",
+   "BSUserFixturesProvider": "tests/BSUserFixturesProvider.php",
+   "BSPageFixtures": "tests/BSPageFixtures.php",
+   "BSUserFixtures": "tests/BSUserFixtures.php",
"BSApiExtJSStoreTestBase": "tests/BSApiExtJSStoreTestBase.php",
"BSApiTasksTestBase": "tests/BSApiTasksTestBase.php",
"BSTemplateHelper": "includes/TemplateHelper.php",
diff --git a/tests/BSApiExtJSStoreTestBase.php 
b/tests/BSApiExtJSStoreTestBase.php
index e4627a8..a9dfb84 100644
--- a/tests/BSApiExtJSStoreTestBase.php
+++ b/tests/BSApiExtJSStoreTestBase.php
@@ -4,7 +4,7 @@
  *
  * Class BSApiExtJSStoreTestBase
  */
-abstract class BSApiExtJSStoreTestBase extends ApiTestCase {
+abstract class BSApiExtJSStoreTestBase extends BSApiTestCase {
 
protected $iFixtureTotal = 0;
protected $sQuery = '';
diff --git a/tests/BSApiTasksTestBase.php b/tests/BSApiTasksTestBase.php
index 63fdb60..90f4b62 100644
--- a/tests/BSApiTasksTestBase.php
+++ b/tests/BSApiTasksTestBase.php
@@ -1,6 +1,6 @@
 makeTestUsers();
+   }
+   }
+
+   /**
+* Making this public so we cam make use of it from within a "*Fixtures"
+* class
+* @param string $pageName
+* @param string $text
+*/
+   public function insertPage($pageName, $text = 'Sample page for unit 
test.') {
+   return parent::insertPage($pageName, $text);
+   }
+}
+
diff --git a/tests/BSFixturesProvider.php b/tests/BSFixturesProvider.php
new file mode 100644
index 000..2d89afc
--- /dev/null
+++ b/tests/BSFixturesProvider.php
@@ -0,0 +1,8 @@
+assertTrue( $title->exists(), 'Title should be known' );
+   }
+
+   public function testUserFixtures() {
+   $user = User::newFromName( 'Paul' );
+   $this->assertFalse( $user->isAnon(), "User should be known" );
+
+
+   $groups = $user->getGroups();
+
+   $this->assertTrue( in_array( 'A', $groups ), 'User should be in 
group A' );
+   $this->assertFalse( in_array( 'B', $groups ), 'User should not 
be in group B' );
+   $this->assertTrue( in_array( 'C', $groups ), 'User should be in 
group C' );
+   }
+}
\ No newline at end of file
diff --git a/tests/BSPageFixtures.php b/tests/BSPageFixtures.php
new file mode 100644
index 000..50c6a4b
--- /dev/null
+++ b/tests/BSPageFixtures.php
@@ -0,0 +1,20 @@
+getFixtureData() as $pageData ) {
+   $testcase->insertPage( $pageData[0], $pageData[1] );
+   }
+   }
+}
\ No newline at end of file
diff --git a/tests/BSPageFixturesProvider.php b/tests/BSPageFixturesProvider.php
index 9779a75..5406143 100644
--- a/tests/BSPageFixturesProvider.php
+++ b/tests/BSPageFixturesProvider.php
@@ -1,12 +1,12 @@
 pages;
}
 }
\ No newline at end of file
diff --git a/tests/BSUserFixtures.php b/tests/BSUserFixtures.php
new file mode 100644
index 000..f998d51
--- /dev/null
+++ b/tests/BSUserFixtures.php
@@ -0,0 +1,51 @@
+setUserFixture( $this );
+
+   //Read in only once!
+   $this->fixtureData = $provider->getFixtureData();
+   }
+
+   /**
+*
+* @return \TestUser[]
+*/
+   public function makeTestUsers() {
+   $users = [];
+   foreach( $this->fixtureData as $userData ) {
+   $user = new TestUser(
+   $userData[0], $userData[1], $userData[2], 

[MediaWiki-commits] [Gerrit] mediawiki...BlueSpiceFoundation[REL1_27]: ApiUnitTests: Added simplified fixtures for users

2017-06-09 Thread Mglaser (Code Review)
Mglaser has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/358013 )

Change subject: ApiUnitTests: Added simplified fixtures for users
..

ApiUnitTests: Added simplified fixtures for users

... and pages

This should ease development of tests that require more than
one page and three users (as it is default in ApiTestCase).

Change-Id: I5af8587aac6b5f6f402b1b73203cedf24041aa03
---
M extension.json
M tests/BSApiExtJSStoreTestBase.php
M tests/BSApiTasksTestBase.php
A tests/BSApiTestCase.php
A tests/BSFixturesProvider.php
A tests/BSFixturesTest.php
A tests/BSPageFixtures.php
M tests/BSPageFixturesProvider.php
A tests/BSUserFixtures.php
A tests/BSUserFixturesProvider.php
A tests/data/users.json
11 files changed, 178 insertions(+), 4 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceFoundation 
refs/changes/13/358013/1

diff --git a/extension.json b/extension.json
index 4f560ba..c8325da 100644
--- a/extension.json
+++ b/extension.json
@@ -562,7 +562,12 @@
"BSEntityConfig": "includes/entityconfigs/EntityConfig.php",
"BSEntityContent": "includes/content/EntityContent.php",
"BSEntityContentHandler": 
"includes/content/EntityContentHandler.php",
+   "BSApiTestCase": "tests/BSApiTestCase.php",
+   "BSFixturesProvider": "tests/BSFixturesProvider.php",
"BSPageFixturesProvider": "tests/BSPageFixturesProvider.php",
+   "BSUserFixturesProvider": "tests/BSUserFixturesProvider.php",
+   "BSPageFixtures": "tests/BSPageFixtures.php",
+   "BSUserFixtures": "tests/BSUserFixtures.php",
"BSApiExtJSStoreTestBase": "tests/BSApiExtJSStoreTestBase.php",
"BSApiTasksTestBase": "tests/BSApiTasksTestBase.php",
"BSTemplateHelper": "includes/TemplateHelper.php",
diff --git a/tests/BSApiExtJSStoreTestBase.php 
b/tests/BSApiExtJSStoreTestBase.php
index e4627a8..a9dfb84 100644
--- a/tests/BSApiExtJSStoreTestBase.php
+++ b/tests/BSApiExtJSStoreTestBase.php
@@ -4,7 +4,7 @@
  *
  * Class BSApiExtJSStoreTestBase
  */
-abstract class BSApiExtJSStoreTestBase extends ApiTestCase {
+abstract class BSApiExtJSStoreTestBase extends BSApiTestCase {
 
protected $iFixtureTotal = 0;
protected $sQuery = '';
diff --git a/tests/BSApiTasksTestBase.php b/tests/BSApiTasksTestBase.php
index 63fdb60..90f4b62 100644
--- a/tests/BSApiTasksTestBase.php
+++ b/tests/BSApiTasksTestBase.php
@@ -1,6 +1,6 @@
 makeTestUsers();
+   }
+   }
+
+   /**
+* Making this public so we cam make use of it from within a "*Fixtures"
+* class
+* @param string $pageName
+* @param string $text
+*/
+   public function insertPage($pageName, $text = 'Sample page for unit 
test.') {
+   return parent::insertPage($pageName, $text);
+   }
+}
+
diff --git a/tests/BSFixturesProvider.php b/tests/BSFixturesProvider.php
new file mode 100644
index 000..2d89afc
--- /dev/null
+++ b/tests/BSFixturesProvider.php
@@ -0,0 +1,8 @@
+assertTrue( $title->exists(), 'Title should be known' );
+   }
+
+   public function testUserFixtures() {
+   $user = User::newFromName( 'Paul' );
+   $this->assertFalse( $user->isAnon(), "User should be known" );
+
+
+   $groups = $user->getGroups();
+
+   $this->assertTrue( in_array( 'A', $groups ), 'User should be in 
group A' );
+   $this->assertFalse( in_array( 'B', $groups ), 'User should not 
be in group B' );
+   $this->assertTrue( in_array( 'C', $groups ), 'User should be in 
group C' );
+   }
+}
\ No newline at end of file
diff --git a/tests/BSPageFixtures.php b/tests/BSPageFixtures.php
new file mode 100644
index 000..50c6a4b
--- /dev/null
+++ b/tests/BSPageFixtures.php
@@ -0,0 +1,20 @@
+getFixtureData() as $pageData ) {
+   $testcase->insertPage( $pageData[0], $pageData[1] );
+   }
+   }
+}
\ No newline at end of file
diff --git a/tests/BSPageFixturesProvider.php b/tests/BSPageFixturesProvider.php
index 9779a75..5406143 100644
--- a/tests/BSPageFixturesProvider.php
+++ b/tests/BSPageFixturesProvider.php
@@ -1,12 +1,12 @@
 pages;
}
 }
\ No newline at end of file
diff --git a/tests/BSUserFixtures.php b/tests/BSUserFixtures.php
new file mode 100644
index 000..f998d51
--- /dev/null
+++ b/tests/BSUserFixtures.php
@@ -0,0 +1,51 @@
+setUserFixture( $this );
+
+   //Read in only once!
+   $this->fixtureData = $provider->getFixtureData();
+   }
+
+   /**
+*
+* @return \TestUser[]
+*/
+   public function makeTestUsers() {
+   $users = [];
+   foreach( $this->fixtureData as $userData ) {
+   $user = new TestUser(
+