View Issue Details

IDProjectCategoryView StatusLast Update
0022231mantisbtmarkdownpublic2024-04-14 07:39
Reportervboctor Assigned Todregad  
PrioritynormalSeverityminorReproducibilityN/A
Status resolvedResolutionfixed 
Product Version2.1.0 
Target Version2.27.0Fixed in Version2.27.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

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.

Related Changesets

MantisBT: master 8b23f272

2024-03-27 09:47

grummbeer

Committer: dregad


Details Diff
Add tests for MantisCoreFormatting plugin

Fixes 0022231, PR https://github.com/mantisbt/mantisbt/pull/1976
Affected Issues
0022231
mod - phpunit.xml Diff File
mod - plugins/MantisCoreFormatting/tests/MarkdownTest.php Diff File

MantisBT: master 3aec6e68

2024-03-31 23:15

grummbeer

Committer: dregad


Details Diff
Clean up markdown processing

- Process input via Markdownparser and return the result, no further
text processing.
- During parsing, catch all <code> blocks and replace them with a hash
value.
- After the markup is returned from Parsedown, apply mentions and links
- Restore the untouched <code> Blocks back in place.

Fixes 0034040, PR https://github.com/mantisbt/mantisbt/pull/1976
Also fixes 0022315, 0022320, 0024241, 0024628, 0024810, 0022231, 0023738

Signed-off-by: Damien Regad <dregad@mantisbt.org>
Affected Issues
0022231, 0022315, 0022320, 0023738, 0024241, 0024628, 0024810, 0034040, 0034393
mod - plugins/MantisCoreFormatting/MantisCoreFormatting.php Diff File
mod - plugins/MantisCoreFormatting/core/MantisMarkdown.php Diff File