<commit_before><?php

/**
 * Some of these tests are simply checking that pages load. They should not assume
 * somethings working.
 *
 * @package sapphiredocs
 */

class DocumentationViewerTest extends FunctionalTest {

	static $fixture_file = 'sapphiredocs/tests/DocumentTests.yml';

	protected $autoFollowRedirection = false;
	
	function setUpOnce() {
		parent::setUpOnce();
		
		$this->origEnabled = DocumentationService::automatic_registration_enabled();
		DocumentationService::set_automatic_registration(false);
		$this->origModules = DocumentationService::get_registered_modules();
		$this->origLinkBase = DocumentationViewer::get_link_base();
		DocumentationViewer::set_link_base('dev/docs/');
		foreach($this->origModules as $module) {
			DocumentationService::unregister($module->getModuleFolder());
		}
		
		// We set 3.0 as current, and test most assertions against 2.4 - to avoid 'current' rewriting issues
		DocumentationService::register("DocumentationViewerTests", BASE_PATH . "/sapphiredocs/tests/docs/", '2.4');
		DocumentationService::register("DocumentationViewerTests", BASE_PATH . "/sapphiredocs/tests/docs-2/", '2.3');
		DocumentationService::register("DocumentationViewerTests", BASE_PATH . "/sapphiredocs/tests/docs-3/", '3.0');
	}
	
	function tearDownOnce() {
		parent::tearDownOnce();
		
		DocumentationService::unregister("DocumentationViewerTests");
		DocumentationService::set_automatic_registration($this->origEnabled);
		DocumentationViewer::set_link_base($this->origLinkBase);
	}
	
	// TODO Works with phpunit executable, but not with sake. 
	// Also works in actual URL routing, just not in tests...
	// function testLocationExists() {
	// 	$response = $this->get('DocumentationViewerTests/en/2.4/');
	// 	$this->assertEquals($response->getStatusCode(), 200, 'Existing base folder');
	// 	
	// 	$response = $this->get('DocumentationViewerTests/en/2.4/subfolder');
	// 	$this->assertEquals($response->getStatusCode(), 200, 'Existing subfolder');
	// 	
	// 	$response = $this->get('DocumentationViewerTests/en/2.4/nonexistant-subfolder');
	// 	$this->assertEquals($response->getStatusCode(), 404, 'Nonexistant subfolder');
	// 	
	// 	$response = $this->get('DocumentationViewerTests/en/2.4/nonexistant-file.txt');
	// 	$this->assertEquals($response->getStatusCode(), 404, 'Nonexistant file');
	// 	
	// 	$response = $this->get('DocumentationViewerTests/en/2.4/test');
	// 	$this->assertEquals($response->getStatusCode(), 200, 'Existing file');
	// }
	
	function testGetModulePagesShort() {
		$v = new DocumentationViewer();
		$response = $v->handleRequest(new SS_HTTPRequest('GET', 'DocumentationViewerTests/en/2.4/subfolder/'));
		$pages = $v->getModulePages();
		
		$arr = $pages->toArray();
		$page = $arr[2];
		
		$this->assertEquals('Subfolder', $page->Title);
	}
	
	function testGetModulePages() {
		$v = new DocumentationViewer();
		$response = $v->handleRequest(new SS_HTTPRequest('GET', 'DocumentationViewerTests/en/2.4/subfolder/'));
		$pages = $v->getModulePages();
		$this->assertEquals(
			array('sort/', 'subfolder/', 'test.md'),
			$pages->column('Filename')
		);
		$this->assertEquals(
			array('link','current', 'link'),
			$pages->column('LinkingMode')
		);
		
		foreach($pages as $page) {
			$page->setVersion('2.4');
		}
		
		$links = $pages->column('Link');
		
		$this->assertStringEndsWith('DocumentationViewerTests/en/2.4/sort/', $links[0]);
		$this->assertStringEndsWith('DocumentationViewerTests/en/2.4/subfolder/', $links[1]);
		$this->assertStringEndsWith('DocumentationViewerTests/en/2.4/test', $links[2]);
		
		// Children
		$pagesArr = $pages->toArray();
		$child1 = $pagesArr[1];
	
		$this->assertFalse($child1->Children);
		$child2 = $pagesArr[2];
		
		$this->assertType('DataObjectSet', $child2->Children);
	
		$this->assertEquals(
			array('subfolder/subpage.md', 'subfolder/subsubfolder/'),
			$child2->Children->column('Filename')
		);
	
		$children = $child2->Children;
		
		foreach($children as $child) {
			$child->setVersion('2.4');
		}<commit_msg>BUGFIX: removed use of deprecated phpunit call.<commit_after><?php

/**
 * Some of these tests are simply checking that pages load. They should not assume
 * somethings working.
 *
 * @package sapphiredocs
 */

class DocumentationViewerTest extends FunctionalTest {

	static $fixture_file = 'sapphiredocs/tests/DocumentTests.yml';

	protected $autoFollowRedirection = false;
	
	function setUpOnce() {
		parent::setUpOnce();
		
		$this->origEnabled = DocumentationService::automatic_registration_enabled();
		DocumentationService::set_automatic_registration(false);
		$this->origModules = DocumentationService::get_registered_modules();
		$this->origLinkBase = DocumentationViewer::get_link_base();
		DocumentationViewer::set_link_base('dev/docs/');
		foreach($this->origModules as $module) {
			DocumentationService::unregister($module->getModuleFolder());
		}
		
		// We set 3.0 as current, and test most assertions against 2.4 - to avoid 'current' rewriting issues
		DocumentationService::register("DocumentationViewerTests", BASE_PATH . "/sapphiredocs/tests/docs/", '2.4');
		DocumentationService::register("DocumentationViewerTests", BASE_PATH . "/sapphiredocs/tests/docs-2/", '2.3');
		DocumentationService::register("DocumentationViewerTests", BASE_PATH . "/sapphiredocs/tests/docs-3/", '3.0');
	}
	
	function tearDownOnce() {
		parent::tearDownOnce();
		
		DocumentationService::unregister("DocumentationViewerTests");
		DocumentationService::set_automatic_registration($this->origEnabled);
		DocumentationViewer::set_link_base($this->origLinkBase);
	}
	
	// TODO Works with phpunit executable, but not with sake. 
	// Also works in actual URL routing, just not in tests...
	// function testLocationExists() {
	// 	$response = $this->get('DocumentationViewerTests/en/2.4/');
	// 	$this->assertEquals($response->getStatusCode(), 200, 'Existing base folder');
	// 	
	// 	$response = $this->get('DocumentationViewerTests/en/2.4/subfolder');
	// 	$this->assertEquals($response->getStatusCode(), 200, 'Existing subfolder');
	// 	
	// 	$response = $this->get('DocumentationViewerTests/en/2.4/nonexistant-subfolder');
	// 	$this->assertEquals($response->getStatusCode(), 404, 'Nonexistant subfolder');
	// 	
	// 	$response = $this->get('DocumentationViewerTests/en/2.4/nonexistant-file.txt');
	// 	$this->assertEquals($response->getStatusCode(), 404, 'Nonexistant file');
	// 	
	// 	$response = $this->get('DocumentationViewerTests/en/2.4/test');
	// 	$this->assertEquals($response->getStatusCode(), 200, 'Existing file');
	// }
	
	function testGetModulePagesShort() {
		$v = new DocumentationViewer();
		$response = $v->handleRequest(new SS_HTTPRequest('GET', 'DocumentationViewerTests/en/2.4/subfolder/'));
		$pages = $v->getModulePages();
		
		$arr = $pages->toArray();
		$page = $arr[2];
		
		$this->assertEquals('Subfolder', $page->Title);
	}
	
	function testGetModulePages() {
		$v = new DocumentationViewer();
		$response = $v->handleRequest(new SS_HTTPRequest('GET', 'DocumentationViewerTests/en/2.4/subfolder/'));
		$pages = $v->getModulePages();
		$this->assertEquals(
			array('sort/', 'subfolder/', 'test.md'),
			$pages->column('Filename')
		);
		$this->assertEquals(
			array('link','current', 'link'),
			$pages->column('LinkingMode')
		);
		
		foreach($pages as $page) {
			$page->setVersion('2.4');
		}
		
		$links = $pages->column('Link');
		
		$this->assertStringEndsWith('DocumentationViewerTests/en/2.4/sort/', $links[0]);
		$this->assertStringEndsWith('DocumentationViewerTests/en/2.4/subfolder/', $links[1]);
		$this->assertStringEndsWith('DocumentationViewerTests/en/2.4/test', $links[2]);
		
		// Children
		$pagesArr = $pages->toArray();
		$child1 = $pagesArr[1];
	
		$this->assertFalse($child1->Children);
		$child2 = $pagesArr[2];
		
		$this->assertInstanceOf('DataObjectSet', $child2->Children);
	
		$this->assertEquals(
			array('subfolder/subpage.md', 'subfolder/subsubfolder/'),
			$child2->Children->column('Filename')
		);
	
		$children = $child2->Children;
		
		foreach($children as $child) {
			$child->setVersion('2.4');
		}
{'fraction_non_alphanumeric': 0.17495669388765156, 'fraction_numerical': 0.015590200445434299, 'mean_word_length': 4.969719350073856, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 99, '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': '5266348', 'n_tokens_mistral': 2879, 'n_tokens_neox': 2608, 'n_words': 404}