Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 153 additions & 0 deletions tests/phpunit/entries/test_FrmEntryMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,159 @@ public function test_update_entry_metas() {
$this->assertNull( $meta );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmEntryMeta::assertNull()


The method you are trying to call is not defined, which can result in a fatal error.

}

/**
* A text field leaves a non-numeric value alone while a number field coerces it to a float,
* so the pair tells us which field packed a given value.
*
* @return array The form, the text field id and the number field id.
*/
private function create_text_and_number_fields() {
$form = $this->factory->form->create_and_get();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Access to an undefined property test_FrmEntryMeta::$factory


The property you are trying to access is not defined and will cause unexpected behavior when used.


$text_field_id = $this->factory->field->create(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Access to an undefined property test_FrmEntryMeta::$factory


The property you are trying to access is not defined and will cause unexpected behavior when used.

array(
'form_id' => $form->id,
'type' => 'text',
'field_key' => 'meta_text_' . $form->id,
)
);

$number_field_id = $this->factory->field->create(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Access to an undefined property test_FrmEntryMeta::$factory


The property you are trying to access is not defined and will cause unexpected behavior when used.

array(
'form_id' => $form->id,
'type' => 'number',
'field_key' => 'meta_number_' . $form->id,
)
);

return array( $form, $text_field_id, $number_field_id );
}

/**
* The field argument has to stay optional. add_entry_meta() and update_entry_meta() are
* called with four arguments from dozens of places across the add-ons, and those callers
* ship on their own release cycles.
*
* @covers FrmEntryMeta::add_entry_meta
* @covers FrmEntryMeta::update_entry_meta
*/
public function test_entry_meta_writers_still_accept_four_arguments() {
foreach ( array( 'add_entry_meta', 'update_entry_meta' ) as $method ) {
$reflection = new ReflectionMethod( 'FrmEntryMeta', $method );
$this->assertSame( 4, $reflection->getNumberOfRequiredParameters(), $method . '() should keep exactly four required parameters.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmEntryMeta::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

}

list( $form, $text_field_id ) = $this->create_text_and_number_fields();

$entry_id = $this->factory->entry->create( $this->factory->field->generate_entry_array( $form ) );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Access to an undefined property test_FrmEntryMeta::$factory


The property you are trying to access is not defined and will cause unexpected behavior when used.


FrmEntryMeta::update_entry_meta( $entry_id, $text_field_id, '', 'Updated with four arguments' );

$stored = FrmEntryMeta::get_entry_meta_by_field( $entry_id, $text_field_id );
$this->assertSame( 'Updated with four arguments', $stored, 'A four argument update should still store the value.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmEntryMeta::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

}

/**
* The loop in update_entry_metas() hands each writer the field it loaded for that value.
* Packing two field types in one call proves each value is packed with its own field, rather
* than one iteration's field leaking into the next.
*
* @covers FrmEntryMeta::update_entry_metas
*/
public function test_update_entry_metas_packs_each_existing_value_with_its_own_field() {
list( $form, $text_field_id, $number_field_id ) = $this->create_text_and_number_fields();

$entry_id = $this->factory->entry->create( $this->factory->field->generate_entry_array( $form ) );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Access to an undefined property test_FrmEntryMeta::$factory


The property you are trying to access is not defined and will cause unexpected behavior when used.


FrmEntryMeta::update_entry_metas(
$entry_id,
array(
$text_field_id => 'abc',
$number_field_id => 'abc',
)
);

$this->assertSame( 'abc', FrmEntryMeta::get_entry_meta_by_field( $entry_id, $text_field_id ), 'The text field should keep a non-numeric value as typed.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmEntryMeta::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

$this->assertSame( '0', FrmEntryMeta::get_entry_meta_by_field( $entry_id, $number_field_id ), 'The number field should coerce a non-numeric value to zero.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmEntryMeta::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

}

/**
* The same has to hold on the insert path, which runs for any field that has no row on the
* entry yet. That is every field on a later page of a multi-page form.
*
* @covers FrmEntryMeta::update_entry_metas
*/
public function test_update_entry_metas_packs_each_new_value_with_its_own_field() {
$form = $this->factory->form->create_and_get();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Access to an undefined property test_FrmEntryMeta::$factory


The property you are trying to access is not defined and will cause unexpected behavior when used.


$this->factory->field->create(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Access to an undefined property test_FrmEntryMeta::$factory


The property you are trying to access is not defined and will cause unexpected behavior when used.

array(
'form_id' => $form->id,
'type' => 'text',
'field_key' => 'meta_seed_' . $form->id,
)
);

// Created before the fields below, so neither of them has a row on this entry yet.
$entry_id = $this->factory->entry->create( $this->factory->field->generate_entry_array( $form ) );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Access to an undefined property test_FrmEntryMeta::$factory


The property you are trying to access is not defined and will cause unexpected behavior when used.


$text_field_id = $this->factory->field->create(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Access to an undefined property test_FrmEntryMeta::$factory


The property you are trying to access is not defined and will cause unexpected behavior when used.

array(
'form_id' => $form->id,
'type' => 'text',
'field_key' => 'meta_new_text_' . $form->id,
)
);

$number_field_id = $this->factory->field->create(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Access to an undefined property test_FrmEntryMeta::$factory


The property you are trying to access is not defined and will cause unexpected behavior when used.

array(
'form_id' => $form->id,
'type' => 'number',
'field_key' => 'meta_new_number_' . $form->id,
)
);

$this->assertNull( FrmEntryMeta::get_entry_meta_by_field( $entry_id, $number_field_id ), 'The number field should have no row before the update.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmEntryMeta::assertNull()


The method you are trying to call is not defined, which can result in a fatal error.


FrmEntryMeta::update_entry_metas(
$entry_id,
array(
$text_field_id => 'abc',
$number_field_id => 'abc',
)
);

$this->assertSame( 'abc', FrmEntryMeta::get_entry_meta_by_field( $entry_id, $text_field_id ), 'A newly inserted text value should be stored as typed.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmEntryMeta::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

$this->assertSame( '0', FrmEntryMeta::get_entry_meta_by_field( $entry_id, $number_field_id ), 'A newly inserted number value should be coerced to zero.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmEntryMeta::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

}

/**
* Values can be keyed by field key instead of field id, in which case the field handed to the
* writers is the one resolved from that key. A mix of both keying styles in one call has to
* still pack every value with the right field.
*
* @covers FrmEntryMeta::update_entry_metas
*/
public function test_update_entry_metas_packs_values_keyed_by_field_key_with_the_resolved_field() {
list( $form, $text_field_id, $number_field_id ) = $this->create_text_and_number_fields();

$entry_id = $this->factory->entry->create( $this->factory->field->generate_entry_array( $form ) );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Access to an undefined property test_FrmEntryMeta::$factory


The property you are trying to access is not defined and will cause unexpected behavior when used.


FrmEntryMeta::update_entry_metas(
$entry_id,
array(
FrmField::get_key_by_id( $text_field_id ) => 'abc',
$number_field_id => 'abc',
)
);

$stored_text = FrmEntryMeta::get_entry_meta_by_field( $entry_id, $text_field_id );
$stored_number = FrmEntryMeta::get_entry_meta_by_field( $entry_id, $number_field_id );

$this->assertSame( 'abc', $stored_text, 'A value keyed by field key should be packed with the text field it resolves to.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmEntryMeta::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

$this->assertSame( '0', $stored_number, 'A value keyed by field id alongside it should still be packed with the number field.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmEntryMeta::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

}

/**
* @covers FrmEntryMeta::should_join_fields_table
*/
Expand Down
Loading