Skip to content

Commit

Permalink
Menu, Link & LinkContainer > add getters (to get content)
Browse files Browse the repository at this point in the history
  • Loading branch information
meritoo committed May 12, 2019
1 parent ec8b9e4 commit 0dd0e3c
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Build navigation easily, without any efforts. Library that provides tools to bui
# 0.0.5

1. Minor refactoring
2. Menu, Link & LinkContainer > add getters (to get content)

# 0.0.4

Expand Down
20 changes: 20 additions & 0 deletions src/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@ public function __construct(string $name, string $url)
$this->url = $url;
}

/**
* Returns name of link
*
* @return string
*/
public function getName(): string
{
return $this->name;
}

/**
* Returns url of link
*
* @return string
*/
public function getUrl(): string
{
return $this->url;
}

/**
* {@inheritdoc}
*/
Expand Down
10 changes: 10 additions & 0 deletions src/LinkContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ public function __construct(Link $link)
$this->link = $link;
}

/**
* Returns container's link
*
* @return Link
*/
public function getLink(): Link
{
return $this->link;
}

/**
* Creates new container for a link
*
Expand Down
10 changes: 10 additions & 0 deletions src/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ public function __construct(array $linksContainers)
$this->linksContainers = $linksContainers;
}

/**
* Returns containers with links
*
* @return LinkContainer[]
*/
public function getLinksContainers(): array
{
return $this->linksContainers;
}

/**
* Creates new menu
*
Expand Down
33 changes: 33 additions & 0 deletions tests/LinkContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,18 @@ public function testCreate(
static::assertEquals($expected, $linkContainer, $description);
}

/**
* @param string $description Description of test
* @param LinkContainer $container Container for a link
* @param Link $expected Expected link
*
* @dataProvider provideContainerToGetLink
*/
public function testGetLink(string $description, LinkContainer $container, Link $expected): void
{
static::assertEquals($expected, $container->getLink(), $description);
}

public function provideDataToCreate(): ?Generator
{
$linkAttributes = [
Expand Down Expand Up @@ -304,4 +316,25 @@ public function provideDataToCreate(): ?Generator
$linkContainerAttributes,
];
}

public function provideContainerToGetLink(): ?Generator
{
yield[
'An empty name and url of link',
new LinkContainer(new Link('', '')),
new Link('', ''),
];

yield[
'Not empty name and empty url of link',
new LinkContainer(new Link('Test', '')),
new Link('Test', ''),
];

yield[
'Container created using static method create()',
LinkContainer::create('Test', ''),
new Link('Test', ''),
];
}
}
66 changes: 66 additions & 0 deletions tests/LinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,30 @@ public function testAddAttributes(): void
static::assertEquals($expected, $existing);
}

/**
* @param string $description Description of test
* @param Link $link The link
* @param string $expected Expected name
*
* @dataProvider provideLinkToGetName
*/
public function testGetName(string $description, Link $link, string $expected): void
{
static::assertSame($expected, $link->getName(), $description);
}

/**
* @param string $description Description of test
* @param Link $link The link
* @param string $expected Expected url
*
* @dataProvider provideLinkToGetUrl
*/
public function testGetUrl(string $description, Link $link, string $expected): void
{
static::assertSame($expected, $link->getUrl(), $description);
}

public function provideIncompleteTemplates(): ?Generator
{
$template = 'Template with \'%s\' index was not found. Did you provide all required templates?';
Expand Down Expand Up @@ -193,4 +217,46 @@ public function provideTemplatesAndLinkToRender(): ?Generator
'<a href="/" id="main-link" data-position="12">Test 2</a>',
];
}

public function provideLinkToGetName(): ?Generator
{
yield[
'An empty name and url',
new Link('', ''),
'',
];

yield[
'Not empty name and empty url',
new Link('Test', ''),
'Test',
];

yield[
'Not empty name and not empty url',
new Link('Test', '/'),
'Test',
];
}

public function provideLinkToGetUrl(): ?Generator
{
yield[
'An empty name and url',
new Link('', ''),
'',
];

yield[
'Not empty name and empty url',
new Link('Test', ''),
'',
];

yield[
'Not empty name and not empty url',
new Link('Test', '/'),
'/',
];
}
}
61 changes: 61 additions & 0 deletions tests/MenuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ public function testConstructor(): void
);
}

/**
* @param string $description Description of test
* @param Menu $menu Menu to verify
* @param array $expected Expected containers with links
*
* @dataProvider provideMenuToGetLinksContainers
*/
public function testGetLinksContainers(string $description, Menu $menu, array $expected): void
{
static::assertEquals($expected, $menu->getLinksContainers(), $description);
}

public function testRenderWithoutLinksContainers(): void
{
$menu = new Menu([]);
Expand Down Expand Up @@ -536,4 +548,53 @@ public function provideLinksContainersToCreateWithAttributes(): ?Generator
$menu2Attributes,
];
}

public function provideMenuToGetLinksContainers(): ?Generator
{
yield[
'No containers',
new Menu([]),
[],
];

yield[
'1 container only',
new Menu([
new LinkContainer(new Link('', '')),
]),
[
new LinkContainer(new Link('', '')),
],
];

yield[
'2 containers',
new Menu([
new LinkContainer(new Link('Test 1', '')),
new LinkContainer(new Link('Test 2', '/')),
]),
[
new LinkContainer(new Link('Test 1', '')),
new LinkContainer(new Link('Test 2', '/')),
],
];

yield[
'2 containers - created by static method create()',
Menu::create([
[
'Test 1',
'',
],
[
'Test 2',
'/',
],
]),
[
new LinkContainer(new Link('Test 1', '')),
new LinkContainer(new Link('Test 2', '/')),
],
];
}
}

0 comments on commit 0dd0e3c

Please sign in to comment.