<commit_before><?php
/**
 * REST_RoutesTest
 *
 * @package   Google\Site_Kit
 * @copyright 2019 Google LLC
 * @license   https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
 * @link      https://sitekit.withgoogle.com
 */

namespace Google\Site_Kit\Tests\Core\REST_API;

use Google\Site_Kit\Context;
use Google\Site_Kit\Core\REST_API\REST_Routes;
use Google\Site_Kit\Tests\TestCase;

/**
 * @group REST_API
 */
class REST_RoutesTest extends TestCase {

	public function test_rest_root() {
		// Assert that REST root is correct (this must not change).
		$this->assertEquals( 'google-site-kit/v1', REST_Routes::REST_ROOT );
	}

	public function test_register() {
		$rest_routes = new REST_Routes( new Context( GOOGLESITEKIT_PLUGIN_MAIN_FILE ) );
		// Clear out initial REST server, and remove all existing actions on rest_api_init
		unset( $GLOBALS['wp_rest_server'] );
		remove_all_actions( 'rest_api_init' );

		$rest_routes->register();
		// Re-init a new REST Server (triggers rest_api_init)
		$server = rest_get_server();

		// Assert that routes with the site-kit namespace were registered.
		$this->assertEquals( array( REST_Routes::REST_ROOT ), $server->get_namespaces() );

		// While most of these routes are added via filter, they should all be in this list.
		$routes = array(
			'/',
			'/' . REST_Routes::REST_ROOT,
			'/' . REST_Routes::REST_ROOT . '/core/site/data/reset',
			'/' . REST_Routes::REST_ROOT . '/core/user/data/disconnect',
			'/' . REST_Routes::REST_ROOT . '/core/user/data/authentication',
			'/' . REST_Routes::REST_ROOT . '/modules',
			'/' . REST_Routes::REST_ROOT . '/modules/(?P<slug>[a-z\\-]+)',
			'/' . REST_Routes::REST_ROOT . '/modules/(?P<slug>[a-z\\-]+)/data/(?P<datapoint>[a-z\\-]+)',
			'/' . REST_Routes::REST_ROOT . '/data',
			'/' . REST_Routes::REST_ROOT . '/modules/(?P<slug>[a-z\\-]+)/notifications',
			'/' . REST_Routes::REST_ROOT . '/core/search/data/post-search',
			'/' . REST_Routes::REST_ROOT . '/core/site/data/developer-plugin',
			'/' . REST_Routes::REST_ROOT . '/core/site/data/setup-tag',
			'/' . REST_Routes::REST_ROOT . '/core/site/data/connection',
			'/' . REST_Routes::REST_ROOT . '/core/site/data/notifications',
			'/' . REST_Routes::REST_ROOT . '/core/site/data/mark-notification',
		);

		$this->assertEqualSets( $routes, array_keys( $server->get_routes() ) );
	}
}<commit_msg>Update REST_Routes test.<commit_after><?php
/**
 * REST_RoutesTest
 *
 * @package   Google\Site_Kit
 * @copyright 2019 Google LLC
 * @license   https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
 * @link      https://sitekit.withgoogle.com
 */

namespace Google\Site_Kit\Tests\Core\REST_API;

use Google\Site_Kit\Context;
use Google\Site_Kit\Core\REST_API\REST_Routes;
use Google\Site_Kit\Tests\TestCase;

/**
 * @group REST_API
 */
class REST_RoutesTest extends TestCase {

	public function test_rest_root() {
		// Assert that REST root is correct (this must not change).
		$this->assertEquals( 'google-site-kit/v1', REST_Routes::REST_ROOT );
	}

	public function test_register() {
		$rest_routes = new REST_Routes( new Context( GOOGLESITEKIT_PLUGIN_MAIN_FILE ) );
		// Clear out initial REST server, and remove all existing actions on rest_api_init
		unset( $GLOBALS['wp_rest_server'] );
		remove_all_actions( 'rest_api_init' );

		$rest_routes->register();
		// Re-init a new REST Server (triggers rest_api_init)
		$server = rest_get_server();

		// Assert that routes with the site-kit namespace were registered.
		$this->assertEquals( array( REST_Routes::REST_ROOT ), $server->get_namespaces() );

		// While most of these routes are added via filter, they should all be in this list.
		$routes = array(
			'/',
			'/' . REST_Routes::REST_ROOT,
			'/' . REST_Routes::REST_ROOT . '/core/site/data/reset',
			'/' . REST_Routes::REST_ROOT . '/core/user/data/disconnect',
			'/' . REST_Routes::REST_ROOT . '/core/user/data/authentication',
			'/' . REST_Routes::REST_ROOT . '/core/modules/data/list',
			'/' . REST_Routes::REST_ROOT . '/core/modules/data/info',
			'/' . REST_Routes::REST_ROOT . '/modules/(?P<slug>[a-z\\-]+)/data/(?P<datapoint>[a-z\\-]+)',
			'/' . REST_Routes::REST_ROOT . '/data',
			'/' . REST_Routes::REST_ROOT . '/modules/(?P<slug>[a-z\\-]+)/data/notifications',
			'/' . REST_Routes::REST_ROOT . '/core/search/data/post-search',
			'/' . REST_Routes::REST_ROOT . '/core/site/data/developer-plugin',
			'/' . REST_Routes::REST_ROOT . '/core/site/data/setup-tag',
			'/' . REST_Routes::REST_ROOT . '/core/site/data/connection',
			'/' . REST_Routes::REST_ROOT . '/core/site/data/notifications',
			'/' . REST_Routes::REST_ROOT . '/core/site/data/mark-notification',
		);

		$this->assertEqualSets( $routes, array_keys( $server->get_routes() ) );
	}
}
{'fraction_non_alphanumeric': 0.1768549747048904, 'fraction_numerical': 0.0037942664418212477, 'mean_word_length': 3.7260956175298805, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 22, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, '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': '3313380', 'n_tokens_mistral': 1874, 'n_tokens_neox': 1678, 'n_words': 290}