<commit_before><?php
/**
 * Test AMP_Story_Templates.
 *
 * @package AMP
 */

/**
 * Test AMP_Story_Post_Type.
 */
class AMP_Story_Templates_Test extends WP_UnitTestCase {

	/**
	 * Setup.
	 *
	 * @inheritdoc
	 */
	public function setUp() {
		parent::setUp();

		foreach ( WP_Block_Type_Registry::get_instance()->get_all_registered() as $block ) {
			WP_Block_Type_Registry::get_instance()->unregister( $block->name );
		}

		AMP_Story_Post_Type::register();
	}

	/**
	 * Test init().
	 *
	 * @covers AMP_Story_Templates::init()
	 */
	public function test_init() {
		if ( ! function_exists( 'register_block_type' ) ) {
			$this->markTestSkipped( 'The function register_block_type() is not present, so the AMP Story post type was not registered.' );
		}

		$amp_story_templates = new AMP_Story_Templates();
		$amp_story_templates->init();

		$this->assertTrue( post_type_exists( 'amp_story' ) );
		$this->assertEquals( 10, has_action( 'rest_wp_block_query', array( $amp_story_templates, 'filter_rest_wp_block_query' ) ) );
		$this->assertEquals( 10, has_action( 'save_post_wp_block', array( $amp_story_templates, 'flag_template_as_modified' ) ) );
		$this->assertEquals( 10, has_action( 'user_has_cap', array( $amp_story_templates, 'filter_user_has_cap' ) ) );
		$this->assertEquals( 10, has_action( 'pre_get_posts', array( $amp_story_templates, 'filter_pre_get_posts' ) ) );
	}

	/**
	 * Test filter_user_has_cap().
	 *
	 * @covers AMP_Story_Templates::filter_user_has_cap()
	 */
	public function test_filter_user_has_cap() {
		if ( ! function_exists( 'register_block_type' ) ) {
			$this->markTestSkipped( 'The function register_block_type() is not present, so the AMP Story post type was not registered.' );
		}

		$story_id = $this->factory()->post->create( array( 'post_type' => AMP_Story_Post_Type::POST_TYPE_SLUG ) );
		wp_set_object_terms( $story_id, AMP_Story_Templates::TEMPLATES_TERM, AMP_Story_Templates::TEMPLATES_TAXONOMY );

		$amp_story_templates = new AMP_Story_Templates();
		$amp_story_templates->init();

		$allcaps = array(
			'edit_others_posts'    => true,
			'edit_published_posts' => true,
		);
		$args    = array(
			0 => 'edit_post',
			2 => $story_id,
		);

		$capabilities = $amp_story_templates->filter_user_has_cap( $allcaps, array(), $args );
		$this->assertTrue( has_term( AMP_Story_Templates::TEMPLATES_TERM, AMP_Story_Templates::TEMPLATES_TAXONOMY, $args[2] ) );
		$this->assertEquals( array(), $capabilities );
	}
}
<commit_msg>Fix unit tests due to unregistering blocks<commit_after><?php
/**
 * Test AMP_Story_Templates.
 *
 * @package AMP
 */

/**
 * Test AMP_Story_Post_Type.
 */
class AMP_Story_Templates_Test extends WP_UnitTestCase {

	/**
	 * Setup.
	 *
	 * @inheritdoc
	 */
	public function setUp() {
		parent::setUp();

		foreach ( WP_Block_Type_Registry::get_instance()->get_all_registered() as $block ) {
			if ( 'amp/' === substr( $block->name, 0, 4 ) ) {
				WP_Block_Type_Registry::get_instance()->unregister( $block->name );
			}
		}

		AMP_Story_Post_Type::register();
	}

	/**
	 * Test init().
	 *
	 * @covers AMP_Story_Templates::init()
	 */
	public function test_init() {
		if ( ! function_exists( 'register_block_type' ) ) {
			$this->markTestSkipped( 'The function register_block_type() is not present, so the AMP Story post type was not registered.' );
		}

		$amp_story_templates = new AMP_Story_Templates();
		$amp_story_templates->init();

		$this->assertTrue( post_type_exists( 'amp_story' ) );
		$this->assertEquals( 10, has_action( 'rest_wp_block_query', array( $amp_story_templates, 'filter_rest_wp_block_query' ) ) );
		$this->assertEquals( 10, has_action( 'save_post_wp_block', array( $amp_story_templates, 'flag_template_as_modified' ) ) );
		$this->assertEquals( 10, has_action( 'user_has_cap', array( $amp_story_templates, 'filter_user_has_cap' ) ) );
		$this->assertEquals( 10, has_action( 'pre_get_posts', array( $amp_story_templates, 'filter_pre_get_posts' ) ) );
	}

	/**
	 * Test filter_user_has_cap().
	 *
	 * @covers AMP_Story_Templates::filter_user_has_cap()
	 */
	public function test_filter_user_has_cap() {
		if ( ! function_exists( 'register_block_type' ) ) {
			$this->markTestSkipped( 'The function register_block_type() is not present, so the AMP Story post type was not registered.' );
		}

		$story_id = $this->factory()->post->create( array( 'post_type' => AMP_Story_Post_Type::POST_TYPE_SLUG ) );
		wp_set_object_terms( $story_id, AMP_Story_Templates::TEMPLATES_TERM, AMP_Story_Templates::TEMPLATES_TAXONOMY );

		$amp_story_templates = new AMP_Story_Templates();
		$amp_story_templates->init();

		$allcaps = array(
			'edit_others_posts'    => true,
			'edit_published_posts' => true,
		);
		$args    = array(
			0 => 'edit_post',
			2 => $story_id,
		);

		$capabilities = $amp_story_templates->filter_user_has_cap( $allcaps, array(), $args );
		$this->assertTrue( has_term( AMP_Story_Templates::TEMPLATES_TERM, AMP_Story_Templates::TEMPLATES_TAXONOMY, $args[2] ) );
		$this->assertEquals( array(), $capabilities );
	}
}

{'fraction_non_alphanumeric': 0.14741671653700378, 'fraction_numerical': 0.0047875523638539795, 'mean_word_length': 5.084951456310679, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 50, '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': '2388250', 'n_tokens_mistral': 1964, 'n_tokens_neox': 1758, 'n_words': 310}