Skip to content

Commit

Permalink
Introduce Component::setComponents method
Browse files Browse the repository at this point in the history
  • Loading branch information
julienbourdeau committed Dec 17, 2018
1 parent 48fd014 commit 612aaf2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ public function addComponent(self $component, $key = null)
}
}

/**
* Set all Components.
*
* @param array $components The array of Component that will be set
* @param null $key The key of the Component
*/
public function setComponents(array $components)
{
$this->components = $components;

return $this;
}

/**
* Renders an array containing the lines of the iCal file.
*
Expand Down
23 changes: 23 additions & 0 deletions tests/Eluceo/iCal/ComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,29 @@ public function testAddComponentOnKey()
$this->assertContains(str_replace("\n", "\\n", $input), $output);
}

public function testSetComponents()
{
$shouldNotBeFound = 'should-not-be-found';
$vCalendar = new \Eluceo\iCal\Component\Calendar('www.example.com');
$vEvent = new \Eluceo\iCal\Component\Event();
$vEvent->setDtStart(new \DateTime('2014-12-24'));
$vEvent->setDtEnd(new \DateTime('2014-12-24'));
$vEvent->setDescription($shouldNotBeFound);
$vCalendar->addComponent($vEvent);

$shouldBeFound = 'this-should-be-found';
$vEventTwo = new \Eluceo\iCal\Component\Event();
$vEventTwo->setDtStart(new \DateTime('2015-12-24'));
$vEventTwo->setDtEnd(new \DateTime('2015-12-24'));
$vEventTwo->setDescription($shouldBeFound);

$vCalendar->setComponents([$vEventTwo]);

$output = $vCalendar->render();
$this->assertContains($shouldBeFound, $output);
$this->assertNotContains($shouldNotBeFound, $output);
}

public function testToString()
{
$vCalendar = new \Eluceo\iCal\Component\Calendar('www.example.com');
Expand Down

0 comments on commit 612aaf2

Please sign in to comment.