<commit_before><?php

// Exit if accessed directly
defined( 'ABSPATH' ) || exit;

/**
 * Unit tests covering `Papi_Property` class.
 *
 * @package Papi
 */

class Papi_Property_Test extends WP_UnitTestCase {

	/**
	 * Setup test.
	 *
	 * @since 1.3.0
	 */

	public function setUp() {
		parent::setUp();

		$this->post_id = $this->factory->post->create();

		global $post;
		$post = get_post( $this->post_id );
	}

	/**
	 * Tear down property.
	 *
	 * @since 1.3.0
	 */

	public function tearDown() {
		parent::tearDown();
		global $post;
		unset( $post, $this->post_id );
	}

	/**
	 * Test static `create` method.
	 *
	 * @since 1.3.0
	 */

	public function test_create() {
		$property = Papi_Property::create( [
			'type'  => 'string',
			'title' => 'Name'
		] );

		$this->assertEquals( $property->get_option( 'type' ), 'string' );
		$this->assertEquals( $property->get_option( 'title' ), 'Name' );
		$this->assertEquals( $property->get_option( 'slug' ), 'papi_name' );
	}

	/**
	 * Test static `default_options` method.
	 *
	 * @since 1.3.0
	 */

	public function test_default_options() {
		$default_options = Papi_Property::default_options();

		$this->assertTrue( is_array( $default_options ) );
		$this->assertEmpty( $default_options['title'] );
		$this->assertEmpty( $default_options['type'] );
		$this->assertEmpty( $default_options['slug'] );
		$this->assertEquals( 1000, $default_options['sort_order'] );
	}

	/**
	 * Test static `factory` method.
	 *
	 * @since 1.3.0
	 */

	public function test_factory() {
		require_once papi_test_get_fixtures_path( '/properties/class-papi-property-fake.php' );

		$this->assertNull( Papi_Property::factory( null ) );
		$this->assertNull( Papi_Property::factory( '' ) );
		$this->assertNull( Papi_Property::factory( 'fake' ) );

		$this->assertTrue( is_object( Papi_Property::factory( 'string' ) ) );
	}

	/**
	 * Test `format_value` method.
	 *
	 * @since 1.3.0
	 */

	public function test_format_value() {
		$property = Papi_Property::create( [
			'type'  => 'string',
			'title' => 'Hello'
		] );

		$actual = $property->format_value( 'Fredrik', '', 0 );

		$this->assertEquals( 'Fredrik', $actual );
	}

	/**
	 * Test `override_property_options` method.
	 *
	 * @since 1.3.0
	 */

	public function test_override_property_options() {
		$property = Papi_Property::create( [
			'type'  => 'string',
			'title' => 'Hello'
		] );

		$this->assertEquals( [], $property->override_property_options() );
	}

	/**
	 * Test `get_default_settings` method.
	 *
	 * @since 1.3.0
	 */

	public function test_get_default_settings() {
		$property = Papi_Property::create( [
			'type'  => 'string',
			'title' => 'Hello'
		] );

		$this->assertEquals( [], $property->get_default_settings() );
	}

	/**
	 * Test `get_default_value` method.
	 *
	 * @since 1.3.0
	 */

	public function test_get_default_value() {
		$property = Papi_Property::create( [
			'type'  => 'string',
			'title' => 'Hello'
		] );

		$this->assertEmpty( $property->get_value() );

		$property->set_options( [
			'type'  => 'string',
			'slug'  => 'name',
			'value' => 'hello world'
		] );

		$this->assertEquals( 'hello world', $property->get_value() );
	}

	/**
	 * Test `get_option` method.
	 *
	 * @since 1.3.0
	 */

	public function test_get_option() {
		$property = Papi_Property::create( [
			'title' => 'Name'
		] );

		$this->assertNull( $property->get_option( 'fake' ) );
		$this->assertEquals( 'Name', $property->get_option( 'title' ) );
		$this->assertEquals( 1000, $property->get_option( 'sort_order' ) );
	}

	/**
	 * Test `get_options` method.
	 *
	 * @since 1.3.0
	 */

	public function test_get_options() {
		$property = new Papi_Property();

		$this->assertEmpty( $property->get_options() );
	}

	/**
	 * Test `get_post_id` method.
	 *
	 * @since 1.3.0
	 */

	public function test_get_post_id() {
		$property = Papi_Property::create();

		$this->assertEquals( $this->post_id, $property->get_post_id() );
	}

	/**
	 * Test `get_settings` method.
	 *
	 * @since 1.3.0
	 */

	public function test_get_settings() {
		$property = new Papi_Property();

		$this->assertEmpty( $property->get_settings() );

		$property->set_options( [
			'settings' => [
				'items' => [
					[
						'type' => 'faker'
					],
					[
						'type' => 'fake'
					]
				]
			]
		] );

		$settings = $property->get_settings();<commit_msg>Added tests for `get_setting` method<commit_after><?php

// Exit if accessed directly
defined( 'ABSPATH' ) || exit;

/**
 * Unit tests covering `Papi_Property` class.
 *
 * @package Papi
 */

class Papi_Property_Test extends WP_UnitTestCase {

	/**
	 * Setup test.
	 *
	 * @since 1.3.0
	 */

	public function setUp() {
		parent::setUp();

		$this->post_id = $this->factory->post->create();

		global $post;
		$post = get_post( $this->post_id );
	}

	/**
	 * Tear down property.
	 *
	 * @since 1.3.0
	 */

	public function tearDown() {
		parent::tearDown();
		global $post;
		unset( $post, $this->post_id );
	}

	/**
	 * Test static `create` method.
	 *
	 * @since 1.3.0
	 */

	public function test_create() {
		$property = Papi_Property::create( [
			'type'  => 'string',
			'title' => 'Name'
		] );

		$this->assertEquals( $property->get_option( 'type' ), 'string' );
		$this->assertEquals( $property->get_option( 'title' ), 'Name' );
		$this->assertEquals( $property->get_option( 'slug' ), 'papi_name' );
	}

	/**
	 * Test static `default_options` method.
	 *
	 * @since 1.3.0
	 */

	public function test_default_options() {
		$default_options = Papi_Property::default_options();

		$this->assertTrue( is_array( $default_options ) );
		$this->assertEmpty( $default_options['title'] );
		$this->assertEmpty( $default_options['type'] );
		$this->assertEmpty( $default_options['slug'] );
		$this->assertEquals( 1000, $default_options['sort_order'] );
	}

	/**
	 * Test static `factory` method.
	 *
	 * @since 1.3.0
	 */

	public function test_factory() {
		require_once papi_test_get_fixtures_path( '/properties/class-papi-property-fake.php' );

		$this->assertNull( Papi_Property::factory( null ) );
		$this->assertNull( Papi_Property::factory( '' ) );
		$this->assertNull( Papi_Property::factory( 'fake' ) );

		$this->assertTrue( is_object( Papi_Property::factory( 'string' ) ) );
	}

	/**
	 * Test `format_value` method.
	 *
	 * @since 1.3.0
	 */

	public function test_format_value() {
		$property = Papi_Property::create( [
			'type'  => 'string',
			'title' => 'Hello'
		] );

		$actual = $property->format_value( 'Fredrik', '', 0 );

		$this->assertEquals( 'Fredrik', $actual );
	}

	/**
	 * Test `override_property_options` method.
	 *
	 * @since 1.3.0
	 */

	public function test_override_property_options() {
		$property = Papi_Property::create( [
			'type'  => 'string',
			'title' => 'Hello'
		] );

		$this->assertEquals( [], $property->override_property_options() );
	}

	/**
	 * Test `get_default_settings` method.
	 *
	 * @since 1.3.0
	 */

	public function test_get_default_settings() {
		$property = Papi_Property::create( [
			'type'  => 'string',
			'title' => 'Hello'
		] );

		$this->assertEquals( [], $property->get_default_settings() );
	}

	/**
	 * Test `get_default_value` method.
	 *
	 * @since 1.3.0
	 */

	public function test_get_default_value() {
		$property = Papi_Property::create( [
			'type'  => 'string',
			'title' => 'Hello'
		] );

		$this->assertEmpty( $property->get_value() );

		$property->set_options( [
			'type'  => 'string',
			'slug'  => 'name',
			'value' => 'hello world'
		] );

		$this->assertEquals( 'hello world', $property->get_value() );
	}

	/**
	 * Test `get_option` method.
	 *
	 * @since 1.3.0
	 */

	public function test_get_option() {
		$property = Papi_Property::create( [
			'title' => 'Name'
		] );

		$this->assertNull( $property->get_option( 'fake' ) );
		$this->assertEquals( 'Name', $property->get_option( 'title' ) );
		$this->assertEquals( 1000, $property->get_option( 'sort_order' ) );
	}

	/**
	 * Test `get_options` method.
	 *
	 * @since 1.3.0
	 */

	public function test_get_options() {
		$property = new Papi_Property();

		$this->assertEmpty( $property->get_options() );
	}

	/**
	 * Test `get_post_id` method.
	 *
	 * @since 1.3.0
	 */

	public function test_get_post_id() {
		$property = Papi_Property::create();

		$this->assertEquals( $this->post_id, $property->get_post_id() );
	}

	/**
	 *
	 */

	public function test_get_setting() {
		$property = new Papi_Property();
		$this->assertNull( $property->get_setting( 'length' ) );

		$property = Papi_Property::create( [
			'type'     => 'string',
			'settings' => [
				'length' => 50
			]
		] );

		$this->assertEquals( 50, $property->get_setting( 'length' ) );
	}

	/**
	 * Test `get_settings` method.
	 *
	 * @since 1.3.0
	 */

	public function test_get_settings() {
		$property = new Papi_Property();

		$this->assertEmpty( $property->get_settings() );

		$property->set_options( [
			'settings' => [
				'items' => [
					[
						'type' => 'faker'
					],
					[
						'type' => 'fake'
					]
				]
			]
		] );

		$settings = $property->get_settings();
{'fraction_non_alphanumeric': 0.19399179691830173, 'fraction_numerical': 0.011085245538188671, 'mean_word_length': 3.3333333333333335, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 140, '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': '2398202', 'n_tokens_mistral': 3680, 'n_tokens_neox': 3189, 'n_words': 571}