<commit_before><?php
/**
 * ApiTest class.
 */

namespace Friendica\Test;

use Friendica\App;
use Friendica\Core\Config;
use Friendica\Core\PConfig;
use Friendica\Network\BadRequestException;
use Friendica\Network\HTTPException;
use Friendica\Render\FriendicaSmarty;

/**
 * Tests for the API functions.
 *
 * Functions that use header() need to be tested in a separate process.
 * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
 */
class ApiTest extends DatabaseTest
{

	/**
	 * Create variables used by tests.
	 */
	protected function setUp()
	{
		global $a;
		parent::setUp();

		// User data that the test database is populated with
		$this->selfUser = [
			'id' => 42,
			'name' => '<NAME>',
			'nick' => 'selfcontact',
			'nurl' => 'http://localhost/profile/selfcontact'
		];
		$this->otherUser = [
			'id' => 43,
			'name' => 'othercontact',
			'nick' => 'othercontact',
			'nurl' => 'http://localhost/profile/othercontact'
		];

		// User ID that we know is not in the database
		$this->wrongUserId = 666;

		// Most API require login so we force the session
		$_SESSION = [
			'allow_api' => true,
			'authenticated' => true,
			'uid' => $this->selfUser['id']
		];

		// Reusable App object
		$this->app = new App(__DIR__.'/../');
		$a = $this->app;

		// Default config
		Config::set('config', 'hostname', 'localhost');
		Config::set('system', 'throttle_limit_day', 100);
		Config::set('system', 'throttle_limit_week', 100);
		Config::set('system', 'throttle_limit_month', 100);
		Config::set('system', 'theme', 'system_theme');
	}

	/**
	 * Assert that an user array contains expected keys.
	 * @param array $user User array
	 * @return void
	 */
	private function assertSelfUser(array $user)
	{
		$this->assertEquals($this->selfUser['id'], $user['uid']);
		$this->assertEquals($this->selfUser['id'], $user['cid']);
		$this->assertEquals(1, $user['self']);
		$this->assertEquals('Friendica', $user['location']);
		$this->assertEquals($this->selfUser['name'], $user['name']);
		$this->assertEquals($this->selfUser['nick'], $user['screen_name']);
		$this->assertEquals('dfrn', $user['network']);
		$this->assertTrue($user['verified']);
	}

	/**
	 * Assert that an user array contains expected keys.
	 * @param array $user User array
	 * @return void
	 */
	private function assertOtherUser(array $user)
	{
		$this->assertEquals($this->otherUser['id'], $user['id']);
		$this->assertEquals($this->otherUser['id'], $user['id_str']);
		$this->assertEquals(0, $user['self']);
		$this->assertEquals($this->otherUser['name'], $user['name']);
		$this->assertEquals($this->otherUser['nick'], $user['screen_name']);
		$this->assertFalse($user['verified']);
	}
<commit_msg>Trying to understand the test tool<commit_after><?php
/**
 * ApiTest class.
 */

namespace Friendica\Test;

use Friendica\App;
use Friendica\Core\Config;
use Friendica\Core\PConfig;
use Friendica\Network\BadRequestException;
use Friendica\Network\HTTPException;
use Friendica\Render\FriendicaSmarty;

/**
 * Tests for the API functions.
 *
 * Functions that use header() need to be tested in a separate process.
 * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
 */
class ApiTest extends DatabaseTest
{

	/**
	 * Create variables used by tests.
	 */
	protected function setUp()
	{
		global $a;
		parent::setUp();

		// User data that the test database is populated with
		$this->selfUser = [
			'id' => 42,
			'name' => '<NAME>',
			'nick' => 'selfcontact',
			'nurl' => 'http://localhost/profile/selfcontact'
		];
		$this->otherUser = [
			'id' => 43,
			'name' => 'othercontact',
			'nick' => 'othercontact',
			'nurl' => 'http://localhost/profile/othercontact'
		];

		// User ID that we know is not in the database
		$this->wrongUserId = 666;

		// Most API require login so we force the session
		$_SESSION = [
			'allow_api' => true,
			'authenticated' => true,
			'uid' => $this->selfUser['id']
		];

		// Reusable App object
		$this->app = new App(__DIR__.'/../');
		$a = $this->app;

		// Default config
		Config::set('config', 'hostname', 'localhost');
		Config::set('system', 'throttle_limit_day', 100);
		Config::set('system', 'throttle_limit_week', 100);
		Config::set('system', 'throttle_limit_month', 100);
		Config::set('system', 'theme', 'system_theme');
	}

	/**
	 * Assert that an user array contains expected keys.
	 * @param array $user User array
	 * @return void
	 */
	private function assertSelfUser(array $user)
	{
		$this->assertEquals($this->selfUser['id'], $user['uid']);
		$this->assertEquals($this->selfUser['id'], $user['cid']);
		$this->assertEquals($this->selfUser['id'], $user['pid']);
		$this->assertEquals(1, $user['self']);
		$this->assertEquals('Friendica', $user['location']);
		$this->assertEquals($this->selfUser['name'], $user['name']);
		$this->assertEquals($this->selfUser['nick'], $user['screen_name']);
		$this->assertEquals('dfrn', $user['network']);
		$this->assertTrue($user['verified']);
	}

	/**
	 * Assert that an user array contains expected keys.
	 * @param array $user User array
	 * @return void
	 */
	private function assertOtherUser(array $user)
	{
		$this->assertEquals($this->otherUser['id'], $user['id']);
		$this->assertEquals($this->otherUser['id'], $user['id_str']);
		$this->assertEquals(0, $user['self']);
		$this->assertEquals($this->otherUser['name'], $user['name']);
		$this->assertEquals($this->otherUser['nick'], $user['screen_name']);
		$this->assertFalse($user['verified']);
	}

{'fraction_non_alphanumeric': 0.19546844092789067, 'fraction_numerical': 0.0071929509081100525, 'mean_word_length': 4.539840637450199, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 85, 'https://': 2, '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': '5677702', 'n_tokens_mistral': 1969, 'n_tokens_neox': 1781, 'n_words': 397}