<commit_before><?php

use UliCMS\Models\Content\Comment;
use UliCMS\Models\Content\VCS;
use UliCMS\Exceptions\DatasetNotFoundException;
use UliCMS\Security\Permissions\PagePermissions;

class PageTest extends \PHPUnit\Framework\TestCase {

    private $user;
    private $commentsInitialEnabled;
    private $initialCommentableContentTypes;
    private $ipsum = 'Lorem ipsum dolor sit amet,
		[module="fortune2"]
		[module="test"]
		[module=&quot;hello&quot;]
		consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.';
    private $savedSettings = [];

    public function setUp() {
        
        $manager = new UserManager();
        $users = $manager->getAllUsers();
        $this->user = $users[0];

        $this->commentsInitialEnabled = Settings::get("comments_enabled");
        $this->initialCommentableContentTypes = Settings::get("commentable_content_types");

        $_SERVER['HTTP_HOST'] = "company.com";
        $_SESSION["language"] = "de";
        $_SERVER["REQUEST_URI"] = "/";

        $settings = array(
            "frontpage",
            "frontpage_de",
            "frontpage_en"
        );

        foreach ($settings as $setting) {
            $this->savedSettings[$setting] = Settings::get($setting);
        }
    }

    public function tearDown() {
        
        $_SERVER = [];
        $_GET = [];
        $_POST = [];
        $_REQUEST = [];

        if ($this->commentsInitialEnabled) {
            Settings::set("comments_enabled", "1");
        } else {
            Settings::delete("comments_enabled");
        }
        if ($this->initialCommentableContentTypes) {
            Settings::set("commentable_content_types", $this->initialCommentableContentTypes);
        } else {
            Settings::delete("commentable_content_types");
        }
        foreach ($this->savedSettings as $key => $value) {
            Settings::set($key, $value);
        }
        Database::query("delete from {prefix}content where slug = 'testdisableshortcodes' or title like 'Unit Test%' or slug like"
                . "'unit-test%' or slug = 'testDisableShortcodesFalse'", true);

        Settings::delete("comments_enabled");
        Settings::delete("commentable_content_types");

        Vars::clear();
    }

    public function testGetEmbeddedModulesPage() {
        $page = new Page();
        $page->content = $this->ipsum;
        $this->assertEquals(3, count($page->getEmbeddedModules()));
    }

    public function testContainsModuleReturnsTrue() {
        $page = new Page();
        $page->content = $this->ipsum;

        $this->assertTrue($page->containsModule());
        $this->assertTrue($page->containsModule("fortune2"));
        $this->assertTrue($page->containsModule("hello"));
    }

    public function testContainsModuleReturnsFalse() {
        $page = new Page();
        $page->content = "<NAME>";

        $this->assertFalse($page->containsModule());
        $this->assertFalse($page->containsModule("fortune2"));
        $this->assertFalse($page->containsModule("hello"));
    }

    public function testGetEmbeddedModulesModulePage() {
        $page = new Module_Page();

        $page->content = $this->ipsum;
        $this->assertEquals(3, count($page->getEmbeddedModules()));
        $page->module = "fortune2";
        $this->assertEquals(3, count($page->getEmbeddedModules()));
        $page->module = "pfbc_sample";
        $this->assertEquals(4, count($page->getEmbeddedModules()));
    }

    public function testDisableShortcodesTrue() {
        $page = new Page();
        $page->title = 'testDisableShortcodesTrue';
        $page->slug = 'testdisableshortcodes';
        $page->language = 'de';
        $page->content = "foo [csrf_token_html] bar";
        $page->author_id = 1;
        $page->group_id = 1;
        $page->custom_data["disable_shortcodes"] = true;
        $page->save();

        $_SESSION["language"] = 'de';
        $_GET["slug"] = "testdisableshortcodes";

        $this->assertStringNotContainsString(get_csrf_token_html(), get_content());
        $this->assertStringContainsString("[csrf_token_html]", get_content());
    }

    public function testDisableShortcodesFalse() {
        $page = new Page();
        $page->title = 'testDisableShortcodesFalse';
        $page->slug = 'testdisableshortcodes';
        $page->language = 'de';
        $page->content = "foo [csrf_token_html] bar";
        $page->author_id = 1;
        $page->group_id = 1;
        $page->custom_data["disable_shortcodes"] = false;
        $page->save();

        $_SESSION["language"] = 'de';
        $_GET["slug"] = "testdisableshortcodes";
<commit_msg>Update PageTest.php<commit_after><?php

use UliCMS\Models\Content\Comment;
use UliCMS\Models\Content\VCS;
use UliCMS\Exceptions\DatasetNotFoundException;
use UliCMS\Security\Permissions\PagePermissions;

class PageTest extends \PHPUnit\Framework\TestCase {

    private $user;
    private $commentsInitialEnabled;
    private $initialCommentableContentTypes;
    private $ipsum = 'Lorem ipsum dolor sit amet,
		[module="fortune2"]
		[module="test"]
		[module=&quot;hello&quot;]
		consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.';
    private $savedSettings = [];

    public function setUp() {
        
        $manager = new UserManager();
        $users = $manager->getAllUsers();
        $this->user = $users[0];

        $this->commentsInitialEnabled = Settings::get("comments_enabled");
        $this->initialCommentableContentTypes = Settings::get("commentable_content_types");

        $_SERVER['HTTP_HOST'] = "company.com";
        $_SESSION["language"] = "de";
        $_SERVER["REQUEST_URI"] = "/";

        $settings = array(
            "frontpage",
            "frontpage_de",
            "frontpage_en"
        );

        foreach ($settings as $setting) {
            $this->savedSettings[$setting] = Settings::get($setting);
        }
    }

    public function tearDown() {
        
        $_SERVER = [];
        $_GET = [];
        $_POST = [];
        $_REQUEST = [];

        if ($this->commentsInitialEnabled) {
            Settings::set("comments_enabled", "1");
        } else {
            Settings::delete("comments_enabled");
        }
        if ($this->initialCommentableContentTypes) {
            Settings::set("commentable_content_types", $this->initialCommentableContentTypes);
        } else {
            Settings::delete("commentable_content_types");
        }
        foreach ($this->savedSettings as $key => $value) {
            Settings::set($key, $value);
        }
        Database::query("delete from {prefix}content where slug = 'testdisableshortcodes' or title like 'Unit Test%' or slug like"
                . "'unit-test%' or slug = 'testDisableShortcodesFalse'", true);

        Settings::delete("comments_enabled");
        Settings::delete("commentable_content_types");

        Vars::clear();
    }

    public function testGetEmbeddedModulesPage() {
        $page = new Page();
        $page->content = $this->ipsum;
        $this->assertEquals(3, count($page->getEmbeddedModules()));
    }

    public function testContainsModuleReturnsTrue() {
        $page = new Page();
        $page->content = $this->ipsum;

        $this->assertTrue($page->containsModule());
        $this->assertTrue($page->containsModule("fortune2"));
        $this->assertTrue($page->containsModule("hello"));
    }

    public function testContainsModuleReturnsFalse() {
        $page = new Page();
        $page->content = "<NAME>";

        $this->assertFalse($page->containsModule());
        $this->assertFalse($page->containsModule("fortune2"));
        $this->assertFalse($page->containsModule("hello"));
    }

    public function testGetEmbeddedModulesModulePage() {
        $page = new Module_Page();

        $page->content = $this->ipsum;
        $this->assertEquals(3, count($page->getEmbeddedModules()));
        $page->module = "fortune2";
        $this->assertEquals(3, count($page->getEmbeddedModules()));
        $page->module = "pfbc_sample";
        $this->assertEquals(4, count($page->getEmbeddedModules()));
    }

    public function testDisableShortcodesTrue() {
        $page = new Page();
        $page->title = 'testDisableShortcodesTrue';
        $page->slug = 'testdisableshortcodes';
        $page->language = 'de';
        $page->content = "foo [csrf_token_html] bar";
        $page->author_id = 1;
        $page->group_id = 1;
        $page->custom_data["disable_shortcodes"] = true;
        $page->update();

        $_SESSION["language"] = 'de';
        $_GET["slug"] = "testdisableshortcodes";

        $this->assertStringNotContainsString(get_csrf_token_html(), get_content());
        $this->assertStringContainsString("[csrf_token_html]", get_content());
    }

    public function testDisableShortcodesFalse() {
        $page = new Page();
        $page->title = 'testDisableShortcodesFalse';
        $page->slug = 'testdisableshortcodes';
        $page->language = 'de';
        $page->content = "foo [csrf_token_html] bar";
        $page->author_id = 1;
        $page->group_id = 1;
        $page->custom_data["disable_shortcodes"] = false;
        $page->menu_image = "foo.jpg";
        $page->custom_data = null;
        $page->save();
        $page->custom_data = null;
        $page->save();

        $_SESSION["language"] = 'de';
        $_GET["slug"] = "testdisableshortcodes";

{'fraction_non_alphanumeric': 0.1345524017467249, 'fraction_numerical': 0.002547307132459971, 'mean_word_length': 2.968592057761733, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 123, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7142847', 'n_tokens_mistral': 3282, 'n_tokens_neox': 3217, 'n_words': 732}