Skip to content

Commit

Permalink
Merge pull request #59 from atiksoftware/3.x
Browse files Browse the repository at this point in the history
Updated Title Entity
  • Loading branch information
butschster committed Apr 9, 2024
2 parents 5e71234 + 92e8d3c commit f11d722
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 16 deletions.
21 changes: 19 additions & 2 deletions src/MetaTags/Entities/Title.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ protected function makeTitle(): string
} else {
$title .= $separator . $this->title;
}

} else if (!empty($this->title)) {
} elseif (!empty($this->title)) {
$title = $this->title;
}

Expand Down Expand Up @@ -108,4 +107,22 @@ public function getTitle(): string
{
return $this->makeTitle();
}

/**
* Get prepends title
* @return array
*/
public function getPrepends(): array
{
return $this->prepend;
}

/**
* Get prepend title
* @return string
*/
public function getPrepend($index = 0): ?string
{
return $this->prepend[$index] ?? null;
}
}
93 changes: 79 additions & 14 deletions tests/MetaTags/TitleMetaTagsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class TitleMetaTagsTest extends TestCase
{
function test_title_can_be_set()
public function test_title_can_be_set()
{
$meta = $this->makeMetaTags()
->setTitle('test title');
Expand All @@ -17,7 +17,7 @@ function test_title_can_be_set()
);
}

function test_get_title()
public function test_get_title()
{
$meta = $this->makeMetaTags()
->setTitle('test title');
Expand All @@ -28,7 +28,7 @@ function test_get_title()
);
}

function test_title_can_be_null()
public function test_title_can_be_null()
{
$meta = $this->makeMetaTags()
->setTitle(null);
Expand All @@ -39,7 +39,7 @@ function test_title_can_be_null()
);
}

function test_title_can_be_prepend()
public function test_title_can_be_prepend()
{
$meta = $this->makeMetaTags()
->setTitle('test title')
Expand All @@ -51,7 +51,7 @@ function test_title_can_be_prepend()
);
}

function test_title_can_be_prepend_as_null_value()
public function test_title_can_be_prepend_as_null_value()
{
$meta = $this->makeMetaTags()
->setTitle('test title')
Expand All @@ -63,7 +63,7 @@ function test_title_can_be_prepend_as_null_value()
);
}

function test_prepend_title_should_be_cleaned()
public function test_prepend_title_should_be_cleaned()
{
$meta = $this->makeMetaTags()
->setTitle('test title')
Expand All @@ -75,7 +75,7 @@ function test_prepend_title_should_be_cleaned()
);
}

function test_title_can_be_prepend_if_title_not_set()
public function test_title_can_be_prepend_if_title_not_set()
{
$meta = $this->makeMetaTags()
->prependTitle('prepend part');
Expand All @@ -86,7 +86,7 @@ function test_title_can_be_prepend_if_title_not_set()
);
}

function test_prepend_separator_can_be_changed()
public function test_prepend_separator_can_be_changed()
{
$meta = $this->makeMetaTags()
->setTitle('test title')
Expand All @@ -99,14 +99,14 @@ function test_prepend_separator_can_be_changed()
);
}

function test_set_title_method_should_be_fluent()
public function test_set_title_method_should_be_fluent()
{
$meta = $this->makeMetaTags();

$this->assertEquals($meta, $meta->setTitle('test title'));
}

function test_title_string_should_be_cleaned()
public function test_title_string_should_be_cleaned()
{
$meta = $this->makeMetaTags()
->setTitle('<h5>test title</h5>');
Expand All @@ -117,15 +117,15 @@ function test_title_string_should_be_cleaned()
);
}

function test_title_can_be_limited()
public function test_title_can_be_limited()
{
$this->assertHtmlableContains(
'<title>test...</title>',
$this->makeMetaTags()->setTitle('test title', 4)
);
}

function test_gets_max_title_length_from_config_by_default()
public function test_gets_max_title_length_from_config_by_default()
{
$config = $this->makeConfig();
$config->shouldReceive('get')->once()->with('meta_tags.title.max_length', null)->andReturn(4);
Expand All @@ -137,7 +137,7 @@ function test_gets_max_title_length_from_config_by_default()
);
}

function test_gets_default_title_separator_from_config_by_default()
public function test_gets_default_title_separator_from_config_by_default()
{
$config = $this->makeConfig();
$config->shouldReceive('get')->twice()->with('meta_tags.title.max_length', null)->andReturn(null);
Expand All @@ -155,7 +155,7 @@ function test_gets_default_title_separator_from_config_by_default()
);
}

function test_converts_to_array()
public function test_converts_to_array()
{
$this->assertEquals(
[
Expand All @@ -165,4 +165,69 @@ function test_converts_to_array()
$this->makeMetaTags()->setTitle('test title')->getTitle()->toArray()
);
}

public function test_get_prepends()
{
$this->assertEquals(
[
'Pre1',
'Pre2',
],
$this->makeMetaTags()
->setTitle('test title')
->prependTitle('Pre1')
->prependTitle('Pre2')
->getTitle()
->getPrepends()
);
}

public function test_get_prepend()
{
$this->assertEquals(
'Pre1',
$this->makeMetaTags()
->setTitle('test title')
->prependTitle('Pre1')
->prependTitle('Pre2')
->getTitle()
->getPrepend(0)
);

$this->assertEquals(
'Pre2',
$this->makeMetaTags()
->setTitle('test title')
->prependTitle('Pre1')
->prependTitle('Pre2')
->getTitle()
->getPrepend(1)
);

$this->assertNull(
$this->makeMetaTags()
->setTitle('test title')
->prependTitle('Pre1')
->prependTitle('Pre2')
->getTitle()
->getPrepend(2)
);

$this->assertEquals(
'Pre1',
$this->makeMetaTags()
->setTitle('test title')
->prependTitle('Pre1')
->prependTitle('Pre2')
->getTitle()
->getPrepend()
);

$this->assertNull(
$this->makeMetaTags()
->setTitle('test title')
->getTitle()
->getPrepend()
);
}
}

0 comments on commit f11d722

Please sign in to comment.