Skip to content

Commit

Permalink
quiz-data - Additional cli_helper tests + fix old tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EJMFarrow committed Nov 20, 2024
1 parent ec21d9d commit 52be5ac
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 85 deletions.
10 changes: 5 additions & 5 deletions classes/cli_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ public function get_arguments(): array {
$longopts = $parsed['longopts'];
$commandlineargs = getopt($shortopts, $longopts);
$argcount = count($commandlineargs);
if (!isset($commandlineargs['z'])) {
if (!isset($commandlineargs['w'])) {
echo "\nProcessed {$argcount} valid command line argument" .
(($argcount !== 1) ? 's' : '') . ".\n";
}
$this->processedoptions = $this->prioritise_options($commandlineargs);
if ($this->processedoptions['help']) {
if (!empty($this->processedoptions['help'])) {
$this->show_help();
exit;
}
Expand Down Expand Up @@ -572,7 +572,7 @@ public function commit_hash_setup(object $activity):void {
$this->create_gitignore($activity->manifestpath);
$manifestdirname = dirname($activity->manifestpath);
chdir($manifestdirname);
if (!(isset($this->get_arguments()['subcall']) && $this->get_arguments()['subcall'])) {
if (empty($this->get_arguments()['subcall'])) {
exec("git add --all");
exec('git commit -m "Initial Commit - ' . basename($activity->manifestpath) . '"');
}
Expand Down Expand Up @@ -684,7 +684,7 @@ public function create_directory(string $directory):string {
* @return void
*/
public function check_for_changes($fullmanifestpath) {
if (!$this->get_arguments()['usegit'] || (isset($this->get_arguments()['subcall']) && $this->get_arguments()['subcall'])) {
if (!$this->get_arguments()['usegit'] || !empty($this->get_arguments()['subcall'])) {
return;
}
$this->check_repo_initialised($fullmanifestpath);
Expand Down Expand Up @@ -758,7 +758,7 @@ public function check_context(object $activity, bool $defaultwarning=false, bool
echo "Failed to get list of questions from Moodle.\n";
static::call_exit();
return new \stdClass(); // Required for PHPUnit.
} else if (!$silent && !(isset($this->get_arguments()['subcall']) && $this->get_arguments()['subcall'])) {
} else if (!$silent && empty($arguments['subcall'])) {
$activityname = get_class($activity);
switch ($activityname) {
case 'qbank_gitsync\export_repo':
Expand Down
2 changes: 1 addition & 1 deletion classes/create_repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public function create_quiz_directories($clihelper, $scriptdirectory) {
}
echo $output;
}
if ($arguments['usegit'] && !(isset($arguments()['subcall']) && $arguments()['subcall'])) {
if ($arguments['usegit'] && empty($arguments['subcall'])) {
// Commit the final quiz file.
// The others are committed by the following createrepo.
chdir($basedirectory);
Expand Down
2 changes: 1 addition & 1 deletion classes/export_quiz.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function __construct(cli_helper $clihelper, array $moodleinstances) {
$this->curlrequest->set_option(CURLOPT_RETURNTRANSFER, true);
$this->curlrequest->set_option(CURLOPT_POST, 1);
$this->curlrequest->set_option(CURLOPT_POSTFIELDS, $this->postsettings);
if (!$arguments['subcall']) {
if (empty($arguments['subcall'])) {
$this->listcurlrequest = $this->get_curl_request($wsurl);
$this->listpostsettings = [
'wstoken' => $token,
Expand Down
4 changes: 2 additions & 2 deletions classes/import_repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public function __construct(cli_helper $clihelper, array $moodleinstances) {
$this->listpostsettings['qcategoryname'] = $qcategoryname;
$this->listcurlrequest->set_option(CURLOPT_POSTFIELDS, $this->listpostsettings);

if (count($this->manifestcontents->questions) === 0 && !$arguments['subcall']) {
if (count($this->manifestcontents->questions) === 0 && empty($arguments['subcall'])) {
// A quiz in a whole course set up can have an empty manifest as
// the questions may be in the course.
echo "\nManifest file is empty. This should only be the case if you are importing ";
Expand Down Expand Up @@ -786,7 +786,7 @@ public function check_question_versions(): void {
} else if (property_exists($questionsinmoodle, 'exception')) {
if (isset($questionsinmoodle->errorcode) && $questionsinmoodle->errorcode === 'categoryerror') {
$arguments = $this->clihelper->get_arguments();
if (!$arguments['subcall']) {
if (empty($arguments['subcall'])) {
echo "Target category {$this->listpostsettings['qcategoryname']} does not exist in Moodle.\n";
echo "This should only be the case if you're importing it for the first time and\n";
echo "want to create new questions in Moodle.\n";
Expand Down
4 changes: 2 additions & 2 deletions cli/exportquizstructurefrommoodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@
$clihelper = new cli_helper($options);
$exportquiz = new export_quiz($clihelper, $moodleinstances);
if ($exportquiz->nonquizmanifestpath) {
if (!isset($clihelper->get_arguments()['subcall'])) {
if (empty($clihelper->get_arguments()['subcall'])) {
echo "Checking repo...\n";
}
$clihelper->check_for_changes($exportquiz->nonquizmanifestpath);
}
if ($exportquiz->quizmanifestpath) {
if (!isset($clihelper->get_arguments()['subcall'])) {
if (empty($clihelper->get_arguments()['subcall'])) {
echo "Checking quiz repo...\n";
}
$clihelper->check_for_changes($exportquiz->quizmanifestpath);
Expand Down
Loading

0 comments on commit 52be5ac

Please sign in to comment.