<commit_before><?php declare(strict_types=1);

namespace SmrTest\lib\DefaultGame;

use Page;

/**
 * This is an integration test, but does not need to extend BaseIntegrationTest
 * since we are not (or should not be!) writing any data.
 * @covers Page
 */
class PageIntegrationTest extends \PHPUnit\Framework\TestCase {

	public function test_create() {
		// Test create with $extra as array
		$page = Page::create('file', 'body', ['extra' => 'data']);
		// Check that the expected keys of the ArrayObject are set
		$expected = ['extra' => 'data', 'url' => 'file', 'body' => 'body'];
		self::assertSame($expected, $page->getArrayCopy());

		// Test create with $extra as a Page object
		$page2 = Page::create('file2', extra: $page);
		// Check that the expected keys of the ArrayObject are set
		$expected2 = ['extra' => 'data', 'url' => 'file2', 'body' => ''];
		self::assertSame($expected2, $page2->getArrayCopy());

		// Make sure they are not references to the same underlying object
		self::assertNotSame($page, $page2);
		// Make sure passing $page to create didn't modify the original
		self::assertSame($expected, $page->getArrayCopy());

		// Test create when setting $remainingPageLoads
		$page3 = Page::create('file', remainingPageLoads: 2);
		self::assertSame(2, $page3['RemainingPageLoads']);
	}

	public function test_copy() {
		// Create an arbitrary Page
		$page = Page::create('file');
		// The copy should be equal, but not the same
		$copy = Page::copy($page);
		self::assertNotSame($page, $copy);
		self::assertEquals($page, $copy);
	}

	public function test_useAsGlobalVar() {
		// Create an arbitrary Page
		$page = Page::create('file');

		// Unset the global $var in case it has been set elsewhere
		global $var;
		$var = null;

		// The global $var should be the same object as $page
		$page->useAsGlobalVar();
		self::assertSame($var, $page);
	}

	public function test_href() {
		// Create an arbitrary Page
		$page = Page::create('file');

		// The Page should not be modified when href() is called
		$expected = $page->getArrayCopy();
		srand(0); // for a deterministic SN
		$_SERVER['REQUEST_URI'] = 'loader.php'; // prevent "Undefined array key"
		$href = $page->href();
		self::assertSame('?sn=qpbqzr', $href);
		self::assertSame($expected, $page->getArrayCopy());
	}

}
<commit_msg>PageIntegrationTest.php: fix SmrSession leak<commit_after><?php declare(strict_types=1);

namespace SmrTest\lib\DefaultGame;

use Page;

/**
 * This is an integration test, but does not need to extend BaseIntegrationTest
 * since we are not (or should not be!) writing any data.
 * @covers Page
 */
class PageIntegrationTest extends \PHPUnit\Framework\TestCase {

	public function test_create() {
		// Test create with $extra as array
		$page = Page::create('file', 'body', ['extra' => 'data']);
		// Check that the expected keys of the ArrayObject are set
		$expected = ['extra' => 'data', 'url' => 'file', 'body' => 'body'];
		self::assertSame($expected, $page->getArrayCopy());

		// Test create with $extra as a Page object
		$page2 = Page::create('file2', extra: $page);
		// Check that the expected keys of the ArrayObject are set
		$expected2 = ['extra' => 'data', 'url' => 'file2', 'body' => ''];
		self::assertSame($expected2, $page2->getArrayCopy());

		// Make sure they are not references to the same underlying object
		self::assertNotSame($page, $page2);
		// Make sure passing $page to create didn't modify the original
		self::assertSame($expected, $page->getArrayCopy());

		// Test create when setting $remainingPageLoads
		$page3 = Page::create('file', remainingPageLoads: 2);
		self::assertSame(2, $page3['RemainingPageLoads']);
	}

	public function test_copy() {
		// Create an arbitrary Page
		$page = Page::create('file');
		// The copy should be equal, but not the same
		$copy = Page::copy($page);
		self::assertNotSame($page, $copy);
		self::assertEquals($page, $copy);
	}

	public function test_useAsGlobalVar() {
		// Create an arbitrary Page
		$page = Page::create('file');

		// Unset the global $var in case it has been set elsewhere
		global $var;
		$var = null;

		// The global $var should be the same object as $page
		$page->useAsGlobalVar();
		self::assertSame($var, $page);
	}

	public function test_href() {
		// Create an arbitrary Page
		$page = Page::create('file');

		// Pre-initialize the SmrSession, since it uses 'rand', and we don't
		// want it to interfere with our rand seed when we call `href`, which
		// internally requires an SmrSession.
		\SmrSession::init();

		// The Page should not be modified when href() is called
		$expected = $page->getArrayCopy();
		srand(0); // for a deterministic SN
		$_SERVER['REQUEST_URI'] = 'loader.php'; // prevent "Undefined array key"
		$href = $page->href();
		self::assertSame('?sn=qpbqzr', $href);
		self::assertSame($expected, $page->getArrayCopy());
	}

}

{'fraction_non_alphanumeric': 0.15454171804356762, 'fraction_numerical': 0.005343197698314837, 'mean_word_length': 4.222103004291846, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5007338', 'n_tokens_mistral': 1603, 'n_tokens_neox': 1487, 'n_words': 497}