xref: /webtrees/tests/app/Services/HtmlServiceTest.php (revision 3976b4703df669696105ed6b024b96d433c8fbdb)
150d6f48cSGreg Roach<?php
2*3976b470SGreg Roach
350d6f48cSGreg Roach/**
450d6f48cSGreg Roach * webtrees: online genealogy
550d6f48cSGreg Roach * Copyright (C) 2019 webtrees development team
650d6f48cSGreg Roach * This program is free software: you can redistribute it and/or modify
750d6f48cSGreg Roach * it under the terms of the GNU General Public License as published by
850d6f48cSGreg Roach * the Free Software Foundation, either version 3 of the License, or
950d6f48cSGreg Roach * (at your option) any later version.
1050d6f48cSGreg Roach * This program is distributed in the hope that it will be useful,
1150d6f48cSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
1250d6f48cSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1350d6f48cSGreg Roach * GNU General Public License for more details.
1450d6f48cSGreg Roach * You should have received a copy of the GNU General Public License
1550d6f48cSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
1650d6f48cSGreg Roach */
1750d6f48cSGreg Roachdeclare(strict_types=1);
1850d6f48cSGreg Roach
1950d6f48cSGreg Roachnamespace Fisharebest\Webtrees\Services;
2050d6f48cSGreg Roach
2150d6f48cSGreg Roachuse Fisharebest\Webtrees\TestCase;
2250d6f48cSGreg Roach
2350d6f48cSGreg Roach/**
2450d6f48cSGreg Roach * Test harness for the class HtmlService
2550d6f48cSGreg Roach */
2650d6f48cSGreg Roachclass HtmlServiceTest extends TestCase
2750d6f48cSGreg Roach{
2850d6f48cSGreg Roach    /**
2950d6f48cSGreg Roach     * @covers \Fisharebest\Webtrees\Services\HtmlService::sanitize
3050d6f48cSGreg Roach     *
3150d6f48cSGreg Roach     * @return void
3250d6f48cSGreg Roach     */
3350d6f48cSGreg Roach    public function testAllowedHtml(): void
3450d6f48cSGreg Roach    {
3550d6f48cSGreg Roach        $html_service = new HtmlService();
3650d6f48cSGreg Roach
3750d6f48cSGreg Roach        $dirty = '<div class="foo">bar</div>';
3850d6f48cSGreg Roach        $clean = $html_service->sanitize($dirty);
3950d6f48cSGreg Roach
4050d6f48cSGreg Roach        $this->assertSame($dirty, $clean);
4150d6f48cSGreg Roach    }
4250d6f48cSGreg Roach
4350d6f48cSGreg Roach    /**
4450d6f48cSGreg Roach     * @covers \Fisharebest\Webtrees\Services\HtmlService::sanitize
4550d6f48cSGreg Roach     *
4650d6f48cSGreg Roach     * @return void
4750d6f48cSGreg Roach     */
4850d6f48cSGreg Roach    public function testDisallowedHtml(): void
4950d6f48cSGreg Roach    {
5050d6f48cSGreg Roach        $html_service = new HtmlService();
5150d6f48cSGreg Roach
5250d6f48cSGreg Roach        $dirty = '<div class="foo" onclick="alert(123)">bar</div>';
5350d6f48cSGreg Roach        $clean = $html_service->sanitize($dirty);
5450d6f48cSGreg Roach
5550d6f48cSGreg Roach        $this->assertSame('<div class="foo">bar</div>', $clean);
5650d6f48cSGreg Roach    }
5750d6f48cSGreg Roach}
58