diff --git a/module/mr/test/lib/mr.unittest.class.php b/module/mr/test/lib/mr.unittest.class.php index bba3f63da5..883e7c034b 100755 --- a/module/mr/test/lib/mr.unittest.class.php +++ b/module/mr/test/lib/mr.unittest.class.php @@ -432,4 +432,29 @@ class mrTest $MR = $this->objectModel->fetchByID($MRID); return $this->objectModel->apiAcceptMR($MR); } + + /** + * Test __construct method. + * + * @param string $appName + * @param string $rawModule + * @access public + * @return mixed + */ + public function constructTest(string $appName = '', string $rawModule = 'mr') + { + global $app; + $originalRawModule = $app->rawModule ?? ''; + + try { + $app->rawModule = $rawModule; + $mrModel = new mrModel($appName); + $result = $mrModel->moduleName; + $app->rawModule = $originalRawModule; + return $result; + } catch (Exception $e) { + $app->rawModule = $originalRawModule; + return 'error: ' . $e->getMessage(); + } + } } diff --git a/module/mr/test/model/construct.php b/module/mr/test/model/construct.php new file mode 100755 index 0000000000..8184542d3e --- /dev/null +++ b/module/mr/test/model/construct.php @@ -0,0 +1,62 @@ +#!/usr/bin/env php +objectModel = $tester->loadModel('mr'); + } + + /** + * Test __construct method. + * + * @param string $appName + * @param string $rawModule + * @access public + * @return mixed + */ + public function constructTest(string $appName = '', string $rawModule = 'mr') + { + global $app; + $originalRawModule = $app->rawModule ?? ''; + + try { + $app->rawModule = $rawModule; + $mrModel = new mrModel($appName); + $result = $mrModel->moduleName; + $app->rawModule = $originalRawModule; + return $result; + } catch (Exception $e) { + $app->rawModule = $originalRawModule; + return 'error: ' . $e->getMessage(); + } + } +} + +su('admin'); + +$mrTest = new mrConstructTest(); + +r($mrTest->constructTest('', 'mr')) && p() && e('mr'); +r($mrTest->constructTest('', 'mr')) && p() && e('mr'); +r($mrTest->constructTest('zentao', 'mr')) && p() && e('mr'); +r($mrTest->constructTest('', 'pullreq')) && p() && e('pullreq'); +r($mrTest->constructTest('zentao', 'pullreq')) && p() && e('pullreq'); \ No newline at end of file