SeekquarrySeekquarry - Yioop Repo - Seekquarry

/ tests / MailComponentTest.php⤓
<?php
/**
 * SeekQuarry/Yioop --
 * Open Source Pure PHP Search Engine, Crawler, and Indexer
 *
 * Copyright (C) 2009 - 2026  Chris Pollett chris@pollett.org
 *
 * LICENSE:
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 * END LICENSE
 *
 * @author Chris Pollett chris@pollett.org
 * @license https://www.gnu.org/licenses/ GPL3
 * @link https://www.seekquarry.com/
 * @copyright 2009 - 2026
 * @filesource
 */
namespace seekquarry\yioop\tests;

use seekquarry\yioop\configs as C;
use seekquarry\yioop\controllers\components\MailComponent;
use seekquarry\yioop\library as L;
use seekquarry\yioop\library\mail\ImapClient;
use seekquarry\yioop\library\mail\MailBackend;
use seekquarry\yioop\library\UnitTest;

/**
 * MailComponentTest checks the parts of MailComponent that can run
 * without a signed-in request.
 */
class MailComponentTest extends UnitTest
{
    /**
     * setUp makes a MailComponent without its controller, which
     * mailErrorText does not use, and sets the English locale.
     */
    public function setUp()
    {
        L\setLocaleObject("en-US");
        $this->test_objects['COMPONENT'] = (new \ReflectionClass(
            MailComponent::class))->newInstanceWithoutConstructor();
    }
    /**
     * tearDown has nothing to remove.
     */
    public function tearDown()
    {
    }
    /**
     * mailErrorTextTestCase checks that a backend's error constant becomes
     * English words: a message uid given as the detail is filled in, the
     * server's explanation of a failed connection follows in parentheses,
     * and a message with no known constant is shown inside the generic
     * mail error.
     */
    public function mailErrorTextTestCase()
    {
        $component = $this->test_objects['COMPONENT'];
        $not_found = new \Exception(MailBackend::ERROR_MESSAGE_NOT_FOUND .
            ": 42");
        $this->assertEqual($component->mailErrorText($not_found),
            L\tl('mail_component_message_not_found', "42"),
            "the uid given as the detail is filled in");
        $timed_out = new \Exception(ImapClient::ERROR_TIMED_OUT .
            ": after 30s");
        $this->assertEqual($component->mailErrorText($timed_out),
            L\tl('mail_component_timed_out') . " (after 30s)",
            "the server's explanation follows in parentheses");
        $unknown = new \Exception("LIST failed: BAD command");
        $this->assertEqual($component->mailErrorText($unknown),
            L\tl('mail_component_error_generic', "LIST failed: BAD command"),
            "an unknown failure is shown inside the generic error");
    }
}