<commit_before><?php

class AMP_Render_Post_Test extends WP_UnitTestCase {
	/**
	 * @expectedDeprecated amp_render_post
	 */
	public function test__invalid_post() {
		// No ob here since it bails early
		$amp_rendered = amp_render_post( PHP_INT_MAX );

		$this->assertNull( $amp_rendered, 'Response was not null' );
		$this->assertEquals( 0, did_action( 'pre_amp_render_post' ), 'pre_amp_render_post action fire when it should not have.' );
	}

	/**
	 * @expectedDeprecated amp_render_post
	 */
	public function test__valid_post() {
		$user_id = self::factory()->user->create();
		$post_id = self::factory()->post->create( [ 'post_author' => $user_id ] );

		// Set global for WP<5.2 where get_the_content() doesn't take the $post parameter.
		$GLOBALS['post'] = get_post( $post_id );

		$output = get_echo( 'amp_render_post', [ $post_id ] );

		$this->assertContains( '<html amp', $output, 'Response does not include html tag with amp attribute.' );
		$this->assertEquals( 1, did_action( 'pre_amp_render_post', 'pre_amp_render_post action fire either did not fire or fired too many times.' ) );
	}

	/**
	 * Stored result of is_amp_endpoint() when calling amp_render_post().
	 *
	 * @var bool
	 */
	protected $was_amp_endpoint;

	/**
	 * Test is_amp_endpoint.
	 *
	 * @covers ::is_amp_endpoint()
	 * @expectedDeprecated amp_render_post
	 */
	public function test__is_amp_endpoint() {
		$user_id = self::factory()->user->create();
		$post_id = self::factory()->post->create(
			[
				'post_author' => $user_id,
			]
		);

		// Set global for WP<5.2 where get_the_content() doesn't take the $post parameter.
		$GLOBALS['post'] = get_post( $post_id );

		$before_is_amp_endpoint = is_amp_endpoint();

		add_action( 'pre_amp_render_post', [ $this, 'check_is_amp_endpoint' ] );
		$this->was_amp_endpoint = false;

		$output = get_echo( 'amp_render_post', [ $post_id ] );
		$this->assertContains( '<html amp', $output );

		$after_is_amp_endpoint = is_amp_endpoint();<commit_msg>Fix AMP_Render_Post_Test (again) by setting up postdata<commit_after><?php

class AMP_Render_Post_Test extends WP_UnitTestCase {
	/**
	 * @expectedDeprecated amp_render_post
	 */
	public function test__invalid_post() {
		// No ob here since it bails early
		$amp_rendered = amp_render_post( PHP_INT_MAX );

		$this->assertNull( $amp_rendered, 'Response was not null' );
		$this->assertEquals( 0, did_action( 'pre_amp_render_post' ), 'pre_amp_render_post action fire when it should not have.' );
	}

	/**
	 * @expectedDeprecated amp_render_post
	 */
	public function test__valid_post() {
		$user_id = self::factory()->user->create();
		$post_id = self::factory()->post->create( [ 'post_author' => $user_id ] );

		// Set global for WP<5.2 where get_the_content() doesn't take the $post parameter.
		$GLOBALS['post'] = get_post( $post_id );
		setup_postdata( $post_id );

		$output = get_echo( 'amp_render_post', [ $post_id ] );

		$this->assertContains( '<html amp', $output, 'Response does not include html tag with amp attribute.' );
		$this->assertEquals( 1, did_action( 'pre_amp_render_post', 'pre_amp_render_post action fire either did not fire or fired too many times.' ) );
	}

	/**
	 * Stored result of is_amp_endpoint() when calling amp_render_post().
	 *
	 * @var bool
	 */
	protected $was_amp_endpoint;

	/**
	 * Test is_amp_endpoint.
	 *
	 * @covers ::is_amp_endpoint()
	 * @expectedDeprecated amp_render_post
	 */
	public function test__is_amp_endpoint() {
		$user_id = self::factory()->user->create();
		$post_id = self::factory()->post->create(
			[
				'post_author' => $user_id,
			]
		);

		// Set global for WP<5.2 where get_the_content() doesn't take the $post parameter.
		$GLOBALS['post'] = get_post( $post_id );
		setup_postdata( $post_id );

		$before_is_amp_endpoint = is_amp_endpoint();

		add_action( 'pre_amp_render_post', [ $this, 'check_is_amp_endpoint' ] );
		$this->was_amp_endpoint = false;

		$output = get_echo( 'amp_render_post', [ $post_id ] );
		$this->assertContains( '<html amp', $output );

		$after_is_amp_endpoint = is_amp_endpoint();
{'fraction_non_alphanumeric': 0.145679012345679, 'fraction_numerical': 0.002962962962962963, 'mean_word_length': 4.526603001364257, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 35, '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': '4992595', 'n_tokens_mistral': 1503, 'n_tokens_neox': 1357, 'n_words': 317}