/** * Tests the dynamic function * * @author Stanislav Kiryukhin <*****@*****.**> * @since 2015-07-01 */ public function testTextDynamicStringCustomDelimeter() { $actual = PhTText::dynamic('(Hi|Hello), my name is a Bob!', '(', ')'); expect($actual)->notContains('('); expect($actual)->notContains(')'); expect(preg_match('/^(Hi|Hello), my name is a Bob!$/', $actual))->equals(1); }
/** * Tests the reduce slashes function * * @author Serghei Iakovlev <*****@*****.**> * @since 2015-05-11 */ public function testReduceSlashes() { $this->specify("reduce slashes do not delete extra slashes", function () { expect(PhTText::reduceSlashes('app/controllers//IndexController'))->equals('app/controllers/IndexController'); expect(PhTText::reduceSlashes('http://foo//bar/baz/buz'))->equals('http://foo/bar/baz/buz'); expect(PhTText::reduceSlashes('php://memory'))->equals('php://memory'); expect(PhTText::reduceSlashes('http//https'))->equals('http/https'); }); }
/** * Tests the humanize function * * @author Serghei Iakovlev <*****@*****.**> * @since 2015-11-09 */ public function testUnderscore() { $this->specify("humanize do not an underscored or dashed phrase human-readable", function () { expect(PhTText::humanize('start_a_horse'))->equals('start a horse'); expect(PhTText::humanize("five-cats"))->equals('five cats'); expect(PhTText::humanize('kittens-are_cats'))->equals('kittens are cats'); expect(PhTText::humanize(" \t Awesome-Phalcon \t "))->equals('Awesome Phalcon'); }); }
/** * Tests the uderscore function * * @author Serghei Iakovlev <*****@*****.**> * @since 2015-11-09 */ public function testUnderscore() { $this->specify("underscore do not replace spaces", function () { expect(PhTText::underscore('start a horse'))->equals('start_a_horse'); expect(PhTText::underscore("five\tcats"))->equals('five_cats'); expect(PhTText::underscore(' look behind '))->equals('look_behind'); expect(PhTText::underscore(" \t Awesome \t \t Phalcon "))->equals('Awesome_Phalcon'); }); }
/** * Tests the camelize function * * @author Nikolaos Dimopoulos <*****@*****.**> * @since 2014-09-29 */ public function testTextCamelizeString() { $this->specify("camelize conversions do not return the correct string", function () { $camelizeTests = ['camelize' => 'Camelize', 'CameLiZe' => 'Camelize', 'cAmeLize' => 'Camelize', '123camelize' => '123camelize', 'c_a_m_e_l_i_z_e' => 'CAMELIZE', 'Camelize' => 'Camelize', 'camel_ize' => 'CamelIze', 'CameLize' => 'Camelize']; foreach ($camelizeTests as $input => $camelized) { $expected = $camelized; $actual = PhTText::camelize($input); expect($actual)->equals($expected); } }); }
/** * Tests the concat function * * @author Stanislav Kiryukhin <*****@*****.**> * @since 2015-05-06 */ public function testTextConcatString() { $this->specify("concat do not return the correct string", function () { // Test 1 $actual = PhTText::concat('/', '/tmp/', '/folder_1/', '/folder_2', 'folder_3/'); $expected = '/tmp/folder_1/folder_2/folder_3/'; expect($actual)->equals($expected); // Test 2 $actual = PhTText::concat('.', '@test.', '.test2.', '.test', '.34'); $expected = '@test.test2.test.34'; expect($actual)->equals($expected); }); }
/** * Tests the startsWith function with case sensitive flag * * @author Nikolaos Dimopoulos <*****@*****.**> * @since 2014-09-29 */ public function testTextStartsWithCaseSensitive() { $this->specify("startsWith does not return correct result with case sensitivity", function () { $actual = PhTText::startsWith("Hello", "hello", true); expect($actual)->true(); $actual = PhTText::startsWith("Hello", "hello", false); expect($actual)->false(); $actual = PhTText::startsWith("Hello", "h", false); expect($actual)->false(); }); }
/** * Tests the increment function with a different separator * * @author Nikolaos Dimopoulos <*****@*****.**> * @since 2014-09-29 */ public function testTextIncrementStringWithDifferentSeparator() { $this->specify("increment does not increment a string with a different separator", function () { $source = 'file'; $expected = 'file-1'; $actual = PhTText::increment($source, '-'); expect($actual)->equals($expected); }); }
/** * Tests the lower function for multi-bytes encoding * * @author Stanislav Kiryukhin <*****@*****.**> * @since 2015-05-06 */ public function testLowerMultiBytesEncoding() { $this->specify("lower returns incorrect results", function () { expect(PhTText::lower('привет мир!'))->equals('привет мир!'); expect(PhTText::lower('ПриВЕт Мир!'))->equals('привет мир!'); expect(PhTText::lower('ПРИВЕТ МИР!'))->equals('привет мир!'); expect(PhTText::lower('männer'))->equals('männer'); expect(PhTText::lower('mÄnnER'))->equals('männer'); expect(PhTText::lower('MÄNNER'))->equals('männer'); }); }
/** * Tests the random function with non zero * * @author Nikolaos Dimopoulos <*****@*****.**> * @since 2014-09-29 */ public function testRandomNonZero() { $this->specify("random with nonzero does not return correct results", function () { for ($i = 1; $i < 10; $i++) { $source = PhTText::random(PhText::RANDOM_NOZERO, $i); expect(preg_match('/[1-9]+/', $source, $matches))->equals(1); expect($matches[0])->equals($source); expect(strlen($source))->equals($i); } }); }