xref: /webtrees/tests/app/WebtreesTest.php (revision cd7f9193387ed66af604b408f480a9837276591a)
187635d09SGreg Roach<?php
287635d09SGreg Roach/**
387635d09SGreg Roach * webtrees: online genealogy
487635d09SGreg Roach * Copyright (C) 2019 webtrees development team
587635d09SGreg Roach * This program is free software: you can redistribute it and/or modify
687635d09SGreg Roach * it under the terms of the GNU General Public License as published by
787635d09SGreg Roach * the Free Software Foundation, either version 3 of the License, or
887635d09SGreg Roach * (at your option) any later version.
987635d09SGreg Roach * This program is distributed in the hope that it will be useful,
1087635d09SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
1187635d09SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1287635d09SGreg Roach * GNU General Public License for more details.
1387635d09SGreg Roach * You should have received a copy of the GNU General Public License
1487635d09SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
1587635d09SGreg Roach */
1687635d09SGreg Roachdeclare(strict_types=1);
1787635d09SGreg Roach
1887635d09SGreg Roachnamespace Fisharebest\Webtrees;
1987635d09SGreg Roach
2087635d09SGreg Roachuse function date_default_timezone_get;
2187635d09SGreg Roachuse function date_default_timezone_set;
2287635d09SGreg Roachuse function error_reporting;
23*cd7f9193SGreg Roachuse ErrorException;
24*cd7f9193SGreg Roachuse function set_error_handler;
2587635d09SGreg Roach
2687635d09SGreg Roach/**
2787635d09SGreg Roach * Test the Webtrees class
2887635d09SGreg Roach */
2987635d09SGreg Roachclass WebtreesTest extends \Fisharebest\Webtrees\TestCase
3087635d09SGreg Roach{
3187635d09SGreg Roach    /**
3287635d09SGreg Roach     * @covers \Fisharebest\Webtrees\Webtrees::init
3387635d09SGreg Roach     * @return void
3487635d09SGreg Roach     */
3587635d09SGreg Roach    public function testInit(): void
3687635d09SGreg Roach    {
3787635d09SGreg Roach        date_default_timezone_set('Europe/London');
3887635d09SGreg Roach        error_reporting(0);
39*cd7f9193SGreg Roach        set_error_handler(null);
4087635d09SGreg Roach
4187635d09SGreg Roach        Webtrees::init();
4287635d09SGreg Roach
4387635d09SGreg Roach        // webtrees always runs in UTC (and converts to local time on demand).
4487635d09SGreg Roach        $this->assertSame('UTC', date_default_timezone_get());
4587635d09SGreg Roach
4687635d09SGreg Roach        // webtrees sets the error reporting level.
4787635d09SGreg Roach        $this->assertNotSame(0, error_reporting());
4887635d09SGreg Roach        $this->assertSame(Webtrees::ERROR_REPORTING, error_reporting());
49*cd7f9193SGreg Roach
50*cd7f9193SGreg Roach        try {
51*cd7f9193SGreg Roach            // Trigger an error
52*cd7f9193SGreg Roach            fopen(__DIR__ . '/no-such-file', 'r');
53*cd7f9193SGreg Roach        } catch (ErrorException $ex) {
54*cd7f9193SGreg Roach            $this->assertSame(__FILE__, $ex->getFile());
55*cd7f9193SGreg Roach        }
56*cd7f9193SGreg Roach
57*cd7f9193SGreg Roach        // Disable error reporting (we could use "@"), and don't raise an exception.
58*cd7f9193SGreg Roach        error_reporting(0);
59*cd7f9193SGreg Roach        fopen(__DIR__ . '/no-such-file', 'r');
6087635d09SGreg Roach    }
6187635d09SGreg Roach}
62