-
Notifications
You must be signed in to change notification settings - Fork 181
Create issue, delete issue unit tests #709
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Raza403
wants to merge
6
commits into
mdjnelson:MOODLE_404_STABLE
Choose a base branch
from
Raza403:features/create-delete-unit-tests
base: MOODLE_404_STABLE
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ad0acc9
Added issue created and issue deleted unit tests.
Raza403 b398e30
Added functions trigger events instead of creating manually.
Raza403 5d15b9c
Added functions trigger events instead of creating manually.
Raza403 7b3cc84
Reverting changes in external.php
Raza403 8b41647
Reverting changes in external.php
Raza403 927381e
Reverting changes in external.php
Raza403 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -466,4 +466,87 @@ public function test_deleting_an_element(): void { | |
$this->assertEquals($templateupdatedevent->contextid, \context_system::instance()->id); | ||
$this->assertDebuggingNotCalled(); | ||
} | ||
|
||
/** | ||
* Tests that the issue_created event is fired correctly. | ||
*/ | ||
public function test_issue_created_event(): void { | ||
global $DB; | ||
|
||
$this->resetAfterTest(); | ||
|
||
$course = $this->getDataGenerator()->create_course(); | ||
$user = $this->getDataGenerator()->create_user(); | ||
$customcert = $this->getDataGenerator()->create_module('customcert', ['course' => $course->id]); | ||
$context = \context_module::instance($customcert->cmid); | ||
|
||
// Simulate certificate issue. | ||
$issue = new \stdClass(); | ||
$issue->userid = $user->id; | ||
$issue->customcertid = $customcert->id; | ||
$issue->timecreated = time(); | ||
$issueid = $DB->insert_record('customcert_issues', $issue); | ||
|
||
$sink = $this->redirectEvents(); | ||
|
||
// Trigger event manually. | ||
\mod_customcert\event\issue_created::create([ | ||
'objectid' => $issueid, | ||
'context' => $context, | ||
'relateduserid' => $user->id, | ||
'userid' => $user->id, | ||
])->trigger(); | ||
|
||
$events = $sink->get_events(); | ||
$this->assertCount(1, $events); | ||
|
||
$event = reset($events); | ||
$this->assertInstanceOf(\mod_customcert\event\issue_created::class, $event); | ||
$this->assertEquals($issueid, $event->objectid); | ||
$this->assertEquals($context->id, $event->contextid); | ||
$this->assertDebuggingNotCalled(); | ||
} | ||
|
||
/** | ||
* Tests that the issue_deleted event is fired correctly. | ||
*/ | ||
public function test_issue_deleted_event(): void { | ||
global $DB; | ||
|
||
$this->resetAfterTest(); | ||
|
||
$course = $this->getDataGenerator()->create_course(); | ||
$user = $this->getDataGenerator()->create_user(); | ||
$customcert = $this->getDataGenerator()->create_module('customcert', ['course' => $course->id]); | ||
$context = \context_module::instance($customcert->cmid); | ||
|
||
// Create an issue. | ||
$issue = new \stdClass(); | ||
$issue->userid = $user->id; | ||
$issue->customcertid = $customcert->id; | ||
$issue->timecreated = time(); | ||
$issueid = $DB->insert_record('customcert_issues', $issue); | ||
|
||
$sink = $this->redirectEvents(); | ||
|
||
// Simulate deleting the issue. | ||
$DB->delete_records('customcert_issues', ['id' => $issueid]); | ||
|
||
// Trigger event manually. | ||
\mod_customcert\event\issue_deleted::create([ | ||
|
||
'objectid' => $issueid, | ||
'context' => $context, | ||
'relateduserid' => $user->id, | ||
'userid' => $user->id, | ||
])->trigger(); | ||
|
||
$events = $sink->get_events(); | ||
$this->assertCount(1, $events); | ||
|
||
$event = reset($events); | ||
$this->assertInstanceOf(\mod_customcert\event\issue_deleted::class, $event); | ||
$this->assertEquals($issueid, $event->objectid); | ||
$this->assertEquals($context->id, $event->contextid); | ||
$this->assertDebuggingNotCalled(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than triggering this manually can we please call the functions that trigger this and then check the event is called?