/**
  * Test whether true is returned when an empty value is passed as an argument
  */
 public function test_entity_certificate_code_no_code()
 {
     $this->load_csv_data();
     $result = entity_certificate_code_exists('');
     $this->assertEquals(true, $result);
 }
Ejemplo n.º 2
0
/**
 * Make multiple attempts to get a unique certificate code.
 *
 * @param none
 * @return string A unique certificate code.
 */
function cm_certificate_get_code()
{
    $counter = 0;
    $attempts = 10;
    $maximumchar = 15;
    $addchar = 0;
    // This loop will try to generate a unique string 11 times.  On the 11th attempt
    // if string is still not unique then it will add to the length of the string
    // If the length of the string exceed the maximum length set by $maximumchar
    // then stop the loop and return an error
    do {
        $code = cm_certificate_generate_code($addchar);
        $exists = curriculum_code_exists($code);
        $exists = $exists && entity_certificate_code_exists($code);
        if (!$exists) {
            return $code;
        }
        // If the counter is equal to the number of attempts
        if ($counter == $attempts) {
            // Set counter back to zero and add a character to the string
            $counter = 0;
            $addchar++;
        }
        // increment counter otherwise this is an infinite loop
        $counter++;
    } while ($maximumchar >= $addchar);
    // Check if the length has exceeded the maximum length
    if ($maximumchar < $addchar) {
        if (!cm_certificate_email_random_number_fail($this)) {
            $message = get_string('certificate_email_fail', 'local_elisprogram');
            $OUTPUT->notification($message);
        }
        print_error('certificate_code_error', 'local_elisprogram');
    }
}