Skip to content

Commit

Permalink
White space and better loggin
Browse files Browse the repository at this point in the history
  • Loading branch information
GlazerMann authored Dec 27, 2024
1 parent 9c3c4d3 commit e286e2a
Showing 1 changed file with 42 additions and 13 deletions.
55 changes: 42 additions & 13 deletions tests/phpunit/constantsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function testConstantsDefined(): void {
}

public function testConstantsOoops(): void { // Did we forget to upper/lower case one of them?
$pg = new TestPage(); unset($pg); // Fill page name with test name for debugging
for ($i = 0; $i < count(JOURNAL_ACRONYMS); $i++) {
$this->assertNotEquals(trim(JOURNAL_ACRONYMS[$i]), trim(UCFIRST_JOURNAL_ACRONYMS[$i]));
}
Expand All @@ -65,6 +66,7 @@ public function testConstantsOoops(): void { // Did we forget to upper/lower cas
}

public function testForDisasters(): void { // Did we get things out of order and cause a disaster?
$pg = new TestPage(); unset($pg); // Fill page name with test name for debugging
$this->assertSame('BJPsych', title_capitalization('Bjpsych', true));
$this->assertSame('HortScience', title_capitalization('Hortscience', true));
$this->assertSame('TheMarker', title_capitalization('Themarker', true));
Expand All @@ -78,6 +80,7 @@ public function testForDisasters(): void { // Did we get things out of order and
}

public function testImplicitConstants(): void {
$pg = new TestPage(); unset($pg); // Fill page name with test name for debugging
// Consonants
$this->assertSame('X', title_capitalization('x', true));
$this->assertSame('Xz', title_capitalization('xz', true));
Expand All @@ -96,6 +99,7 @@ public function testImplicitConstants(): void {
}

public function testAllLowerCase(): void {
$pg = new TestPage(); unset($pg); // Fill page name with test name for debugging
$big_array = array_merge(HAS_NO_VOLUME, BAD_ACCEPTED_MANUSCRIPT_TITLES, BAD_AUTHORS,
PUBLISHER_ENDINGS, BAD_TITLES, IN_PRESS_ALIASES, NON_PUBLISHERS,
JOURNAL_IS_BOOK_SERIES, HAS_NO_ISSUE, WORKS_ARE_PUBLISHERS, PREFER_VOLUMES,
Expand All @@ -106,6 +110,7 @@ public function testAllLowerCase(): void {
}

public function testMinimized(): void { // See is_book_series() function
$pg = new TestPage(); unset($pg); // Fill page name with test name for debugging
$big_array = JOURNAL_IS_BOOK_SERIES;
foreach ($big_array as $actual) {
$simple = trim(str_replace(['-', '.', ' ', ' ', '[[', ']]'], [' ', ' ', ' ', ' ', ' ', ' '], $actual));
Expand All @@ -115,6 +120,7 @@ public function testMinimized(): void { // See is_book_series() function
}

public function testAllFreeOfUTF(): void { // If this fails, then we have to switch everything to MB_ (BAD_AUTHORS, HAS_NO_ISSUE already has UTF-8)
$pg = new TestPage(); unset($pg); // Fill page name with test name for debugging
$big_array = array_merge(HAS_NO_VOLUME, BAD_ACCEPTED_MANUSCRIPT_TITLES,
PUBLISHER_ENDINGS, BAD_TITLES, IN_PRESS_ALIASES, NON_PUBLISHERS,
JOURNAL_IS_BOOK_SERIES, WORKS_ARE_PUBLISHERS, PREFER_VOLUMES,
Expand All @@ -129,6 +135,7 @@ public function testAllFreeOfUTF(): void { // If this fails, then we have to swi
}

public function testNoSpacesOnEnds(): void {
$pg = new TestPage(); unset($pg); // Fill page name with test name for debugging
$big_array = array_merge(HAS_NO_VOLUME, BAD_ACCEPTED_MANUSCRIPT_TITLES, BAD_AUTHORS,
PUBLISHER_ENDINGS, BAD_TITLES, IN_PRESS_ALIASES, NON_PUBLISHERS,
JOURNAL_IS_BOOK_SERIES, HAS_NO_ISSUE, WORKS_ARE_PUBLISHERS, PREFER_VOLUMES,
Expand All @@ -141,6 +148,7 @@ public function testNoSpacesOnEnds(): void {
}

public function testAtoZ(): void {
$pg = new TestPage(); unset($pg); // Fill page name with test name for debugging
$leader = true;
$start_alpha = '/* The following will be automatically updated to alphabetical order */';
$end_alpha = '/* The above will be automatically updated to alphabetical order */';
Expand Down Expand Up @@ -193,6 +201,7 @@ public function testAtoZ(): void {
}

public function testWhiteList(): void {
$pg = new TestPage(); unset($pg); // Fill page name with test name for debugging
$we_failed = false;
$our_original_whitelist = PARAMETER_LIST;
$our_whitelist = array_unique($our_original_whitelist);
Expand Down Expand Up @@ -252,6 +261,7 @@ public function testWhiteList(): void {
}

public function testWhiteListNotBlacklisted(): void {
$pg = new TestPage(); unset($pg); // Fill page name with test name for debugging
$whitelist = array_merge(DEAD_PARAMETERS, PARAMETER_LIST);
$orig = '';
$new = '';
Expand Down Expand Up @@ -289,6 +299,7 @@ public function testWhiteListNotBlacklisted(): void {
}

public function testDead(): void {
$pg = new TestPage(); unset($pg); // Fill page name with test name for debugging
$overlap = array_intersect(DEAD_PARAMETERS, PARAMETER_LIST);
if (empty($overlap)) {
$this->assertTrue(true);
Expand All @@ -301,6 +312,7 @@ public function testDead(): void {
}

public function testMagazinesAndNot(): void {
$pg = new TestPage(); unset($pg); // Fill page name with test name for debugging
$overlap = array_intersect(ARE_MAGAZINES, ARE_MANY_THINGS);
if (empty($overlap)) {
$this->assertTrue(true);
Expand Down Expand Up @@ -331,6 +343,7 @@ public function testMagazinesAndNot(): void {
}

public function testAuthorsFlat() {
$pg = new TestPage(); unset($pg); // Fill page name with test name for debugging
$failed = false;
$test_flat = [];
foreach (AUTHOR_PARAMETERS as $array) {
Expand Down Expand Up @@ -374,6 +387,7 @@ public function testAuthorsFlat() {
}

public function testNonJournalList() {
$pg = new TestPage(); unset($pg); // Fill page name with test name for debugging
$flat = NON_JOURNAL_WEBSITES;
sort($flat);
$failed = false;
Expand Down Expand Up @@ -409,6 +423,7 @@ public function testNonJournalList() {
}

public function testNonJournalListIsNotBad() {
$pg = new TestPage(); unset($pg); // Fill page name with test name for debugging
$failed = false;
foreach (CANONICAL_PUBLISHER_URLS as $journal) {
$journal = $journal . '/';
Expand Down Expand Up @@ -450,6 +465,7 @@ public function testNonJournalListIsNotBad() {
}

public function testItalicsOrder(): void {
$pg = new TestPage(); unset($pg); // Fill page name with test name for debugging
$in_order = true;
$spaces_at = 99999999;
$max_spaces = 0;
Expand Down Expand Up @@ -497,6 +513,7 @@ public function testItalicsOrder(): void {
}

public function testItalicsNoDuplicates(): void {
$pg = new TestPage(); unset($pg); // Fill page name with test name for debugging
$italics = explode("|", ITALICS_LIST);
sort($italics);
$last = "123412341234";
Expand All @@ -514,6 +531,7 @@ public function testItalicsNoDuplicates(): void {
}

public function testCamelNoDuplicates(): void {
$pg = new TestPage(); unset($pg); // Fill page name with test name for debugging
$italics = CAMEL_CASE;
sort($italics);
$last = "123412341234";
Expand All @@ -532,31 +550,37 @@ public function testCamelNoDuplicates(): void {


public function testItalicsEscaped1(): void {
$italics = str_replace(['\\(', '\\)', '\\.'], '', ITALICS_LIST);
$this->assertSame(0 , substr_count($italics, '('));
$pg = new TestPage(); unset($pg); // Fill page name with test name for debugging
$italics = str_replace(['\\(', '\\)', '\\.'], '', ITALICS_LIST);
$this->assertSame(0 , substr_count($italics, '('));
}
public function testItalicsEscaped2(): void {
$italics = str_replace(['\\(', '\\)', '\\.'], '', ITALICS_LIST);
$this->assertSame(0 , substr_count($italics, ')'));
$pg = new TestPage(); unset($pg); // Fill page name with test name for debugging
$italics = str_replace(['\\(', '\\)', '\\.'], '', ITALICS_LIST);
$this->assertSame(0 , substr_count($italics, ')'));
}
public function testItalicsEscaped3(): void {
$italics = str_replace(['\\(', '\\)', '\\.'], '', ITALICS_LIST);
$this->assertSame(0 , substr_count($italics, '\\'));
$pg = new TestPage(); unset($pg); // Fill page name with test name for debugging
$italics = str_replace(['\\(', '\\)', '\\.'], '', ITALICS_LIST);
$this->assertSame(0 , substr_count($italics, '\\'));
}
public function testItalicsEscaped4(): void {
$italics = str_replace(['\\(', '\\)', '\\.'], '', ITALICS_LIST);
$this->assertSame(0 , substr_count($italics, '.'));
$pg = new TestPage(); unset($pg); // Fill page name with test name for debugging
$italics = str_replace(['\\(', '\\)', '\\.'], '', ITALICS_LIST);
$this->assertSame(0 , substr_count($italics, '.'));
}

public function testItalicsNoSpaces(): void {
public function testItalicsNoSpaces(): void {
$pg = new TestPage(); unset($pg); // Fill page name with test name for debugging
$italics = explode("|", ITALICS_LIST);
foreach ($italics as $item) {
$this->assertNotEquals(' ', substr($item, 0, 1));
$this->assertNotEquals(' ', substr($item, -1));
}
}
}

public function testItalicsHardCode(): void {
public function testItalicsHardCode(): void {
$pg = new TestPage(); unset($pg); // Fill page name with test name for debugging
$this->assertSame(count(ITALICS_HARDCODE_IN), count(ITALICS_HARDCODE_OUT));
for ($i = 0; $i < count(ITALICS_HARDCODE_OUT); $i++) {
$this->assertSame(0, substr_count("'''", ITALICS_HARDCODE_IN[$i]));
Expand All @@ -565,9 +589,9 @@ public function testItalicsHardCode(): void {
$out = str_replace(["'", " ", ':', ',', '.'], ['', '', '', '', ''], ITALICS_HARDCODE_OUT[$i]);
$this->assertSame($in, $out); // Same once spaces and single quotes are removed
}
}
}

public function testConversionsGood(): void {
public function testConversionsGood(): void {
WikipediaBot::make_ch();
$page = new TestPage();
$errors = "";
Expand Down Expand Up @@ -598,6 +622,7 @@ public function testConversionsGood(): void {
}

public function testFreeDOI(): void {
$pg = new TestPage(); unset($pg); // Fill page name with test name for debugging
foreach (DOI_FREE_PREFIX as $prefix) {
$this->assertTrue($prefix != '');
if (strpos($prefix, '/') === false) {
Expand All @@ -607,6 +632,7 @@ public function testFreeDOI(): void {
}

public function testISBNlist(): void {
$pg = new TestPage(); unset($pg); // Fill page name with test name for debugging
$last = -1;
foreach (ISBN_HYPHEN_POS as $k => $v) {
$k = (int) $k;
Expand All @@ -620,18 +646,21 @@ public function testISBNlist(): void {
}

public function testForISBNListUpdates(): void { // https://en.wikipedia.org/w/index.php?title=Module:Format_ISBN/data&action=history
$pg = new TestPage(); unset($pg); // Fill page name with test name for debugging
$wikipedia_response = WikipediaBot::GetAPage('Module:Format_ISBN/data');
$this->assertSame(1, substr_count($wikipedia_response, 'RangeMessage timestamp:'));
$this->assertSame(1, substr_count($wikipedia_response, ISBN_TIME_STAMP_USED));
}

public function testCurlLimit(): void {
$pg = new TestPage(); unset($pg); // Fill page name with test name for debugging
$ch = curl_init();
$this->assertSame(1, curl_limit_page_size($ch, 1, 134217729));
$this->assertSame(0, curl_limit_page_size($ch, 1, 134217728));
}

public function testDoubleMap(): void {
$pg = new TestPage(); unset($pg); // Fill page name with test name for debugging
$errors = '';
$all_maps = array_merge(COMMON_MISTAKES, COMMON_MISTAKES_TOOL);
$okay_to_be_bad = ['coauthors', 'deadurl', 'lay-date', 'lay-source', 'lay-url', 'month', 'authors']; // We upgrade dead paramters to better dead parameters
Expand Down

0 comments on commit e286e2a

Please sign in to comment.