View Issue Details

IDProjectCategoryView StatusLast Update
0022231mantisbtmarkdownpublic2017-02-01 08:31
Reportervboctor Assigned Tojoel  
PrioritynormalSeverityminorReproducibilityN/A
Status assignedResolutionopen 
Product Version2.1.0 
Summary0022231: Fix unit tests for markdown
Description

We need to revise unit tests for Markdown to:

  1. Make sure they always run as part of MantisBT tests that run in Travis.
  2. Make sure they test the production code vis string_* methods rather than markdown specific code.
  3. Make sure they are in sync with latest production expected results.
TagsNo tags attached.

Relationships

child of 0022180 new Markdown issues following implementation in 0017920 

Activities

joel

joel

2017-01-31 10:07

developer   ~0055424

Last edited: 2017-01-31 10:38

View 5 revisions

I'm having an issue of including the helper methods in my tests suites:

phpunit plugins/MantisCoreFormatting/tests/MarkdownTest.php

    /**
     * Mantis Text, Bug/Notes and Mention link Processing
     *
     * @return string Formatted text
     */
    private function textBugNoteMentionLinksProcess ( $p_string ) {

        $t_string = $p_string;

        # Text processing
        $t_string = string_strip_hrefs( $t_string );
        $t_string = string_html_specialchars( $t_string );
        $t_string = string_restore_valid_html_tags( $t_string, true );

        # Bug and Notes processing
        $t_string = string_process_bug_link( $t_string );
        $t_string = string_process_bugnote_link( $t_string );

        # Mention processing
        $t_string = mention_format_text( $t_string, true );

        return $t_string;
    }

    /**
     * Test If string starts with hash(#) symbol
     *
     * @return void
     */
    public function testHash() {

        $t_expected_string = '<h1>hello</h1>';

        # followed by letter
        $t_input_string = '#hello';
        $t_process_string = $this->textBugNoteMentionLinksProcess( $t_input_string );
        $this->assertEquals( $t_expected_string, MantisMarkdown::convert_text( $t_process_string ) );

        # followed by space
        $t_input_string = '# hello';
        $t_process_string = $this->textBugNoteMentionLinksProcess( $t_input_string );
        $this->assertEquals( $t_expected_string, MantisMarkdown::convert_text( $t_process_string ) );

        # followed by numeric
        $t_input_string = #[1];

        $t_process_string = $this->textBugNoteMentionLinksProcess( $t_input_string );

        $this->assertEquals( $t_expected_string, MantisMarkdown::convert_text( $t_process_string ) );
    }

I'm referring with the Bug and Notes processing methods:

# Bug and Notes processing
$t_string = string_process_bug_link( $t_string );
$t_string = string_process_bugnote_link( $t_string );

A Fatal error: Call to a member function Param() on null in /core/database_api.php on line 85

It seems that the helper methods is asking a db connection though. right?

Q? is there a way to inject any required dependencies (autoloading) from the console? phpunit plugins/MantisCoreFormatting/tests/MarkdownTest.php

dregad

dregad

2017-02-01 03:59

developer   ~0055429

I'm sorry I don't have time to look into this right now, but I suggest you check out how it's done for other API tests (in tests/Mantis/).

Since this is a core plugin, I would also suggest you put your tests there in the tests/Mantis/ directory, and not in a plugin-specific dir.

Finally, I recommend you refactor your testHash() function to remove code duplication by using a PHPUnit data provider function. see example and reference documentation.

joel

joel

2017-02-01 08:31

developer   ~0055437

Thank you @dregad, I was just confused why there is logic to check from the database if( bug_exists( $c_bug_id ) ) line 351 in string_api->string_process_bug_link. I was thinking that the helper method would just process the link without checking the database if bug exist or not (the helper method is hard to tests with that setup). I would suggest to inject the dependency instead.

Since this is a core plugin, I would also suggest you put your tests there in the tests/Mantis/ directory, and not in a plugin-specific dir.

right, will move it to tests/Mantis directory.

Finally, I recommend you refactor your testHash() function to remove code duplication by using a PHPUnit data provider function. see example and reference documentation.

right.

Issue History

Date Modified Username Field Change
2017-01-22 18:15 vboctor New Issue
2017-01-22 18:18 vboctor Relationship added child of 0022180
2017-01-23 02:59 joel Assigned To => joel
2017-01-23 02:59 joel Status new => assigned
2017-01-31 10:07 joel Note Added: 0055424
2017-01-31 10:27 joel Note Edited: 0055424 View Revisions
2017-01-31 10:28 joel Note Edited: 0055424 View Revisions
2017-01-31 10:29 joel Note Edited: 0055424 View Revisions
2017-01-31 10:38 joel Note Edited: 0055424 View Revisions
2017-02-01 03:59 dregad Note Added: 0055429
2017-02-01 08:31 joel Note Added: 0055437