Merge branch 'MDL-73483-master' of https://github.com/dmitriim/moodle
[moodle.git] / lib / tests / qrcode_test.php
blob7e2830482a93f1843106b2acd7ad323430f0b51e
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.
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/>.
17 namespace core;
19 use core_qrcode;
21 /**
22 * A set of tests for some of the QR code functionality within Moodle.
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
29 class qrcode_test extends \basic_testcase {
31 /**
32 * Basic test to generate a QR code and check that the library is not broken.
34 public function test_generate_basic_qr() {
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.
38 $text = 'abc';
39 $color = 'black';
40 $qrcode = new core_qrcode($text, $color);
41 $svgdata = $qrcode->getBarcodeSVGcode(1, 1);
43 // Just check the SVG was generated.
44 $this->assertStringContainsString('<desc>' . $text . '</desc>', $svgdata);
45 $this->assertStringContainsString('fill="' . $color . '"', $svgdata);