From f49218e0636ef65dbbc217c9e46daadfd0512525 Mon Sep 17 00:00:00 2001 From: NovemLinguae Date: Thu, 30 Dec 2021 08:47:40 -0800 Subject: [PATCH] fix bot responding to pings on non FGTC pages --- src/Helper.php | 5 +-- tests/HelperTest.php | 72 +++++++++++++++++++++++++++++++++++++++++++ tests/PromoteTest.php | 2 ++ 3 files changed, 77 insertions(+), 2 deletions(-) diff --git a/src/Helper.php b/src/Helper.php index c3add19..7ba4e38 100644 --- a/src/Helper.php +++ b/src/Helper.php @@ -1,9 +1,10 @@ h = new Helper(); } + // TODO: add @group for grouping. this is equivlent to Jest's "describe" + function test_insertCodeAtEndOfFirstTemplate_TemplateWithParameters() { $templateNameRegEx = 'Article ?history'; $codeToInsert = '[inserted code]'; @@ -184,4 +186,74 @@ function test_deleteArrayValuesBeginningWith_normal() { ]; $this->assertSame($expected, $result); } + + function test_sliceFirstTemplateFound_normal() { + $wikicode = +"Test +{{Good topic box +| algo = old(120d) +| archive = Wikipedia talk:Featured and good topic candidates/%(year)d +| archiveheader = {{Automatic archive navigator}} +| minthreadstoarchive = 1 +| minthreadsleft = 4 +}} +{{tmbox +|text= '''Questions about a topic you are working on or about the process in general should be asked at [[Wikipedia talk:Featured and good topic questions|Featured and good topic questions]].''' This page is primarily for discussion on proposals regarding the FTC process. +}}"; + $templateName = 'good topic box'; + $result = $this->h->sliceFirstTemplateFound($wikicode, $templateName); + $expected = +"{{Good topic box +| algo = old(120d) +| archive = Wikipedia talk:Featured and good topic candidates/%(year)d +| archiveheader = {{Automatic archive navigator}} +| minthreadstoarchive = 1 +| minthreadsleft = 4 +}}"; + $this->assertSame($expected, $result); + } + + function test_sliceFirstTemplateFound_secondTemplate() { + $wikicode = +"Test +{{tmbox +|text= '''Questions about a topic you are working on or about the process in general should be asked at [[Wikipedia talk:Featured and good topic questions|Featured and good topic questions]].''' This page is primarily for discussion on proposals regarding the FTC process. +}} +{{Good topic box +| algo = old(120d) +| archive = Wikipedia talk:Featured and good topic candidates/%(year)d +| archiveheader = {{Automatic archive navigator}} +| minthreadstoarchive = 1 +| minthreadsleft = 4 +}}"; + $templateName = 'good topic box'; + $result = $this->h->sliceFirstTemplateFound($wikicode, $templateName); + $expected = +"{{Good topic box +| algo = old(120d) +| archive = Wikipedia talk:Featured and good topic candidates/%(year)d +| archiveheader = {{Automatic archive navigator}} +| minthreadstoarchive = 1 +| minthreadsleft = 4 +}}"; + $this->assertSame($expected, $result); + } + + function test_sliceFirstTemplateFound_templateNotFound() { + $wikicode = +"{{User:MiszaBot/config +| algo = old(120d) +| archive = Wikipedia talk:Featured and good topic candidates/%(year)d +| archiveheader = {{Automatic archive navigator}} +| minthreadstoarchive = 1 +| minthreadsleft = 4 +}} +{{tmbox +|text= '''Questions about a topic you are working on or about the process in general should be asked at [[Wikipedia talk:Featured and good topic questions|Featured and good topic questions]].''' This page is primarily for discussion on proposals regarding the FTC process. +}}"; + $templateName = 'good topic box'; + $result = $this->h->sliceFirstTemplateFound($wikicode, $templateName); + $expected = null; + $this->assertSame($expected, $result); + } } \ No newline at end of file diff --git a/tests/PromoteTest.php b/tests/PromoteTest.php index b55c7cf..55248fe 100644 --- a/tests/PromoteTest.php +++ b/tests/PromoteTest.php @@ -11,6 +11,8 @@ function setUp(): void { $this->p = new Promote($eh, $h); } + // TODO: add @group for grouping. this is equivlent to Jest's "describe" + function test_getTopicWikipediaPageTitle_dontWriteToWikipediaGoodTopics() { $mainArticleTitle = 'TestPage'; $goodOrFeatured = 'good';