element_test.php 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. // This file is part of the tool_certificate plugin for 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. namespace certificateelement_teachersname;
  17. use advanced_testcase;
  18. use tool_certificate_generator;
  19. use core_text;
  20. /**
  21. * Unit tests for teachersname element.
  22. *
  23. * @package certificateelement_teachersname
  24. * @group tool_certificate
  25. * @copyright 2022 Alex
  26. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  27. */
  28. class element_test extends advanced_testcase {
  29. /**
  30. * Test set up.
  31. */
  32. public function setUp(): void {
  33. $this->resetAfterTest();
  34. }
  35. /**
  36. * Get certificate generator
  37. * @return tool_certificate_generator
  38. */
  39. protected function get_generator() : tool_certificate_generator {
  40. return $this->getDataGenerator()->get_plugin_generator('tool_certificate');
  41. }
  42. /**
  43. * Test render_html
  44. */
  45. public function test_render_html() {
  46. // global $USER, $DB, $CFG;
  47. //
  48. // require_once($CFG->dirroot.'/user/profile/lib.php');
  49. //
  50. // $this->setAdminUser();
  51. //
  52. // $certificate1 = $this->get_generator()->create_template((object)['name' => 'Certificate 1']);
  53. // $pageid = $this->get_generator()->create_page($certificate1)->get_id();
  54. // $element = $this->get_generator()->create_element($pageid, 'userfield',
  55. // ['userfield' => 'fullname']);
  56. //
  57. // $formdata = (object)['name' => 'User email element', 'userfield' => 'email'];
  58. // $e = $this->get_generator()->create_element($pageid, 'userfield', $formdata);
  59. //
  60. // $this->assertTrue(strpos($e->render_html(), '@') !== false);
  61. //
  62. // Add a custom field of textarea type.
  63. // $id1 = $DB->insert_record('user_info_field', array(
  64. // 'shortname' => 'frogdesc', 'name' => 'Description of frog', 'categoryid' => 1,
  65. // 'datatype' => 'textarea'));
  66. //
  67. // $formdata = (object)['name' => 'User custom field element', 'userfield' => $id1];
  68. // $e = $this->get_generator()->create_element($pageid, 'userfield', $formdata);
  69. //
  70. // profile_save_data((object)['id' => $USER->id, 'profile_field_frogdesc' => 'Gryffindor']);
  71. //
  72. // $this->assertTrue(strpos($e->render_html(), 'Gryffindor') !== false);
  73. //
  74. // Generate PDF for preview.
  75. // $filecontents = $this->get_generator()->generate_pdf($certificate1, true);
  76. // $filesize = core_text::strlen($filecontents);
  77. // $this->assertTrue($filesize > 30000 && $filesize < 90000);
  78. //
  79. // Generate PDF for issue.
  80. // $issue = $this->get_generator()->issue($certificate1, $this->getDataGenerator()->create_user());
  81. // $filecontents = $this->get_generator()->generate_pdf($certificate1, false, $issue);
  82. // $filesize = core_text::strlen($filecontents);
  83. // $this->assertTrue($filesize > 30000 && $filesize < 90000);
  84. }
  85. }