<?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\GitComponent;
use seekquarry\yioop\library\UnitTest;

/**
 * Unit tests for GitComponent, which serves a group's git repository over
 * HTTP. These check the rule that decides, from a group's register type,
 * whether the public may read, and so clone, the repository without signing
 * in. This is the rule that lets a "By Request" or "Anyone" repository be
 * cloned anonymously while keeping an invite-only one closed.
 *
 * @author Chris Pollett
 */
class GitComponentTest extends UnitTest
{
    /**
     * These tests need nothing set up beforehand.
     */
    public function setUp()
    {
    }
    /**
     * These tests leave nothing behind to clean up.
     */
    public function tearDown()
    {
    }
    /**
     * A group counts as publicly readable, and so cloneable without signing
     * in, exactly when its register type is one Yioop shows the wider world:
     * the "By Request" browse-and-request type or the open "Anyone" type. An
     * unlisted-by-request or invite-only group, or an unknown type, does
     * not.
     */
    public function publiclyReadableGroupTestCase()
    {
        $this->assertTrue(
            GitComponent::publiclyReadableGroup(C\PUBLIC_JOIN),
            "an Anyone group is publicly readable");
        $this->assertTrue(
            GitComponent::publiclyReadableGroup(
            C\PUBLIC_BROWSE_REQUEST_JOIN),
            "a By Request group is publicly readable");
        $this->assertFalse(
            GitComponent::publiclyReadableGroup(C\REQUEST_JOIN),
            "an Unlisted By Request group is not publicly readable");
        $this->assertFalse(
            GitComponent::publiclyReadableGroup(C\INVITE_ONLY_JOIN),
            "an invite-only group is not publicly readable");
        $this->assertFalse(GitComponent::publiclyReadableGroup(-1),
            "an unknown register type is not publicly readable");
    }
}
