2024-08-13
This commit is contained in:
parent
74779c64c1
commit
6b27b6d5e6
30 changed files with 6781 additions and 2 deletions
50
web/vendor/htmlburger/carbon-fields/tests/unit-tests/Field/ColorFieldTest.php
vendored
Normal file
50
web/vendor/htmlburger/carbon-fields/tests/unit-tests/Field/ColorFieldTest.php
vendored
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
use Mockery as M;
|
||||
use Carbon_Fields\Field\Color_Field;
|
||||
use Carbon_Fields\Value_Set\Value_Set;
|
||||
|
||||
/**
|
||||
* @group field
|
||||
* @coversDefaultClass Carbon_Fields\Field\Color_Field
|
||||
*/
|
||||
class ColorFieldTest extends WP_UnitTestCase {
|
||||
public $subject;
|
||||
|
||||
public function setUp(): void {
|
||||
$this->subject = M::mock( 'Carbon_Fields\Field\Color_Field' )->makePartial();
|
||||
}
|
||||
|
||||
public function tearDown(): void {
|
||||
M::close();
|
||||
unset( $this->subject );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::get_palette
|
||||
* @covers ::set_palette
|
||||
*/
|
||||
public function testSetPaletteUpdatesPalette() {
|
||||
$expected1 = array( '#FF0000' );
|
||||
$expected2 = array( '#00FF00' );
|
||||
|
||||
$this->subject->set_palette( $expected1 );
|
||||
$this->assertSame( $expected1, $this->subject->get_palette() );
|
||||
|
||||
$this->subject->set_palette( $expected2 );
|
||||
$this->assertSame( $expected2, $this->subject->get_palette() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::get_alpha_enabled
|
||||
* @covers ::set_alpha_enabled
|
||||
*/
|
||||
public function testSetAlphaEnabledUpdatesAlphaEnabled() {
|
||||
$expected1 = false;
|
||||
$expected2 = true;
|
||||
|
||||
$this->assertSame( $expected1, $this->subject->get_alpha_enabled() );
|
||||
$this->subject->set_alpha_enabled( $expected2 );
|
||||
$this->assertSame( $expected2, $this->subject->get_alpha_enabled() );
|
||||
}
|
||||
}
|
||||
189
web/vendor/htmlburger/carbon-fields/tests/unit-tests/Field/FieldConditionalLogicTest.php
vendored
Normal file
189
web/vendor/htmlburger/carbon-fields/tests/unit-tests/Field/FieldConditionalLogicTest.php
vendored
Normal file
|
|
@ -0,0 +1,189 @@
|
|||
<?php
|
||||
|
||||
use Carbon_Fields\Field\Field;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass Carbon_Fields\Field\Field
|
||||
*/
|
||||
class FieldConditionalLogicTest extends WP_UnitTestCase {
|
||||
private $field;
|
||||
|
||||
public function setUp(): void {
|
||||
$this->field = Field::make( 'text', 'color' );
|
||||
}
|
||||
|
||||
public function tearDown(): void {
|
||||
unset( $this->field );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::set_conditional_logic
|
||||
*
|
||||
* @expectedException Carbon_Fields\Exception\Incorrect_Syntax_Exception
|
||||
* @expectedExceptionMessage should be an array
|
||||
*/
|
||||
public function testErrorIsThrownWhenCondLogicIsNotArray() {
|
||||
$this->field->set_conditional_logic( 'this should actually be array' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::set_conditional_logic
|
||||
*
|
||||
* @expectedException Carbon_Fields\Exception\Incorrect_Syntax_Exception
|
||||
*/
|
||||
public function testErrorIsThrownWhenFlatArrayIsProvided() {
|
||||
$this->field->set_conditional_logic( array(
|
||||
'field' => 'is_product',
|
||||
'value' => 'yes',
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Private helper method for brevity
|
||||
*/
|
||||
public function verify_cond_logic( $user_defined_cond_logic, $expected_parsed_cond_logic ) {
|
||||
$actual_parsed_cond_logic = $this->field
|
||||
->set_conditional_logic( $user_defined_cond_logic )
|
||||
->get_conditional_logic();
|
||||
|
||||
$this->assertEquals(
|
||||
$expected_parsed_cond_logic,
|
||||
$actual_parsed_cond_logic
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::set_conditional_logic
|
||||
* @covers ::get_conditional_logic
|
||||
*/
|
||||
public function testBasicCondLogic() {
|
||||
$user_defined_cond_logic = array(
|
||||
array(
|
||||
'field' => 'is_product',
|
||||
'value' => 'yes',
|
||||
)
|
||||
);
|
||||
|
||||
$expected_parsed_cond_logic = array(
|
||||
'relation' => 'AND',
|
||||
'rules' => array(
|
||||
array(
|
||||
'field' => 'is_product',
|
||||
'value' => 'yes',
|
||||
'compare' => '=',
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->verify_cond_logic(
|
||||
$user_defined_cond_logic,
|
||||
$expected_parsed_cond_logic
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::set_conditional_logic
|
||||
* @covers ::get_conditional_logic
|
||||
*/
|
||||
public function testValueDefaultsToEmptyString() {
|
||||
$user_defined_cond_logic = array(
|
||||
array(
|
||||
'field' => 'is_product',
|
||||
'compare' => '!=',
|
||||
)
|
||||
);
|
||||
|
||||
$expected_parsed_cond_logic = array(
|
||||
'relation' => 'AND',
|
||||
'rules' => array(
|
||||
array(
|
||||
'field' => 'is_product',
|
||||
'value' => '',
|
||||
'compare' => '!=',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->verify_cond_logic(
|
||||
$user_defined_cond_logic,
|
||||
$expected_parsed_cond_logic
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::set_conditional_logic
|
||||
* @covers ::get_conditional_logic
|
||||
*/
|
||||
public function testRelationOperatorIsProvidedInLowercase() {
|
||||
$user_defined_cond_logic = array(
|
||||
'relation' => 'or',
|
||||
array(
|
||||
'field' => 'is_product',
|
||||
'value' => 'yes',
|
||||
)
|
||||
);
|
||||
|
||||
$expected_parsed_cond_logic = array(
|
||||
'relation' => 'OR',
|
||||
'rules' => array(
|
||||
array(
|
||||
'field' => 'is_product',
|
||||
'value' => 'yes',
|
||||
'compare' => '=',
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->verify_cond_logic(
|
||||
$user_defined_cond_logic,
|
||||
$expected_parsed_cond_logic
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::set_conditional_logic
|
||||
*
|
||||
* @expectedException Carbon_Fields\Exception\Incorrect_Syntax_Exception
|
||||
* @expectedExceptionMessage Invalid relation
|
||||
*/
|
||||
public function testBadRelationOperatorThrowsError() {
|
||||
$this->field->set_conditional_logic( array(
|
||||
'relation' => 'maybe',
|
||||
array(
|
||||
'field' => 'is_product',
|
||||
'value' => 'yes',
|
||||
)
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::set_conditional_logic
|
||||
*
|
||||
* @expectedException Carbon_Fields\Exception\Incorrect_Syntax_Exception
|
||||
* @expectedExceptionMessage compare operator
|
||||
*/
|
||||
public function testBadCompareOperatorThrowsError() {
|
||||
$this->field->set_conditional_logic( array(
|
||||
array(
|
||||
'field' => 'is_product',
|
||||
'value' => 'yes',
|
||||
'compare' => '!==' // There is no `!==` operator
|
||||
)
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::set_conditional_logic
|
||||
*
|
||||
* @expectedException Carbon_Fields\Exception\Incorrect_Syntax_Exception
|
||||
* @expectedExceptionMessage An array is expected
|
||||
*/
|
||||
public function testInCompareOperatorRequiresArrayAsValue() {
|
||||
$this->field->set_conditional_logic( array(
|
||||
array(
|
||||
'field' => 'is_product',
|
||||
'value' => 'yes',
|
||||
'compare' => 'IN'
|
||||
)
|
||||
) );
|
||||
}
|
||||
}
|
||||
26
web/vendor/htmlburger/carbon-fields/tests/unit-tests/Field/FieldGetSetIdTest.php
vendored
Normal file
26
web/vendor/htmlburger/carbon-fields/tests/unit-tests/Field/FieldGetSetIdTest.php
vendored
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
/**
|
||||
* @group field
|
||||
* @coversDefaultClass Carbon_Fields\Field\Field
|
||||
*/
|
||||
class FieldGetSetId extends WP_UnitTestCase {
|
||||
public $field;
|
||||
|
||||
public function setUp(): void {
|
||||
$this->field = $this->getMockForAbstractClass( 'Carbon_Fields\Field\Field', array(), '', false );
|
||||
}
|
||||
|
||||
public function tearDown(): void {
|
||||
unset( $this->field );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::get_id
|
||||
* @covers ::set_id
|
||||
*/
|
||||
public function testGetSetId() {
|
||||
$expected = mt_rand();
|
||||
$this->field->set_id( $expected );
|
||||
$this->assertSame( $expected, $this->field->get_id() );
|
||||
}
|
||||
}
|
||||
215
web/vendor/htmlburger/carbon-fields/tests/unit-tests/Field/FieldInitializationTest.php
vendored
Normal file
215
web/vendor/htmlburger/carbon-fields/tests/unit-tests/Field/FieldInitializationTest.php
vendored
Normal file
|
|
@ -0,0 +1,215 @@
|
|||
<?php
|
||||
|
||||
use Carbon_Fields\Field\Field;
|
||||
use Carbon_Fields\Exception\Incorrect_Syntax_Exception;
|
||||
|
||||
/**
|
||||
* @group field
|
||||
* @coversDefaultClass Carbon_Fields\Field\Field
|
||||
*/
|
||||
class FieldInitializationTest extends WP_UnitTestCase {
|
||||
public $fieldName;
|
||||
|
||||
public function setUp(): void {
|
||||
$this->fieldName = '_color';
|
||||
}
|
||||
|
||||
public function tearDown(): void {
|
||||
// This is required just to overwrite code in WP_UnitTestCase
|
||||
// that accesses the database
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::make
|
||||
* @covers ::factory
|
||||
* @covers ::__construct
|
||||
* @covers ::get_name
|
||||
* @covers ::set_name
|
||||
*/
|
||||
public function testMakeTextFields() {
|
||||
$field = Field::make( 'text', $this->fieldName );
|
||||
$this->assertSame( $this->fieldName, $field->get_name() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::make
|
||||
* @covers ::factory
|
||||
* @covers ::__construct
|
||||
*
|
||||
* @expectedException Carbon_Fields\Exception\Incorrect_Syntax_Exception
|
||||
*/
|
||||
public function testExceptionIsThrownWhenFieldTypeIsEmpty() {
|
||||
$field = Field::make( '', $this->fieldName );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::make
|
||||
* @covers ::factory
|
||||
* @covers ::__construct
|
||||
*
|
||||
* @expectedException Carbon_Fields\Exception\Incorrect_Syntax_Exception
|
||||
*/
|
||||
public function testExceptionIsThrownWhenFieldTypeIsInvalid() {
|
||||
$field = Field::make( '__no_such_field_type__', $this->fieldName );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::make
|
||||
* @covers ::factory
|
||||
* @covers ::__construct
|
||||
*/
|
||||
public function testBrokenFieldIsReturnedWhenDebugIsDisabledAndFieldIsInvalid() {
|
||||
$old_val = Incorrect_Syntax_Exception::$throw_errors;
|
||||
|
||||
Incorrect_Syntax_Exception::$throw_errors = false;
|
||||
$field = Field::make( '__no_such_field_type__', $this->fieldName );
|
||||
$this->assertInstanceOf( 'Carbon_Fields\Field\Broken_Field', $field );
|
||||
|
||||
Incorrect_Syntax_Exception::$throw_errors = $old_val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::make
|
||||
* @covers ::factory
|
||||
* @covers ::__construct
|
||||
*
|
||||
* @expectedException Carbon_Fields\Exception\Incorrect_Syntax_Exception
|
||||
*/
|
||||
public function testDashIsNotAllowedInFieldType() {
|
||||
$field = Field::make( 'gravity-form', $this->fieldName );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::make
|
||||
* @covers ::factory
|
||||
* @covers ::__construct
|
||||
*/
|
||||
public function testFieldTypeCaseIsIgnored() {
|
||||
$field = Field::make( 'Text', $this->fieldName );
|
||||
$this->assertInstanceOf( 'Carbon_Fields\Field\Text_Field', $field );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::make
|
||||
* @covers ::factory
|
||||
* @covers ::__construct
|
||||
*/
|
||||
public function testSpacesInFieldTypeAreSupported() {
|
||||
$field = Field::make( 'Gravity Form', $this->fieldName );
|
||||
$this->assertTrue( true ); // no exception ...
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::make
|
||||
* @covers ::factory
|
||||
* @covers ::__construct
|
||||
* @covers ::get_name
|
||||
* @covers ::set_name
|
||||
*/
|
||||
public function testFieldNameIsPrependedWithUnderscoreAutomatically() {
|
||||
$field = Field::make( 'text', 'something' );
|
||||
$this->assertSame( '_something', $field->get_name() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::make
|
||||
* @covers ::factory
|
||||
* @covers ::__construct
|
||||
* @covers ::get_name
|
||||
* @covers ::set_name
|
||||
*
|
||||
* @expectedException Carbon_Fields\Exception\Incorrect_Syntax_Exception
|
||||
*/
|
||||
public function testFieldNameThrowsExceptionOnUpperCaseValues() {
|
||||
$field = Field::make( 'text', 'UPPER_CASE_FIELD_NAME' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::make
|
||||
* @covers ::factory
|
||||
* @covers ::__construct
|
||||
* @covers ::set_name
|
||||
*
|
||||
* @expectedException Carbon_Fields\Exception\Incorrect_Syntax_Exception
|
||||
*/
|
||||
public function testFieldNameThrowsExceptionOnNonEnglishWordCharacters() {
|
||||
$field = Field::make( 'text', '## Even a weirder | name! :)' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::make
|
||||
* @covers ::factory
|
||||
* @covers ::__construct
|
||||
* @covers ::get_name
|
||||
* @covers ::set_name
|
||||
*
|
||||
* @expectedException Carbon_Fields\Exception\Incorrect_Syntax_Exception
|
||||
*/
|
||||
public function testFieldNameThrowsExceptionOnUnicodeValues() {
|
||||
$field = Field::make( 'text', 'bulgarian; България' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::make
|
||||
* @covers ::factory
|
||||
* @covers ::__construct
|
||||
*/
|
||||
public function testLabelIsSetupProperlyWhenPassedExplicitly() {
|
||||
$field = Field::make( 'text', 'color', "Field Color" );
|
||||
$this->assertSame( "Field Color", $field->get_label() );
|
||||
|
||||
// Make sure that non-UTF8 labels are properlly supported
|
||||
$field = Field::make( 'text', 'color', "Цвят" );
|
||||
$this->assertSame( "Цвят", $field->get_label() );
|
||||
|
||||
// Derive the label in proper case
|
||||
$field = Field::make( 'text', 'color_of_something' );
|
||||
$this->assertSame( "Color Of Something", $field->get_label() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::make
|
||||
* @covers ::factory
|
||||
* @covers ::__construct
|
||||
*/
|
||||
public function testLabelIsDerivedProperly() {
|
||||
$field = Field::make( 'text', 'field_color' );
|
||||
$this->assertSame( "Field Color", $field->get_label() );
|
||||
|
||||
$field = Field::make( 'text', '_field_color' );
|
||||
$this->assertSame( "Field Color", $field->get_label() );
|
||||
|
||||
$field = Field::make( 'text', 'crb_field_color' );
|
||||
$this->assertSame( "Field Color", $field->get_label() );
|
||||
|
||||
$field = Field::make('text', '_crb_field_color' );
|
||||
$this->assertSame( "Field Color", $field->get_label() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::make
|
||||
* @covers ::factory
|
||||
* @covers ::__construct
|
||||
* @covers ::set_name
|
||||
*
|
||||
* @expectedException Carbon_Fields\Exception\Incorrect_Syntax_Exception
|
||||
* @expectedExceptionMessage can only contain lowercase alphanumeric characters
|
||||
*/
|
||||
public function testFieldNameCantBeEmpty() {
|
||||
Field::make( 'text', '' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::make
|
||||
* @covers ::factory
|
||||
* @covers ::__construct
|
||||
* @covers ::set_name
|
||||
*
|
||||
* @expectedException Carbon_Fields\Exception\Incorrect_Syntax_Exception
|
||||
* @expectedExceptionMessage can only contain lowercase alphanumeric characters
|
||||
*/
|
||||
public function testFieldNameCantContainHiddenlySupportedBrackets() {
|
||||
Field::make( 'text', 'test_field_with_[brackets]' );
|
||||
}
|
||||
|
||||
}
|
||||
148
web/vendor/htmlburger/carbon-fields/tests/unit-tests/Field/FieldLoadSaveTest.php
vendored
Normal file
148
web/vendor/htmlburger/carbon-fields/tests/unit-tests/Field/FieldLoadSaveTest.php
vendored
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
<?php
|
||||
|
||||
use Mockery as M;
|
||||
use Carbon_Fields\Value_Set\Value_Set;
|
||||
|
||||
/**
|
||||
* @group field
|
||||
* @coversDefaultClass Carbon_Fields\Field\Field
|
||||
*/
|
||||
class FieldLoadSaveTest extends WP_UnitTestCase {
|
||||
public $subject;
|
||||
public $datastore;
|
||||
|
||||
public function setUp(): void {
|
||||
$this->subject = M::mock( 'Carbon_Fields\Field\Field' )->makePartial();
|
||||
$this->subject->set_base_name( 'carbon_field' );
|
||||
$this->subject->set_name( 'carbon_field' );
|
||||
$this->subject->set_label( 'Carbon Field' );
|
||||
|
||||
$this->datastore = M::mock( 'Carbon_Fields\Datastore\Datastore_Interface' );
|
||||
}
|
||||
|
||||
public function tearDown(): void {
|
||||
M::close();
|
||||
unset( $this->subject );
|
||||
unset( $this->datastore );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::set_datastore
|
||||
* @covers ::get_datastore
|
||||
*/
|
||||
public function testGetDatastoreReturnsPreviouslySetDatastore() {
|
||||
$this->subject->set_datastore( $this->datastore );
|
||||
$this->assertSame( $this->datastore, $this->subject->get_datastore() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::set_default_value
|
||||
* @covers ::get_default_value
|
||||
*/
|
||||
public function testGetDefaultValueReturnsPreviouslySetDefaultValue() {
|
||||
$expected = 'test default value';
|
||||
$this->subject->set_default_value( $expected );
|
||||
$this->assertSame( $expected, $this->subject->get_default_value() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::set_value
|
||||
* @covers ::get_value
|
||||
*/
|
||||
public function testGetValueReturnsPreviouslySetValue() {
|
||||
$expected = 'test value';
|
||||
$this->subject->set_value( $expected );
|
||||
$this->assertSame( $expected, $this->subject->get_value() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::load
|
||||
* @covers ::get_value
|
||||
*/
|
||||
public function testLoadAppliesDefaultValueWhenDatastoreReturnsNull() {
|
||||
$expected = 'test default value';
|
||||
$this->datastore->shouldReceive( 'load' )->andReturn( null )->once();
|
||||
|
||||
$this->subject->set_datastore( $this->datastore );
|
||||
$this->subject->set_default_value( $expected );
|
||||
$this->assertSame( $expected, $this->subject->get_value() );
|
||||
$this->subject->load();
|
||||
$this->assertSame( $expected, $this->subject->get_value() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::load
|
||||
* @covers ::get_value
|
||||
*/
|
||||
public function testLoadAppliesTheSameValueWhenDatastoreReturnsValue() {
|
||||
$expected = 'test value from datastore';
|
||||
$this->datastore->shouldReceive( 'load' )->andReturn( array(
|
||||
array(
|
||||
Value_Set::VALUE_PROPERTY => $expected,
|
||||
),
|
||||
) )->once();
|
||||
|
||||
$this->subject->set_datastore( $this->datastore );
|
||||
$this->subject->load();
|
||||
$this->assertSame( $expected, $this->subject->get_value() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::save
|
||||
*/
|
||||
public function testSavePassesFieldToDatastore() {
|
||||
$this->datastore->shouldReceive( 'save' )->once();
|
||||
$this->subject->shouldReceive( 'delete' )->once();
|
||||
$this->subject->set_datastore( $this->datastore );
|
||||
$this->subject->save();
|
||||
$this->assertTrue( true ); // rely on Mockery expectations to fail the test
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::delete
|
||||
*/
|
||||
public function testDeletePassesFieldToDatastore() {
|
||||
$this->datastore->shouldReceive( 'delete' )->once();
|
||||
$this->subject->set_datastore( $this->datastore );
|
||||
$this->subject->delete();
|
||||
$this->assertTrue( true ); // rely on Mockery expectations to fail the test
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::set_value_from_input
|
||||
*/
|
||||
public function testSetValueFromInputTakesValue() {
|
||||
$expected = 'test value from input';
|
||||
$input = array( '_carbon_field' => $expected );
|
||||
$this->subject->set_value_from_input( $input );
|
||||
$this->assertSame( $expected, $this->subject->get_value() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::set_value_from_input
|
||||
*/
|
||||
public function testSetValueFromInputSetsEmptyValueWhenMissingFromInput() {
|
||||
$expected = 'test value from input';
|
||||
$input = array( );
|
||||
$this->subject->set_value_from_input( $input );
|
||||
$this->assertSame( '', $this->subject->get_value() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::get_formatted_value
|
||||
*/
|
||||
public function testGetFormattedValueReturnsValue() {
|
||||
$expected = 'test value from input';
|
||||
$this->subject->set_value( $expected );
|
||||
$this->assertSame( $expected, $this->subject->get_formatted_value() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::get_formatted_value
|
||||
*/
|
||||
public function testGetFormattedValueReturnsDefaultValue() {
|
||||
$expected = 'test value from input';
|
||||
$this->subject->set_default_value( $expected );
|
||||
$this->assertSame( $expected, $this->subject->get_formatted_value() );
|
||||
}
|
||||
}
|
||||
48
web/vendor/htmlburger/carbon-fields/tests/unit-tests/Field/MapFieldTest.php
vendored
Normal file
48
web/vendor/htmlburger/carbon-fields/tests/unit-tests/Field/MapFieldTest.php
vendored
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
use Mockery as M;
|
||||
use Carbon_Fields\Field\Map_Field;
|
||||
use Carbon_Fields\Value_Set\Value_Set;
|
||||
|
||||
/**
|
||||
* @group field
|
||||
* @coversDefaultClass Carbon_Fields\Field\Map_Field
|
||||
*/
|
||||
class MapFieldTest extends WP_UnitTestCase {
|
||||
public $subject;
|
||||
|
||||
public function setUp(): void {
|
||||
$this->subject = M::mock( 'Carbon_Fields\Field\Map_Field' )->makePartial();
|
||||
}
|
||||
|
||||
public function tearDown(): void {
|
||||
M::close();
|
||||
unset( $this->subject );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::set_position
|
||||
*/
|
||||
public function testSetPositionUpdatesDefaultValue() {
|
||||
$clean = array(
|
||||
Value_Set::VALUE_PROPERTY => '',
|
||||
'lat' => 0,
|
||||
'lng' => 0,
|
||||
'zoom' => 0,
|
||||
'address' => '',
|
||||
);
|
||||
$expected = array(
|
||||
Value_Set::VALUE_PROPERTY => '40.346544,-101.645507',
|
||||
'lat' => 40.346544,
|
||||
'lng' => -101.645507,
|
||||
'zoom' => 10,
|
||||
'address' => '',
|
||||
);
|
||||
|
||||
$this->subject->set_position( $clean['lat'], $clean['lng'], $clean['zoom'] );
|
||||
$this->assertSame( $clean, $this->subject->get_default_value() );
|
||||
|
||||
$this->subject->set_position( $expected['lat'], $expected['lng'], $expected['zoom'] );
|
||||
$this->assertSame( $expected, $this->subject->get_default_value() );
|
||||
}
|
||||
}
|
||||
160
web/vendor/htmlburger/carbon-fields/tests/unit-tests/Field/MiscTest.php
vendored
Normal file
160
web/vendor/htmlburger/carbon-fields/tests/unit-tests/Field/MiscTest.php
vendored
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
<?php
|
||||
|
||||
use Mockery as M;
|
||||
use Carbon_Fields\Pimple\Container as PimpleContainer;
|
||||
use Carbon_Fields\Container\Repository as ContainerRepository;
|
||||
use Carbon_Fields\Toolset\Key_Toolset;
|
||||
use Carbon_Fields\Value_Set\Value_Set;
|
||||
use Carbon_Fields\Container\Condition\Factory as ConditionFactory;
|
||||
|
||||
/**
|
||||
* @group field
|
||||
* @coversDefaultClass Carbon_Fields\Field\Field
|
||||
*/
|
||||
class MiscTest extends WP_UnitTestCase {
|
||||
public $text_field;
|
||||
public $set_field;
|
||||
public $complex_field;
|
||||
public $container;
|
||||
|
||||
public function setUp(): void {
|
||||
$ioc = new PimpleContainer();
|
||||
|
||||
$ioc['container_repository'] = function( $ioc ) {
|
||||
return new ContainerRepository();
|
||||
};
|
||||
|
||||
$ioc['key_toolset'] = function() {
|
||||
return new Key_Toolset();
|
||||
};
|
||||
|
||||
$ioc['container_condition_factory'] = function( $ioc ) {
|
||||
return new ConditionFactory( $ioc['container_conditions'] );
|
||||
};
|
||||
|
||||
$ioc['container_condition_translator_array'] = function( $ioc ) {
|
||||
return new \Carbon_Fields\Container\Fulfillable\Translator\Array_Translator( $ioc['container_condition_factory'] );
|
||||
};
|
||||
|
||||
$ioc['container_condition_translator_json'] = function( $ioc ) {
|
||||
return new \Carbon_Fields\Container\Fulfillable\Translator\Json_Translator( $ioc['container_condition_factory'] );
|
||||
};
|
||||
|
||||
$ioc['container_condition_fulfillable_collection'] = $ioc->factory( function( $ioc ) {
|
||||
return M::mock( 'Carbon_Fields\\Container\\Fulfillable\\Fulfillable_Collection' )->shouldIgnoreMissing();
|
||||
} );
|
||||
|
||||
$ioc['container_conditions'] = function() {
|
||||
return new PimpleContainer();
|
||||
};
|
||||
|
||||
\Carbon_Fields\Carbon_Fields::instance()->install( $ioc );
|
||||
|
||||
$this->text_field = Carbon_Fields\Field::make( 'text', 'text_field' );
|
||||
$this->set_field = Carbon_Fields\Field::make( 'set', 'set_field' );
|
||||
$this->complex_field = Carbon_Fields\Field::make( 'complex', 'complex_field' );
|
||||
$this->container = Carbon_Fields\Container::make( 'theme_options', 'Theme Options' );
|
||||
}
|
||||
|
||||
public function tearDown(): void {
|
||||
M::close();
|
||||
unset( $this->text_field );
|
||||
unset( $this->set_field );
|
||||
unset( $this->complex_field );
|
||||
unset( $this->container );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::is_simple_root_field
|
||||
*/
|
||||
public function testIsSimpleRootFieldForUnassignedFields() {
|
||||
$this->assertSame( true, $this->text_field->is_simple_root_field() );
|
||||
$this->assertSame( false, $this->set_field->is_simple_root_field() );
|
||||
$this->assertSame( false, $this->complex_field->is_simple_root_field() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::is_simple_root_field
|
||||
*/
|
||||
public function testIsSimpleRootFieldForRootFields() {
|
||||
$this->container->add_fields( array(
|
||||
$this->text_field,
|
||||
$this->set_field,
|
||||
$this->complex_field,
|
||||
) );
|
||||
$this->assertSame( true, $this->text_field->is_simple_root_field() );
|
||||
$this->assertSame( false, $this->set_field->is_simple_root_field() );
|
||||
$this->assertSame( false, $this->complex_field->is_simple_root_field() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::is_simple_root_field
|
||||
*/
|
||||
public function testIsSimpleRootFieldForNestedFields() {
|
||||
$parent_field = Carbon_Fields\Field::make( 'complex', 'parent_field' );
|
||||
$parent_field->add_fields( array(
|
||||
$this->text_field,
|
||||
$this->set_field,
|
||||
$this->complex_field,
|
||||
) );
|
||||
$this->container->add_fields( array(
|
||||
$parent_field,
|
||||
) );
|
||||
$this->assertSame( false, $this->text_field->is_simple_root_field() );
|
||||
$this->assertSame( false, $this->set_field->is_simple_root_field() );
|
||||
$this->assertSame( false, $this->complex_field->is_simple_root_field() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::get_value_set
|
||||
*/
|
||||
public function testGetValueSetReturnsDefaultValueSet() {
|
||||
$default_value_set = new Value_Set();
|
||||
$this->assertSame( $default_value_set->get_type(), $this->text_field->get_value_set()->get_type() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::get_value_set
|
||||
* @covers ::set_value_set
|
||||
*/
|
||||
public function testSetValueSetOverridesValueSet() {
|
||||
$expected = new Value_Set( Value_Set::TYPE_MULTIPLE_VALUES );
|
||||
$this->text_field->set_value_set( $expected );
|
||||
$this->assertSame( $expected, $this->text_field->get_value_set() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::get_name_prefix
|
||||
* @covers ::set_name_prefix
|
||||
*/
|
||||
public function testSetNamePrefixChangesFieldNameWithEmptyPrefix() {
|
||||
$prefix = '';
|
||||
$expected = $prefix . 'text_field';
|
||||
$this->text_field->set_name_prefix( $prefix );
|
||||
$this->assertSame( $expected, $this->text_field->get_name() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::get_name_prefix
|
||||
* @covers ::set_name_prefix
|
||||
*/
|
||||
public function testSetNamePrefixChangesFieldName() {
|
||||
$prefix = '_zzz_';
|
||||
$expected = $prefix . 'text_field';
|
||||
$this->text_field->set_name_prefix( $prefix );
|
||||
$this->assertSame( $expected, $this->text_field->get_name() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::get_name_prefix
|
||||
* @covers ::set_name_prefix
|
||||
*/
|
||||
public function testSetNamePrefixChangesFieldNameAfterSeveralChanges() {
|
||||
$prefixes = array( 'test1_', 2, 'test3_' );
|
||||
foreach ( $prefixes as $prefix ) {
|
||||
$this->text_field->set_name_prefix( $prefix );
|
||||
}
|
||||
$expected = $prefixes[ count( $prefixes ) - 1 ] . 'text_field';
|
||||
$this->assertSame( $expected, $this->text_field->get_name() );
|
||||
}
|
||||
}
|
||||
294
web/vendor/htmlburger/carbon-fields/tests/unit-tests/Field/PredefinedOptionsFieldTest.php
vendored
Normal file
294
web/vendor/htmlburger/carbon-fields/tests/unit-tests/Field/PredefinedOptionsFieldTest.php
vendored
Normal file
|
|
@ -0,0 +1,294 @@
|
|||
<?php
|
||||
|
||||
use Mockery as M;
|
||||
use Carbon_Fields\Field\Predefined_Options_Field;
|
||||
use Carbon_Fields\Exception\Incorrect_Syntax_Exception;
|
||||
|
||||
/**
|
||||
* @group field
|
||||
* @coversDefaultClass Carbon_Fields\Field\Predefined_Options_Field
|
||||
*/
|
||||
class PredefinedOptionsFieldTest extends WP_UnitTestCase {
|
||||
public $subject;
|
||||
|
||||
public function setUp(): void {
|
||||
$this->subject = M::mock( 'Carbon_Fields\Field\Predefined_Options_Field' )->makePartial();
|
||||
}
|
||||
|
||||
public function tearDown(): void {
|
||||
M::close();
|
||||
unset( $this->subject );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::set_options
|
||||
* @covers ::get_options
|
||||
*/
|
||||
public function testSetAndGetOptions() {
|
||||
$expected = array(1, 2, 3);
|
||||
$this->subject->set_options( $expected );
|
||||
$this->assertSame( $expected, $this->subject->get_options() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::set_options
|
||||
* @covers ::get_options
|
||||
*/
|
||||
public function testSetOptionsResetsPreviousOnes() {
|
||||
$this->subject->set_options( array(1, 2, 3) );
|
||||
|
||||
$expected = array(4, 5, 6);
|
||||
$this->subject->set_options( $expected );
|
||||
|
||||
$this->assertSame( $expected, $this->subject->get_options() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::set_options
|
||||
* @covers ::get_options
|
||||
*/
|
||||
public function testSetEmptyArrayWillDeleteExistingOptions() {
|
||||
$this->subject->set_options( array(1, 2, 3) );
|
||||
|
||||
$expected = array();
|
||||
$this->subject->set_options( $expected );
|
||||
|
||||
$this->assertSame( $expected, $this->subject->get_options() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::set_options
|
||||
* @covers ::get_options
|
||||
*/
|
||||
public function testSetOptionsCallable() {
|
||||
$expected = array(1, 2, 3);
|
||||
$callback = function() use ( $expected ) {
|
||||
return $expected;
|
||||
};
|
||||
|
||||
$this->subject->set_options( $callback );
|
||||
|
||||
$this->assertSame( $expected, $this->subject->get_options() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::set_options
|
||||
*
|
||||
* @expectedException Carbon_Fields\Exception\Incorrect_Syntax_Exception
|
||||
* @expectedExceptionMessage Only arrays and callbacks are allowed in the <code>set_options()</code> method.
|
||||
*/
|
||||
public function testSetOptionsString() {
|
||||
$this->subject->set_options( 'foo' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::set_options
|
||||
*
|
||||
* @expectedException Carbon_Fields\Exception\Incorrect_Syntax_Exception
|
||||
* @expectedExceptionMessage Only arrays and callbacks are allowed in the <code>set_options()</code> method.
|
||||
*/
|
||||
public function testSetOptionsInteger() {
|
||||
$this->subject->set_options( 123 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::set_options
|
||||
*
|
||||
* @expectedException Carbon_Fields\Exception\Incorrect_Syntax_Exception
|
||||
* @expectedExceptionMessage Only arrays and callbacks are allowed in the <code>set_options()</code> method.
|
||||
*/
|
||||
public function testSetOptionsBool() {
|
||||
$this->subject->set_options( false );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::set_options
|
||||
*
|
||||
* @expectedException Carbon_Fields\Exception\Incorrect_Syntax_Exception
|
||||
* @expectedExceptionMessage Only arrays and callbacks are allowed in the <code>set_options()</code> method.
|
||||
*/
|
||||
public function testSetOptionsObject() {
|
||||
$this->subject->set_options( M::mock( 'stdClass' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::add_options
|
||||
* @covers ::get_options
|
||||
*/
|
||||
public function testAddOptionsArray() {
|
||||
$expected = array('foo', 'bar');
|
||||
|
||||
$this->subject->add_options( $expected );
|
||||
|
||||
$this->assertSame( $expected, $this->subject->get_options() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::add_options
|
||||
* @covers ::get_options
|
||||
*/
|
||||
public function testAddOptionsArrayPreservesOtherOptions() {
|
||||
$options_1 = array( 'foo', 'bar' );
|
||||
$options_2 = array( 'foobar', 'barfoo' );
|
||||
$expected = array( 'foo', 'bar', 'foobar', 'barfoo' );
|
||||
|
||||
$this->subject->add_options( $options_1 );
|
||||
$this->subject->add_options( $options_2 );
|
||||
|
||||
$this->assertSame( $expected, $this->subject->get_options() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::add_options
|
||||
* @covers ::get_options
|
||||
*/
|
||||
public function testAddOptionsArrayWithAssociativeArray() {
|
||||
$options_1 = array( 'foo' => 'bar', 'bar' => 'foo' );
|
||||
$options_2 = array( 'foobar' => 'barfoo', 'bar' => 'barbar' );
|
||||
$expected = array( 'foo' => 'bar', 'bar' => 'foo', 'foobar' => 'barfoo', 'bar' => 'barbar' );
|
||||
|
||||
$this->subject->add_options( $options_1 );
|
||||
$this->subject->add_options( $options_2 );
|
||||
|
||||
$this->assertSame( $expected, $this->subject->get_options() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::add_options
|
||||
* @covers ::get_options
|
||||
*/
|
||||
public function testAddOptionsArraysWithNumericAssociativeArrays() {
|
||||
$options_1 = array( 3 => 'Option 1' );
|
||||
$options_2 = array( 9 => 'Option 2' );
|
||||
$expected = array( 3 => 'Option 1', 9 => 'Option 2' );
|
||||
|
||||
$this->subject->add_options( $options_1 );
|
||||
$this->subject->add_options( $options_2 );
|
||||
|
||||
$this->assertSame( $expected, $this->subject->get_options() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::add_options
|
||||
* @covers ::get_options
|
||||
*/
|
||||
public function testAddOptionsArraysWithMixedAssociativeArrays() {
|
||||
$options_1 = array( 0 => 'Option 1' );
|
||||
$options_2 = array( 'foo' => 'Option 2' );
|
||||
$options_3 = array( 1 => 'Option 3' );
|
||||
$expected = array( 0 => 'Option 1', 'foo' => 'Option 2', 1 => 'Option 3' );
|
||||
|
||||
$this->subject->add_options( $options_1 );
|
||||
$this->subject->add_options( $options_2 );
|
||||
$this->subject->add_options( $options_3 );
|
||||
|
||||
$this->assertSame( $expected, $this->subject->get_options() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Possibly a duplicate of other tests but kept for its readability
|
||||
*
|
||||
* @covers ::add_options
|
||||
* @covers ::get_options
|
||||
*/
|
||||
public function testAddOptionsArraysReindex() {
|
||||
$options_1 = array( 0 => 'Option 1' );
|
||||
$options_2 = array( 0 => 'Option 2' );
|
||||
$expected = array( 0 => 'Option 1', 1 => 'Option 2' );
|
||||
|
||||
$this->subject->add_options( $options_1 );
|
||||
$this->subject->add_options( $options_2 );
|
||||
|
||||
$this->assertSame( $expected, $this->subject->get_options() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::add_options
|
||||
* @covers ::get_options
|
||||
*/
|
||||
public function testAddOptionsArraysAppend() {
|
||||
$options_1 = array( 0 => 'Option 1', 1 => 'Option 2' );
|
||||
$options_2 = array( 9 => 'Option 3' );
|
||||
$expected = array( 0 => 'Option 1', 1 => 'Option 2', 9 => 'Option 3' );
|
||||
|
||||
$this->subject->add_options( $options_1 );
|
||||
$this->subject->add_options( $options_2 );
|
||||
|
||||
$this->assertSame( $expected, $this->subject->get_options() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::add_options
|
||||
* @covers ::get_options
|
||||
*/
|
||||
public function testAddOptionsArraysOverwrite() {
|
||||
$options_1 = array( 0 => 'Option 1' );
|
||||
$options_2 = array( 9 => 'Option 2' );
|
||||
$options_3 = array( 0 => 'Option 3' );
|
||||
$expected = array( 0 => 'Option 3', 9 => 'Option 2' );
|
||||
|
||||
$this->subject->add_options( $options_1 );
|
||||
$this->subject->add_options( $options_2 );
|
||||
$this->subject->add_options( $options_3 );
|
||||
|
||||
$this->assertSame( $expected, $this->subject->get_options() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::set_options
|
||||
* @covers ::add_options
|
||||
* @covers ::get_options
|
||||
*/
|
||||
public function testAddOptionsArrayAfterCallable() {
|
||||
$base = array( 1, 2, 3 );
|
||||
$added = array( 4, 5, 6 );
|
||||
$expected = array( 1, 2, 3, 4, 5, 6 );
|
||||
|
||||
$this->subject->set_options( function() use ( $base ) {
|
||||
return $base;
|
||||
} );
|
||||
$this->subject->add_options( $added );
|
||||
$this->assertSame( $expected, $this->subject->get_options() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::add_options
|
||||
*
|
||||
* @expectedException Carbon_Fields\Exception\Incorrect_Syntax_Exception
|
||||
* @expectedExceptionMessage Only arrays and callbacks are allowed in the <code>add_options()</code> method.
|
||||
*/
|
||||
public function testAddOptionsString() {
|
||||
$this->subject->add_options( 'foo' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::add_options
|
||||
*
|
||||
* @expectedException Carbon_Fields\Exception\Incorrect_Syntax_Exception
|
||||
* @expectedExceptionMessage Only arrays and callbacks are allowed in the <code>add_options()</code> method.
|
||||
*/
|
||||
public function testAddOptionsInteger() {
|
||||
$this->subject->add_options( 123 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::add_options
|
||||
*
|
||||
* @expectedException Carbon_Fields\Exception\Incorrect_Syntax_Exception
|
||||
* @expectedExceptionMessage Only arrays and callbacks are allowed in the <code>add_options()</code> method.
|
||||
*/
|
||||
public function testAddOptionsBool() {
|
||||
$this->subject->add_options( false );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::add_options
|
||||
*
|
||||
* @expectedException Carbon_Fields\Exception\Incorrect_Syntax_Exception
|
||||
* @expectedExceptionMessage Only arrays and callbacks are allowed in the <code>add_options()</code> method.
|
||||
*/
|
||||
public function testAddOptionsObject() {
|
||||
$this->subject->add_options( M::mock( 'stdClass' ) );
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue