Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Update tests to support gradient themes and test starting year #508

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 28 additions & 9 deletions tests/OptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ public function testThemes(): void
$themes = include "src/themes.php";
foreach ($themes as $theme => $colors) {
$actualColors = getRequestedTheme(["theme" => $theme]);
unset($actualColors["backgroundGradient"]);
$this->assertEquals($colors, $actualColors);
$expectedColors = $colors;
$expectedColors["backgroundGradient"] = "";
if (strpos($colors["background"], ",") !== false) {
$expectedColors["backgroundGradient"] =
"<linearGradient id='gradient' gradientTransform='rotate(45)' gradientUnits='userSpaceOnUse'><stop offset='0%' stop-color='#28EBA2' /><stop offset='100%' stop-color='#0935EB' /></linearGradient>";
$expectedColors["background"] = "url(#gradient)";
}
$this->assertEquals($expectedColors, $actualColors);
}
}

Expand All @@ -46,8 +52,9 @@ public function testFallbackToDefaultTheme(): void
$params = ["theme" => "not a theme name"];
// test that invalid theme name gives default values
$actual = getRequestedTheme($params);
unset($actual["backgroundGradient"]);
$this->assertEquals($this->defaultTheme, $actual);
$expected = $this->defaultTheme;
$expected["backgroundGradient"] = "";
$this->assertEquals($expected, $actual);
}

/**
Expand All @@ -57,7 +64,9 @@ public function testThemesHaveValidParameters(): void
{
// check that all themes contain all parameters and have valid values
$themes = include "src/themes.php";
$hexRegex = "/^#([A-F0-9]{3}|[A-F0-9]{4}|[A-F0-9]{6}|[A-F0-9]{8})$/";
$hexPartialRegex = "(?:[A-F0-9]{3}|[A-F0-9]{4}|[A-F0-9]{6}|[A-F0-9]{8})";
$hexRegex = "/^#{$hexPartialRegex}$/";
$backgroundRegex = "/^#{$hexPartialRegex}|-?\d+(?:,{$hexPartialRegex})+$/";
foreach ($themes as $theme => $colors) {
// check that there are no extra keys in the theme
$this->assertEquals(
Expand All @@ -69,6 +78,15 @@ public function testThemesHaveValidParameters(): void
foreach (array_keys($this->defaultTheme) as $param) {
// check that the key exists
$this->assertArrayHasKey($param, $colors, "The theme '$theme' is missing the key '$param'.");
if ($param === "background") {
// check that the key is a valid background value
$this->assertMatchesRegularExpression(
$backgroundRegex,
$colors[$param],
"The parameter '$param' of '$theme' is not a valid background value."
);
continue;
}
// check that the key is a valid hex color
$this->assertMatchesRegularExpression(
$hexRegex,
Expand Down Expand Up @@ -101,7 +119,7 @@ public function testColorOverrideParameters(): void
$expected = array_merge($expected, [$param => "#f00"]);
// test color change
$actual = getRequestedTheme($params);
unset($actual["backgroundGradient"]);
$expected["backgroundGradient"] = "";
$this->assertEquals($expected, $actual);
}
}
Expand Down Expand Up @@ -129,7 +147,7 @@ public function testValidColorInputs(): void
$expected = array_merge($expected, ["background" => $output]);
// test color change
$actual = getRequestedTheme($params);
unset($actual["backgroundGradient"]);
$expected["backgroundGradient"] = "";
$this->assertEquals($expected, $actual);
}
}
Expand All @@ -150,8 +168,9 @@ public function testInvalidColorInputs(): void
$params = ["background" => $input];
// test that theme is still default
$actual = getRequestedTheme($params);
unset($actual["backgroundGradient"]);
$this->assertEquals($this->defaultTheme, $actual);
$expected = $this->defaultTheme;
$expected["backgroundGradient"] = "";
$this->assertEquals($expected, $actual);
}
}

Expand Down
12 changes: 12 additions & 0 deletions tests/StatsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ public function testValidUsername(): void
}
}

/**
* Test contributions with overriden starting year
*/
public function testOverrideStartingYear(): void
{
$contributionGraphs = getContributionGraphs("DenverCoder1", 2019);
$contributions = getContributionDates($contributionGraphs);
$stats = getContributionStats($contributions);
// test first contribution
$this->assertEquals("2019-01-01", $stats["firstContribution"]);
}

/**
* Test that an invalid username returns 'not found' error
*/
Expand Down