CMB2 Pipes first real functional test

First functional test for the CMB2 Pipes plugin functions.

“Will be difficult”

The one above has been my first thought when thinking about testing the CMB2 Pipes plugin.
I’m trying to intervene somewhere into the working flow of the Custom Meta Boxes 2 plugin to test inputs and outputs; the code base of the plugin is not a small one and it should be difficult.
Turns out it’s not; the Custom Meta Boxes 2 plugin has been developed using tests and it shows: the code is not a side-effect festival and a “where-is-this-coming-from” puzzle and creating the first test for the plugin, after the scaffolding phase is done, was a question of minutes.

First real test

I’ve modified the code of the first functional test case to have a real and valuable test of the plugin functions and the brevity of the set up phase is a testimony to the plug-and-play nature of Custom Meta Boxes 2:

class PostPipingTest extends \WP_UnitTestCase {

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

        // your set up methods here
    }

    public function tearDown() {
        // your tear down methods here

        // then
        parent::tearDown();
    }

    /**
     * @test
     * it should override the meta value when direction reads from post field
     */
    public function it_should_override_the_meta_value_when_direction_reads_from_post_field() {
        // Set up
        $id       = $this->factory->post->create( [ 'post_title' => 'From posts table' ] );            
        $field_id = 'the_post_title';
        update_post_meta( $id, $field_id, 'From meta table' );
        $args  = [
            'object_id'   => $id,
            'object_type' => 'post',
            'field_args'  => [
                'name' => __( 'The post date', 'cmb2' ),
                'id'   => cmb2_pipe( $field_id, '<', 'post_title' ),
                'type' => 'text',
            ]
        ];
        $field = new CMB2_Field( $args );

        // Exercise
        $value = $field->get_data( $field_id );

        // Verify
        $this->assertEquals( 'From posts table', $value );
    }
}

and that’s really all it takes to have a first passing test.
Functional test green

Next

Since I’m testing code I’ve written already I will cover all the functions the plugin now offers and then move to other “pipes” I can easily think of.

I appreciate your input