Skip to content

Commit

Permalink
use mb_*
Browse files Browse the repository at this point in the history
  • Loading branch information
veneliniliev committed Aug 5, 2016
1 parent 2e52088 commit a241eea
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
composer.phar
composer.lock
.DS_Store
.idea
10 changes: 5 additions & 5 deletions src/Torann/LaravelMetaTags/MetaTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ private function setTitle($value)

if ($title && $this->config['title_limit']) {
$title = ' - '.$title;
$limit = $this->config['title_limit'] - strlen($title);
$limit = $this->config['title_limit'] - mb_strlen($title);
}
else {
$limit = 'title';
Expand Down Expand Up @@ -297,16 +297,16 @@ private function cut($text, $key)
return $text;
}

$length = strlen($text);
$length = mb_strlen($text);

if ($length <= (int) $limit) {
return $text;
}

$text = substr($text, 0, ($limit -= 3));
$text = mb_substr($text, 0, ($limit -= 3));

if ($space = strrpos($text, ' ')) {
$text = substr($text, 0, $space);
if ($space = mb_strrpos($text, ' ')) {
$text = mb_substr($text, 0, $space);
}

return $text.'...';
Expand Down
52 changes: 26 additions & 26 deletions tests/Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ protected static function text($length)
$base = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$text = '';

while (strlen($text) < $length) {
while (mb_strlen($text) < $length) {
$text .= str_shuffle($base);
}

return substr($text, 0, $length);
return mb_substr($text, 0, $length);
}

public function testMetaTitle()
Expand All @@ -38,7 +38,7 @@ public function testMetaTitle()
$response = $this->Meta->meta('title', $text = self::text(80));

$this->assertNotTrue($text, $response);
$this->assertTrue(strlen($response) === 70);
$this->assertTrue(mb_strlen($response) === 70);
}

public function testMetaDescription()
Expand All @@ -50,7 +50,7 @@ public function testMetaDescription()
$response = $this->Meta->meta('description', $text = self::text(250));

$this->assertNotTrue($text === $response);
$this->assertTrue(strlen($response) === 200);
$this->assertTrue(mb_strlen($response) === 200);
}

public function testMetaTitleWithTitle()
Expand All @@ -66,7 +66,7 @@ public function testMetaTitleWithTitle()
$response = $this->Meta->meta('title', $text = self::text(80));

$this->assertNotTrue($text.' - '.self::$title === $response);
$this->assertTrue(strlen($response) === 70);
$this->assertTrue(mb_strlen($response) === 70);
}

public function testMetaImage()
Expand Down Expand Up @@ -99,8 +99,8 @@ public function testTagTitle()

$tag = $this->Meta->tag('title');

$this->assertTrue(substr_count($tag, '<meta') === 4);
$this->assertTrue(substr_count($tag, 'title"') === 4);
$this->assertTrue(mb_substr_count($tag, '<meta') === 4);
$this->assertTrue(mb_substr_count($tag, 'title"') === 4);
$this->assertTrue(strstr($tag, self::$title) ? true : false);
$this->assertTrue(strstr($tag, $text) ? true : false);
}
Expand All @@ -112,8 +112,8 @@ public function testTagMetaNameTitle()

$tag = $this->Meta->tagMetaName('title');

$this->assertTrue(substr_count($tag, '<meta') === 2);
$this->assertTrue(substr_count($tag, 'title"') === 2);
$this->assertTrue(mb_substr_count($tag, '<meta') === 2);
$this->assertTrue(mb_substr_count($tag, 'title"') === 2);
$this->assertTrue(strstr($tag, self::$title) ? true : false);
$this->assertTrue(strstr($tag, $text) ? true : false);
}
Expand All @@ -125,8 +125,8 @@ public function testTagMetaPropertyTitle()

$tag = $this->Meta->tagMetaProperty('title');

$this->assertTrue(substr_count($tag, '<meta') === 2);
$this->assertTrue(substr_count($tag, 'title"') === 2);
$this->assertTrue(mb_substr_count($tag, '<meta') === 2);
$this->assertTrue(mb_substr_count($tag, 'title"') === 2);
$this->assertTrue(strstr($tag, self::$title) ? true : false);
$this->assertTrue(strstr($tag, $text) ? true : false);
}
Expand All @@ -137,8 +137,8 @@ public function testTagDescription()

$tag = $this->Meta->tag('description');

$this->assertTrue(substr_count($tag, '<meta') === 4);
$this->assertTrue(substr_count($tag, 'description"') === 4);
$this->assertTrue(mb_substr_count($tag, '<meta') === 4);
$this->assertTrue(mb_substr_count($tag, 'description"') === 4);
$this->assertTrue(strstr($tag, $text) ? true : false);
}

Expand All @@ -148,8 +148,8 @@ public function testTagMetaNameDescription()

$tag = $this->Meta->tagMetaName('description');

$this->assertTrue(substr_count($tag, '<meta') === 2);
$this->assertTrue(substr_count($tag, 'description"') === 2);
$this->assertTrue(mb_substr_count($tag, '<meta') === 2);
$this->assertTrue(mb_substr_count($tag, 'description"') === 2);
$this->assertTrue(strstr($tag, $text) ? true : false);
}

Expand All @@ -159,8 +159,8 @@ public function testTagMetaPropertyDescription()

$tag = $this->Meta->tagMetaProperty('description');

$this->assertTrue(substr_count($tag, '<meta') === 2);
$this->assertTrue(substr_count($tag, 'description"') === 2);
$this->assertTrue(mb_substr_count($tag, '<meta') === 2);
$this->assertTrue(mb_substr_count($tag, 'description"') === 2);
$this->assertTrue(strstr($tag, $text) ? true : false);
}

Expand All @@ -170,8 +170,8 @@ public function testTagKeywords()

$tag = $this->Meta->tag('keywords');

$this->assertTrue(substr_count($tag, '<meta') === 2);
$this->assertTrue(substr_count($tag, 'keywords"') === 2);
$this->assertTrue(mb_substr_count($tag, '<meta') === 2);
$this->assertTrue(mb_substr_count($tag, 'keywords"') === 2);
$this->assertTrue(strstr($tag, $text) ? true : false);
}

Expand All @@ -181,8 +181,8 @@ public function testTagMetaNameKeywords()

$tag = $this->Meta->tagMetaName('keywords');

$this->assertTrue(substr_count($tag, '<meta') === 1);
$this->assertTrue(substr_count($tag, 'keywords"') === 1);
$this->assertTrue(mb_substr_count($tag, '<meta') === 1);
$this->assertTrue(mb_substr_count($tag, 'keywords"') === 1);
$this->assertTrue(strstr($tag, $text) ? true : false);
}

Expand All @@ -192,8 +192,8 @@ public function testTagMetaPropertyKeywords()

$tag = $this->Meta->tagMetaProperty('keywords');

$this->assertTrue(substr_count($tag, '<meta') === 1);
$this->assertTrue(substr_count($tag, 'keywords"') === 1);
$this->assertTrue(mb_substr_count($tag, '<meta') === 1);
$this->assertTrue(mb_substr_count($tag, 'keywords"') === 1);
$this->assertTrue(strstr($tag, $text) ? true : false);
}

Expand All @@ -205,8 +205,8 @@ public function testTagImage()

$tag = $this->Meta->tag('image');

$this->assertTrue(substr_count($tag, '<meta') === 20);
$this->assertTrue(substr_count($tag, '<link') === 5);
$this->assertTrue(substr_count($tag, 'image') === 25);
$this->assertTrue(mb_substr_count($tag, '<meta') === 20);
$this->assertTrue(mb_substr_count($tag, '<link') === 5);
$this->assertTrue(mb_substr_count($tag, 'image') === 25);
}
}

0 comments on commit a241eea

Please sign in to comment.