<?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
* <a href="https://www.gnu.org/licenses/">https://www.gnu.org/licenses/</a>
*
* 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\controllers\GroupController;
use seekquarry\yioop\library\UnitTest;
/**
* WikiComponentTest checks the rules a wiki page's reader is held to:
* which reader may see a page's source and history.
*
* @author Chris Pollett
*/
class WikiComponentTest extends UnitTest
{
/**
* $component is the wiki component under test, made from a group
* controller as the site makes it.
* @var object
*/
public $component;
/**
* $source_is_public reaches the private rule so a case can call it.
* @var \ReflectionMethod
*/
public $source_is_public;
/**
* setUp makes the component the cases read, and reaches its private
* source rule through reflection, which needs no asking since PHP 8.1.
*/
public function setUp()
{
$parent = new GroupController();
$this->component = $parent->component("wiki");
$this->source_is_public = new \ReflectionMethod(
get_class($this->component), "sourceIsPublic");
}
/**
* tearDown has nothing to take down, since the cases write no file
* and no database row.
*/
public function tearDown()
{
}
/**
* groupSettingClosesSourceOverPageHeadTestCase checks that a group
* which does not allow public source closes each page's source,
* whatever the page's own head says. The help pages carry
* public_source true in their heads, and reading the page's word
* first showed a whole group's source to strangers.
*/
public function groupSettingClosesSourceOverPageHeadTestCase()
{
$closed_group = ['PAGE_SOURCE_ALLOWED' => 0];
$this->assertFalse($this->source_is_public->invoke(
$this->component, $closed_group, ['public_source' => 'true']),
"a page head saying true does not open a closed group");
$this->assertFalse($this->source_is_public->invoke(
$this->component, $closed_group, []),
"a page head saying nothing is closed in a closed group");
}
/**
* pageHeadClosesSourceOnlyInAnOpenGroupTestCase checks that a group
* which allows public source lets a page's head close its own source
* with public_source false, and leaves it open otherwise.
*/
public function pageHeadClosesSourceOnlyInAnOpenGroupTestCase()
{
$open_group = ['PAGE_SOURCE_ALLOWED' => 1];
$this->assertTrue($this->source_is_public->invoke(
$this->component, $open_group, []),
"a page in an open group is open when its head says nothing");
$this->assertTrue($this->source_is_public->invoke(
$this->component, $open_group, ['public_source' => 'true']),
"and open when its head says true");
$this->assertFalse($this->source_is_public->invoke(
$this->component, $open_group, ['public_source' => 'false']),
"and closed when its head says false");
}
}