1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
namespace core;
|
|
|
18 |
|
|
|
19 |
use core_qrcode;
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* A set of tests for some of the QR code functionality within Moodle.
|
|
|
23 |
*
|
|
|
24 |
* @package core
|
|
|
25 |
* @copyright Moodle Pty Ltd
|
|
|
26 |
* @author <juan@moodle.com>
|
|
|
27 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
28 |
*/
|
|
|
29 |
class qrcode_test extends \basic_testcase {
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
* Basic test to generate a QR code and check that the library is not broken.
|
|
|
33 |
*/
|
11 |
efrain |
34 |
public function test_generate_basic_qr(): void {
|
1 |
efrain |
35 |
// The QR code generator library apply masks by random order, this is why everytime a QR code is generated the resultant
|
|
|
36 |
// binary file can be different. This is why tests are limited.
|
|
|
37 |
|
|
|
38 |
$text = 'abc';
|
|
|
39 |
$color = 'black';
|
|
|
40 |
$qrcode = new core_qrcode($text, $color);
|
|
|
41 |
$svgdata = $qrcode->getBarcodeSVGcode(1, 1);
|
|
|
42 |
|
|
|
43 |
// Just check the SVG was generated.
|
|
|
44 |
$this->assertStringContainsString('<desc>' . $text . '</desc>', $svgdata);
|
|
|
45 |
$this->assertStringContainsString('fill="' . $color . '"', $svgdata);
|
|
|
46 |
}
|
|
|
47 |
}
|