Skip to content

Commit

Permalink
refactor test to use data provider
Browse files Browse the repository at this point in the history
  • Loading branch information
cmgmyr committed Jan 25, 2019
1 parent fc664b7 commit 64efe41
Showing 1 changed file with 118 additions and 114 deletions.
232 changes: 118 additions & 114 deletions tests/TitleFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,121 +6,125 @@

class TitleFormatterTest extends TestCase
{
protected $tests = [
[
// tests single sentence with mid-word special character
'title' => 'this sh*t is a test',
'correct' => 'This Sh*t is a Test',
],
[
// tests multiple sentences
'title' => 'is this sh*t is a test. for sure!!!',
'correct' => 'Is This Sh*t is a Test. For Sure!!!',
],
[
// tests sentences in brackets
'title' => 'is this sh*t is a test. for sure. [yikes as example]',
'correct' => 'Is This Sh*t is a Test. For Sure. [Yikes as Example]',
],
[
// tests dashed words
'title' => 'this should be a super-awesome post! cool? not-so-much!',
'correct' => 'This Should Be a Super-Awesome Post! Cool? Not-So-Much!',
],
[
// tests sentence with extra spaces
'title' => ' this should be interesting ',
'correct' => 'This Should Be Interesting',
],
[
// tests simple sentence
'title' => 'very simple sentence',
'correct' => 'Very Simple Sentence',
],
[
// tests to make sure last word is capitalized
'title' => 'very simple sentence of',
'correct' => 'Very Simple Sentence Of',
],
[
// tests words that have capital letters, they should be ignored
'title' => 'i think eBay is the greatest site! also, McCormick has the best spices!',
'correct' => 'I Think eBay is the Greatest Site! Also, McCormick Has the Best Spices!',
],
[
// tests words with multiple punctuation prefixes
'title' => 'this post is $$$money',
'correct' => 'This Post is $$$Money',
],
[
// tests for all CAPS words, they should be ignored
'title' => 'i really like playing with LEGOS, they are a lot of fun!',
'correct' => 'I Really Like Playing With LEGOS, They Are a Lot of Fun!',
],
[
// tests for a bug in first words with apostrophes, should not capitalize second letter
'title' => 'it\'s really- something, isn\'t it?',
'correct' => 'It\'s Really- Something, Isn\'t It?',
],
[
// tests for a bug with a dash separator
'title' => 'test - jet fighters',
'correct' => 'Test - Jet Fighters',
],
[
// tests for a bug with multiple separators
'title' => 'test --- jet-- fighters - test ==== testtest',
'correct' => 'Test --- Jet-- Fighters - Test ==== Testtest',
],
[
// tests numbers only
'title' => '1234 567',
'correct' => '1234 567',
],
[
// tests colon
'title' => 'this is a test: cool, huh?',
'correct' => 'This is a Test: Cool, Huh?',
],
[
// tests for a bug with empty title
'title' => '',
'correct' => '',
],
[
// tests for a bug with null title
'title' => null,
'correct' => '',
],
[
// tests for a bug with all spaces
'title' => ' ',
'correct' => '',
],
[
// tests for a bug with all spaces, one word
'title' => ' test',
'correct' => 'Test',
],
[
// tests one word
'title' => 'test',
'correct' => 'Test',
],
[
// tests for a bug with special characters
'title' => 'get up and dance — 7 reasons why you should be… moving your feet to the beat',
'correct' => 'Get Up and Dance — 7 Reasons Why You Should Be… Moving Your Feet to the Beat',
],
];

/** @test */
public function it_should_format_titles_correctly()
/**
* @test
* @dataProvider titleProvider
* @param string $initial
* @param string $expected
*/
public function it_should_format_titles_correctly($initial, $expected)
{
foreach ($this->tests as $test) {
$newTitle = TitleFormatter::titleCase($test['title']);
$this->assertEquals($expected, TitleFormatter::titleCase($initial));
}

$this->assertEquals($test['correct'], $newTitle);
}
public function titleProvider()
{
return [
[
// tests single sentence with mid-word special character
'this sh*t is a test',
'This Sh*t is a Test',
],
[
// tests multiple sentences
'is this sh*t is a test. for sure!!!',
'Is This Sh*t is a Test. For Sure!!!',
],
[
// tests sentences in brackets
'is this sh*t is a test. for sure. [yikes as example]',
'Is This Sh*t is a Test. For Sure. [Yikes as Example]',
],
[
// tests dashed words
'this should be a super-awesome post! cool? not-so-much!',
'This Should Be a Super-Awesome Post! Cool? Not-So-Much!',
],
[
// tests sentence with extra spaces
' this should be interesting ',
'This Should Be Interesting',
],
[
// tests simple sentence
'very simple sentence',
'Very Simple Sentence',
],
[
// tests to make sure last word is capitalized
'very simple sentence of',
'Very Simple Sentence Of',
],
[
// tests words that have capital letters, they should be ignored
'i think eBay is the greatest site! also, McCormick has the best spices!',
'I Think eBay is the Greatest Site! Also, McCormick Has the Best Spices!',
],
[
// tests words with multiple punctuation prefixes
'this post is $$$money',
'This Post is $$$Money',
],
[
// tests for all CAPS words, they should be ignored
'i really like playing with LEGOS, they are a lot of fun!',
'I Really Like Playing With LEGOS, They Are a Lot of Fun!',
],
[
// tests for a bug in first words with apostrophes, should not capitalize second letter
'it\'s really- something, isn\'t it?',
'It\'s Really- Something, Isn\'t It?',
],
[
// tests for a bug with a dash separator
'test - jet fighters',
'Test - Jet Fighters',
],
[
// tests for a bug with multiple separators
'test --- jet-- fighters - test ==== testtest',
'Test --- Jet-- Fighters - Test ==== Testtest',
],
[
// tests numbers only
'1234 567',
'1234 567',
],
[
// tests colon
'this is a test: cool, huh?',
'This is a Test: Cool, Huh?',
],
[
// tests for a bug with empty title
'',
'',
],
[
// tests for a bug with null title
null,
'',
],
[
// tests for a bug with all spaces
' ',
'',
],
[
// tests for a bug with all spaces, one word
' test',
'Test',
],
[
// tests one word
'test',
'Test',
],
[
// tests for a bug with special characters
'get up and dance — 7 reasons why you should be… moving your feet to the beat',
'Get Up and Dance — 7 Reasons Why You Should Be… Moving Your Feet to the Beat',
],
];
}
}

0 comments on commit 64efe41

Please sign in to comment.