Skip to content

Commit

Permalink
Enforce priority value to be in the interval [0,1] (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
emanuelmutschlechner authored and freekmurze committed Nov 5, 2018
1 parent 14a3787 commit fb10bca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Tags/Url.php
Expand Up @@ -87,7 +87,7 @@ public function setChangeFrequency(string $changeFrequency)
*/
public function setPriority(float $priority)
{
$this->priority = $priority;
$this->priority = max(0, min(1, $priority));

return $this;
}
Expand Down
12 changes: 12 additions & 0 deletions tests/UrlTest.php
Expand Up @@ -63,6 +63,18 @@ public function priority_can_be_set()
$this->assertEquals(0.1, $this->url->priority);
}

/** @test */
public function priority_is_clamped()
{
$this->url->setPriority(-0.1);

$this->assertEquals(0, $this->url->priority);

$this->url->setPriority(1.1);

$this->assertEquals(1, $this->url->priority);
}

public function change_frequency_can_be_set()
{
$this->url->setChangeFrequency(Url::CHANGE_FREQUENCY_YEARLY);
Expand Down

0 comments on commit fb10bca

Please sign in to comment.