1*50d6f48cSGreg Roach<?php 2*50d6f48cSGreg Roach/** 3*50d6f48cSGreg Roach * webtrees: online genealogy 4*50d6f48cSGreg Roach * Copyright (C) 2019 webtrees development team 5*50d6f48cSGreg Roach * This program is free software: you can redistribute it and/or modify 6*50d6f48cSGreg Roach * it under the terms of the GNU General Public License as published by 7*50d6f48cSGreg Roach * the Free Software Foundation, either version 3 of the License, or 8*50d6f48cSGreg Roach * (at your option) any later version. 9*50d6f48cSGreg Roach * This program is distributed in the hope that it will be useful, 10*50d6f48cSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 11*50d6f48cSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12*50d6f48cSGreg Roach * GNU General Public License for more details. 13*50d6f48cSGreg Roach * You should have received a copy of the GNU General Public License 14*50d6f48cSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 15*50d6f48cSGreg Roach */ 16*50d6f48cSGreg Roachdeclare(strict_types=1); 17*50d6f48cSGreg Roach 18*50d6f48cSGreg Roachnamespace Fisharebest\Webtrees\Services; 19*50d6f48cSGreg Roach 20*50d6f48cSGreg Roachuse Fisharebest\Webtrees\MockGlobalFunctions; 21*50d6f48cSGreg Roachuse Fisharebest\Webtrees\TestCase; 22*50d6f48cSGreg Roach 23*50d6f48cSGreg Roach/** 24*50d6f48cSGreg Roach * Test harness for the class HtmlService 25*50d6f48cSGreg Roach */ 26*50d6f48cSGreg Roachclass HtmlServiceTest extends TestCase 27*50d6f48cSGreg Roach{ 28*50d6f48cSGreg Roach /** 29*50d6f48cSGreg Roach * @covers \Fisharebest\Webtrees\Services\HtmlService::sanitize 30*50d6f48cSGreg Roach * 31*50d6f48cSGreg Roach * @return void 32*50d6f48cSGreg Roach */ 33*50d6f48cSGreg Roach public function testAllowedHtml(): void 34*50d6f48cSGreg Roach { 35*50d6f48cSGreg Roach $html_service = new HtmlService(); 36*50d6f48cSGreg Roach 37*50d6f48cSGreg Roach $dirty = '<div class="foo">bar</div>'; 38*50d6f48cSGreg Roach $clean = $html_service->sanitize($dirty); 39*50d6f48cSGreg Roach 40*50d6f48cSGreg Roach $this->assertSame($dirty, $clean); 41*50d6f48cSGreg Roach } 42*50d6f48cSGreg Roach 43*50d6f48cSGreg Roach /** 44*50d6f48cSGreg Roach * @covers \Fisharebest\Webtrees\Services\HtmlService::sanitize 45*50d6f48cSGreg Roach * 46*50d6f48cSGreg Roach * @return void 47*50d6f48cSGreg Roach */ 48*50d6f48cSGreg Roach public function testDisallowedHtml(): void 49*50d6f48cSGreg Roach { 50*50d6f48cSGreg Roach $html_service = new HtmlService(); 51*50d6f48cSGreg Roach 52*50d6f48cSGreg Roach $dirty = '<div class="foo" onclick="alert(123)">bar</div>'; 53*50d6f48cSGreg Roach $clean = $html_service->sanitize($dirty); 54*50d6f48cSGreg Roach 55*50d6f48cSGreg Roach $this->assertSame('<div class="foo">bar</div>', $clean); 56*50d6f48cSGreg Roach } 57*50d6f48cSGreg Roach} 58