assertSame('', Text::auto_p('')); } /** * * @return array Test Data */ function provider_auto_para_does_not_enclose_html_tags_in_paragraphs() { return [ [ ['div'], '
Pick a plum of peppers
', ], [ ['div'], '
Tangas
', ], ]; } /** * This test makes sure that auto_p surrounds a single line of text * with paragraph tags * * @test * @covers Text::auto_p */ function test_auto_para_encloses_slot_in_paragraph() { $text = 'Pick a pinch of purple pepper'; $this->assertSame('

'.$text.'

', Text::auto_p($text)); } /** * Make sure that multiple new lines are replaced with paragraph tags * * @test * @covers Text::auto_p */ public function test_auto_para_replaces_multiple_newlines_with_paragraph() { $this->assertSame( "

My name is john

\n\n

I'm a developer

", Text::auto_p("My name is john\n\n\n\nI'm a developer") ); } /** * Data provider for test_limit_words * * @return array Array of test data */ function provider_limit_words() { return [ ['', '', 100, NULL], ['…', 'The rain in spain', -10, NULL], ['The rain…', 'The rain in spain', 2, NULL], ['The rain...', 'The rain in spain', 2, '...'], ]; } /** * * @test * @dataProvider provider_limit_words */ function test_limit_words($expected, $str, $limit, $end_char) { $this->assertSame($expected, Text::limit_words($str, $limit, $end_char)); } /** * Provides test data for test_limit_chars() * * @return array Test data */ function provider_limit_chars() { return [ ['', '', 100, NULL, FALSE], ['…', 'BOO!', -42, NULL, FALSE], ['making php bet…', 'making php better for the sane', 14, NULL, FALSE], ['Garçon! Un café s.v.p.', 'Garçon! Un café s.v.p.', 50, '__', FALSE], ['Garçon!__', 'Garçon! Un café s.v.p.', 8, '__', FALSE], // @issue 3238 ['making php…', 'making php better for the sane', 14, NULL, TRUE], ['Garçon!__', 'Garçon! Un café s.v.p.', 9, '__', TRUE], ['Garçon!__', 'Garçon! Un café s.v.p.', 7, '__', TRUE], ['__', 'Garçon! Un café s.v.p.', 5, '__', TRUE], ]; } /** * Tests Text::limit_chars() * * @test * @dataProvider provider_limit_chars */ function test_limit_chars($expected, $str, $limit, $end_char, $preserve_words) { $this->assertSame($expected, Text::limit_chars($str, $limit, $end_char, $preserve_words)); } /** * Test Text::alternate() * * @test */ function test_alternate_alternates_between_parameters() { list($val_a, $val_b, $val_c) = ['good', 'bad', 'ugly']; $this->assertSame('good', Text::alternate($val_a, $val_b, $val_c)); $this->assertSame('bad', Text::alternate($val_a, $val_b, $val_c)); $this->assertSame('ugly', Text::alternate($val_a, $val_b, $val_c)); $this->assertSame('good', Text::alternate($val_a, $val_b, $val_c)); } /** * Tests Text::alternate() * * @test * @covers Text::alternate */ function test_alternate_resets_when_called_with_no_params_and_returns_empty_string() { list($val_a, $val_b, $val_c) = ['yes', 'no', 'maybe']; $this->assertSame('yes', Text::alternate($val_a, $val_b, $val_c)); $this->assertSame('', Text::alternate()); $this->assertSame('yes', Text::alternate($val_a, $val_b, $val_c)); } /** * Provides test data for test_ucfirst * * @return array Test data */ public function provider_ucfirst() { return [ ['Content-Type', 'content-type', '-'], ['Բարեւ|Ձեզ', 'բարեւ|ձեզ', '|'], ]; } /** * Covers Text::ucfirst() * * @test * @dataProvider provider_ucfirst */ public function test_ucfirst($expected, $string, $delimiter) { $this->assertSame($expected, Text::ucfirst($string, $delimiter)); } /** * Provides test data for test_reducde_slashes() * * @returns array Array of test data */ function provider_reduce_slashes() { return [ ['/', '//'], ['/google/php/ko7/', '//google/php//ko7//'], ]; } /** * Covers Text::reduce_slashes() * * @test * @dataProvider provider_reduce_slashes */ function test_reduce_slashes($expected, $str) { $this->assertSame($expected, Text::reduce_slashes($str)); } /** * Provides test data for test_censor() * * @return array Test data */ function provider_censor() { return [ // If the replacement is 1 character long it should be repeated for the length of the removed word ["A donkey is also an ***", 'A donkey is also an ass', ['ass'], '*', TRUE], ["Cake### isn't nearly as good as ko7###", "CakePHP isn't nearly as good as ko7php", ['php'], '#', TRUE], // If it's > 1 then it's just replaced straight out ["If you're born out of wedlock you're a --expletive--", "If you're born out of wedlock you're a child", ['child'], '--expletive--', TRUE], ['class', 'class', ['ass'], '*', FALSE], ]; } /** * Tests Text::censor * * @test * @dataProvider provider_censor */ function test_censor($expected, $str, $badwords, $replacement, $replace_partial_words) { $this->assertSame($expected, Text::censor($str, $badwords, $replacement, $replace_partial_words)); } /** * Provides test data for test_random * * @return array Test Data */ function provider_random() { return [ ['alnum', 8], ['alpha', 10], ['hexdec', 20], ['nozero', 5], ['numeric', 14], ['distinct', 12], ['aeiou', 4], ['‹¡›«¿»', 8], // UTF8 characters [NULL, 8], // Issue #3256 ]; } /** * Tests Text::random() as well as possible * * Obviously you can't compare a randomly generated string against a * pre-generated one and check that they are the same as this goes * against the whole ethos of random. * * This test just makes sure that the value returned is of the correct * values and length * * @test * @dataProvider provider_random */ function test_random($type, $length) { if ($type === NULL) { $type = 'alnum'; } $pool = (string) $type; switch ($pool) { case 'alnum': $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; break; case 'alpha': $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; break; case 'hexdec': $pool = '0123456789abcdef'; break; case 'numeric': $pool = '0123456789'; break; case 'nozero': $pool = '123456789'; break; case 'distinct': $pool = '2345679ACDEFHJKLMNPRSTUVWXYZ'; break; } $this->assertRegExp('/^['.$pool.']{'.$length.'}$/u', Text::random($type, $length)); } /** * Provides test data for test_similar * * @return array */ function provider_similar() { return [ // TODO: add some more cases ['foo', ['foobar', 'food', 'fooberry']], ]; } /** * Tests Text::similar() * * @test * @dataProvider provider_similar * @covers Text::similar */ function test_similar($expected, $words) { $this->assertSame($expected, Text::similar($words)); } /** * Provides test data for test_bytes * * @return array */ public function provider_bytes() { return [ // TODO: cover the other units ['256.00 B', 256, NULL, NULL, TRUE], ['1.02 kB', 1024, NULL, NULL, TRUE], // In case you need to know the size of a floppy disk in petabytes ['0.00147 GB', 1.44 * 1000 * 1024, 'GB', '%01.5f %s', TRUE], // SI is the standard, but lets deviate slightly ['1.00 MiB', 1024 * 1024, 'MiB', NULL, FALSE], ]; } /** * Tests Text::bytes() * * @test * @dataProvider provider_bytes */ function test_bytes($expected, $bytes, $force_unit, $format, $si) { $this->assertSame($expected, Text::bytes($bytes, $force_unit, $format, $si)); } /** * Provides test data for test_widont() * * @return array Test data */ function provider_widont() { return [ // A very simple widont test [ 'A very simple test', 'A very simple test', ], // Single word items shouldn't be changed [ 'Test', 'Test', ], // Single word after single space shouldn't be changed either [ ' Test', ' Test', ], // Single word with HTML all around [ '