Skip to content
...@@ -6,18 +6,18 @@ ...@@ -6,18 +6,18 @@
* Date: 24.09.13 * Date: 24.09.13
* Time: 11:16 * Time: 11:16
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
class ilQuestionSetPoolPluginMock{ class ilQuestionSetPoolPluginMock
{
protected $directory = "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/test/Mocks";
protected $directory = "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/test/Mocks"; public function getDirectory()
{
return $this->directory;
}
public function getDirectory() public function setDirectory($dir)
{ {
return $this->directory; $this->directory = $dir;
} }
public function setDirectory($dir)
{
$this->directory = $dir;
}
} }
...@@ -9,124 +9,125 @@ require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/ ...@@ -9,124 +9,125 @@ require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/
* Time: 09:53 * Time: 09:53
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
class ilPluginDispatcherTest extends PHPUnit_Framework_TestCase { class ilPluginDispatcherTest extends PHPUnit_Framework_TestCase
{
/** /**
* @var ilPluginDispatcher * @var ilPluginDispatcher
*/ */
protected $dispatcher; protected $dispatcher;
/** /**
* @var PHPUnit_Framework_MockObject_MockObject * @var PHPUnit_Framework_MockObject_MockObject
*/ */
protected $baseController_mock; protected $baseController_mock;
public function setUp() public function setUp()
{ {
// Include original Object for mock, because an Error accures, if it is included in subfiles in a test // Include original Object for mock, because an Error accures, if it is included in subfiles in a test
require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/classes/class.ilObjQuestionSetPoolGUI.php"; require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/classes/class.ilObjQuestionSetPoolGUI.php";
require_once "./Services/UIComponent/Tabs/classes/class.ilTabsGUI.php"; require_once "./Services/UIComponent/Tabs/classes/class.ilTabsGUI.php";
require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/test/Mocks/ilQuestionSetPoolPluginMock.php"; require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/test/Mocks/ilQuestionSetPoolPluginMock.php";
global $DIC; global $DIC;
$ilTabs = $DIC->tabs(); $ilTabs = $DIC->tabs();
$this->baseController_mock = $this->getMockBuilder("ilObjQuestionSetPoolGUI")->disableOriginalConstructor()->getMock(); $this->baseController_mock = $this->getMockBuilder("ilObjQuestionSetPoolGUI")->disableOriginalConstructor()->getMock();
$this->baseController_mock->plugin = new ilQuestionSetPoolPluginMock(); $this->baseController_mock->plugin = new ilQuestionSetPoolPluginMock();
$ilTabs_mock = $this->getMockBuilder("ilTabsGUI")->disableOriginalConstructor()->getMock(); $ilTabs_mock = $this->getMockBuilder("ilTabsGUI")->disableOriginalConstructor()->getMock();
$ilTabs_mock $ilTabs_mock
->expects($this->any()) ->expects($this->any())
->method("activateTab"); ->method("activateTab");
$ilTabs = $ilTabs_mock; $ilTabs = $ilTabs_mock;
$this->dispatcher = ilPluginDispatcher::getInstance($this->baseController_mock); $this->dispatcher = ilPluginDispatcher::getInstance($this->baseController_mock);
} }
public function testGetInstance() public function testGetInstance()
{ {
$dispatcher2 = ilPluginDispatcher::getInstance($this->baseController_mock); $dispatcher2 = ilPluginDispatcher::getInstance($this->baseController_mock);
$this->assertNotNull($this->dispatcher); $this->assertNotNull($this->dispatcher);
$this->assertEquals($this->dispatcher, $dispatcher2); $this->assertEquals($this->dispatcher, $dispatcher2);
} }
public function testGetController() public function testGetController()
{ {
$getController = $this->getMethod("getController"); $getController = $this->getMethod("getController");
$controller = $getController->invokeArgs($this->dispatcher, array("testController.testMethod")); $controller = $getController->invokeArgs($this->dispatcher, array("testController.testMethod"));
$this->assertEquals("testController", $controller); $this->assertEquals("testController", $controller);
} }
public function testGetCommand() public function testGetCommand()
{ {
$getCommand = $this->getMethod("getCommand"); $getCommand = $this->getMethod("getCommand");
$command = $getCommand->invokeArgs($this->dispatcher, array("testController.testMethod")); $command = $getCommand->invokeArgs($this->dispatcher, array("testController.testMethod"));
$this->assertEquals("testMethod", $command); $this->assertEquals("testMethod", $command);
} }
public function testGetCommandWithoutPassedController() public function testGetCommandWithoutPassedController()
{ {
$getCommand = $this->getMethod("getCommand"); $getCommand = $this->getMethod("getCommand");
$command = $getCommand->invokeArgs($this->dispatcher, array("testMethod")); $command = $getCommand->invokeArgs($this->dispatcher, array("testMethod"));
$this->assertEquals("testMethod", $command); $this->assertEquals("testMethod", $command);
} }
public function testGetControllerWithoutPassedController() public function testGetControllerWithoutPassedController()
{ {
$getController = $this->getMethod("getController"); $getController = $this->getMethod("getController");
$controller = $getController->invokeArgs($this->dispatcher, array("testMethod")); $controller = $getController->invokeArgs($this->dispatcher, array("testMethod"));
$this->assertEquals($this->baseController_mock, $controller); $this->assertEquals($this->baseController_mock, $controller);
} }
public function testInstantiateController() public function testInstantiateController()
{ {
$getController = $this->getMethod("getController"); $getController = $this->getMethod("getController");
$instantiateController = $this->getMethod("instantiateController"); $instantiateController = $this->getMethod("instantiateController");
$controllerName = $getController->invokeArgs($this->dispatcher, array("ilPluginSubControllerMock.testMethod")); $controllerName = $getController->invokeArgs($this->dispatcher, array("ilPluginSubControllerMock.testMethod"));
$controller = $instantiateController->invokeArgs($this->dispatcher, array($controllerName)); $controller = $instantiateController->invokeArgs($this->dispatcher, array($controllerName));
$this->assertInstanceOf("ilPluginSubControllerMock", $controller); $this->assertInstanceOf("ilPluginSubControllerMock", $controller);
} }
public function testGetControllerPath() public function testGetControllerPath()
{ {
$getControllerPath = $this->getMethod("getControllerPath"); $getControllerPath = $this->getMethod("getControllerPath");
$actual = $getControllerPath->invokeArgs($this->dispatcher, array()); $actual = $getControllerPath->invokeArgs($this->dispatcher, array());
$this->assertStringEndsWith("/classes/controllers/", $actual); $this->assertStringEndsWith("/classes/controllers/", $actual);
} }
public function testDispatch() public function testDispatch()
{ {
$this->expectOutputString("It work's"); $this->expectOutputString("It work's");
$this->dispatcher->dispatch("ilPluginSubControllerMock.testMethod"); $this->dispatcher->dispatch("ilPluginSubControllerMock.testMethod");
} }
/** /**
* Get an ReflectionMethod to test private or protected functions * Get an ReflectionMethod to test private or protected functions
* *
* @param string $method * @param string $method
* *
* @return ReflectionMethod * @return ReflectionMethod
*/ */
private function getMethod($method) private function getMethod($method)
{ {
$class = new ReflectionClass("ilPluginDispatcher"); $class = new ReflectionClass("ilPluginDispatcher");
$method = $class->getMethod($method); $method = $class->getMethod($method);
$method->setAccessible(true); $method->setAccessible(true);
return $method; return $method;
} }
} }
...@@ -8,23 +8,22 @@ require_once "./Services/Repository/classes/class.ilObjectPluginGUI.php"; ...@@ -8,23 +8,22 @@ require_once "./Services/Repository/classes/class.ilObjectPluginGUI.php";
* Date: 24.09.13 * Date: 24.09.13
* Time: 12:16 * Time: 12:16
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
class ilQuestionSetPoolTestSuite extends PHPUnit_Framework_TestSuite class ilQuestionSetPoolTestSuite extends PHPUnit_Framework_TestSuite
{ {
public static function suite()
{
$suite = new self();
public static function suite() require_once './Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/test/dispatcher/ilPluginDispatcherTest.php';
{ $suite->addTestSuite('ilPluginDispatcherTest');
$suite = new self();
require_once './Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/test/dispatcher/ilPluginDispatcherTest.php'; require_once './Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/test/providers/ilQuestionSetPoolQuestionsProviderTest.php';
$suite->addTestSuite('ilPluginDispatcherTest'); $suite->addTestSuite('ilQuestionSetPoolQuestionsProviderTest');
require_once './Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/test/providers/ilQuestionSetPoolQuestionsProviderTest.php'; require_once './Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/test/providers/ilPluginTableDatabaseDataProviderTest.php';
$suite->addTestSuite('ilQuestionSetPoolQuestionsProviderTest'); $suite->addTestSuite('ilPluginTableDatabaseDataProviderTest');
require_once './Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/test/providers/ilPluginTableDatabaseDataProviderTest.php'; return $suite;
$suite->addTestSuite('ilPluginTableDatabaseDataProviderTest'); }
return $suite;
}
} }
...@@ -9,36 +9,35 @@ require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/ ...@@ -9,36 +9,35 @@ require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/
* Time: 13:33 * Time: 13:33
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
class ilPluginTableDatabaseDataProviderTest extends PHPUnit_Framework_TestCase { class ilPluginTableDatabaseDataProviderTest extends PHPUnit_Framework_TestCase
{
/**
* @var ilQuestionSetPoolQuestionsBrowserProvider /**
*/ * @var ilQuestionSetPoolQuestionsBrowserProvider
protected $provider; */
protected $provider;
public function setUp()
{ public function setUp()
global $DIC; {
$ilDB = $DIC->database(); global $DIC;
$ilDB = $DIC->database();
$ilDB_mock = $this->getMockBuilder("ilDB")->getMock();
$ilDB_mock $ilDB_mock = $this->getMockBuilder("ilDB")->getMock();
->expects($this->any()) $ilDB_mock
->method("quote") ->expects($this->any())
->with(2) ->method("quote")
->will($this->returnValue(2)); ->with(2)
->will($this->returnValue(2));
$ilDB = $ilDB_mock;
$ilDB = $ilDB_mock;
$this->provider = new ilPluginTableDatabaseDataProviderMock();
} $this->provider = new ilPluginTableDatabaseDataProviderMock();
}
public function testIsLoaded()
{ public function testIsLoaded()
$this->assertFalse($this->provider->isLoaded(), "The Provider isn't loaded"); {
$this->provider->setLoaded(true); $this->assertFalse($this->provider->isLoaded(), "The Provider isn't loaded");
$this->assertTrue($this->provider->isLoaded(), "The Provider is loaded"); $this->provider->setLoaded(true);
} $this->assertTrue($this->provider->isLoaded(), "The Provider is loaded");
}
} }
...@@ -7,121 +7,123 @@ ...@@ -7,121 +7,123 @@
* Time: 12:33 * Time: 12:33
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
class ilQuestionSetPoolQuestionsProviderTest extends PHPUnit_Framework_TestCase { class ilQuestionSetPoolQuestionsProviderTest extends PHPUnit_Framework_TestCase
{
/** /**
* @var ilQuestionSetPoolQuestionsProvider; * @var ilQuestionSetPoolQuestionsProvider;
*/ */
protected $provider; protected $provider;
public function setUp(){ public function setUp()
require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/classes/providers/class.ilQuestionSetPoolQuestionsProvider.php"; {
require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/classes/providers/class.ilQuestionSetPoolQuestionsProvider.php";
global $DIC;
$ilDB = $DIC->database(); global $DIC;
$ilDB = $DIC->database();
$ilDB_mock = $this->getMockBuilder("ilDB")->getMock(); $ilDB_mock = $this->getMockBuilder("ilDB")->getMock();
$ilDB_mock $ilDB_mock
->expects($this->any()) ->expects($this->any())
->method("quote") ->method("quote")
->with(2) ->with(2)
->will($this->returnValue(2)); ->will($this->returnValue(2));
$ilDB = $ilDB_mock; $ilDB = $ilDB_mock;
$this->provider = new ilQuestionSetPoolQuestionsProvider(); $this->provider = new ilQuestionSetPoolQuestionsProvider();
} }
public function testGetSelectPart() public function testGetSelectPart()
{ {
$method = $this->getMethod("getSelectPart"); $method = $this->getMethod("getSelectPart");
$expected = "qpl_questions.*, qpl_qst_type.type_tag, qpl_qst_type.plugin, object_data.title as pool_title"; $expected = "qpl_questions.*, qpl_qst_type.type_tag, qpl_qst_type.plugin, object_data.title as pool_title";
$actual = $method->invokeArgs($this->provider, array()); $actual = $method->invokeArgs($this->provider, array());
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);
} }
public function testGetFromPart() public function testGetFromPart()
{ {
$method = $this->getMethod("getFromPart"); $method = $this->getMethod("getFromPart");
$expected = "qpl_questions"; $expected = "qpl_questions";
$actual = $method->invokeArgs($this->provider, array()); $actual = $method->invokeArgs($this->provider, array());
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);
} }
public function testGetJoinPart() public function testGetJoinPart()
{ {
$method = $this->getMethod("getJoinPart"); $method = $this->getMethod("getJoinPart");
$expected = $expected =
"INNER JOIN qpl_qst_type ON qpl_questions.question_type_fi = qpl_qst_type.question_type_id ". "INNER JOIN qpl_qst_type ON qpl_questions.question_type_fi = qpl_qst_type.question_type_id " .
"INNER JOIN object_data ON object_data.obj_id = qpl_questions.obj_fi ". "INNER JOIN object_data ON object_data.obj_id = qpl_questions.obj_fi " .
"LEFT JOIN rep_robj_xqsp_question ON qpl_questions.question_id = rep_robj_xqsp_question.question_fi"; "LEFT JOIN rep_robj_xqsp_question ON qpl_questions.question_id = rep_robj_xqsp_question.question_fi";
$actual = $method->invokeArgs($this->provider, array()); $actual = $method->invokeArgs($this->provider, array());
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);
} }
public function testWherePart() public function testWherePart()
{ {
$method = $this->getMethod("getWherePart"); $method = $this->getMethod("getWherePart");
$filter = array( $filter = array(
"xqsp_id" => 2 "xqsp_id" => 2
); );
$expected = "qpl_questions.original_id IS NULL AND qpl_questions.tstamp > 0 AND rep_robj_xqsp_question.questionsetpool_fi = 2"; $expected = "qpl_questions.original_id IS NULL AND qpl_questions.tstamp > 0 AND rep_robj_xqsp_question.questionsetpool_fi = 2";
$actual = $method->invokeArgs($this->provider, array($filter)); $actual = $method->invokeArgs($this->provider, array($filter));
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);
} }
public function testGroupByPart() public function testGroupByPart()
{ {
$method = $this->getMethod("getGroupByPart"); $method = $this->getMethod("getGroupByPart");
$actual = $method->invokeArgs($this->provider, array()); $actual = $method->invokeArgs($this->provider, array());
$this->assertEquals("", $actual); $this->assertEquals("", $actual);
} }
public function testHavingPart() public function testHavingPart()
{ {
$method = $this->getMethod("getHavingPart"); $method = $this->getMethod("getHavingPart");
$filter = array(); $filter = array();
$actual = $method->invokeArgs($this->provider, array($filter)); $actual = $method->invokeArgs($this->provider, array($filter));
$this->assertEquals("", $actual); $this->assertEquals("", $actual);
} }
public function testOrderByPart() public function testOrderByPart()
{ {
$method = $this->getMethod("getOrderByPart"); $method = $this->getMethod("getOrderByPart");
$filter = array(); $filter = array();
$actual = $method->invokeArgs($this->provider, array($filter)); $actual = $method->invokeArgs($this->provider, array($filter));
$this->assertEquals("", $actual); $this->assertEquals("", $actual);
} }
/** /**
* Get an ReflectionMethod to test private or protected functions * Get an ReflectionMethod to test private or protected functions
* *
* @param string $method * @param string $method
* *
* @return ReflectionMethod * @return ReflectionMethod
*/ */
private function getMethod($method) private function getMethod($method)
{ {
$class = new ReflectionClass("ilQuestionSetPoolQuestionsProvider"); $class = new ReflectionClass("ilQuestionSetPoolQuestionsProvider");
$method = $class->getMethod($method); $method = $class->getMethod($method);
$method->setAccessible(true); $method->setAccessible(true);
return $method; return $method;
} }
} }