Example #1
0
 /**
  * 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(Text::humanize('start_a_horse'))->equals('start a horse');
         expect(Text::humanize("five-cats"))->equals('five cats');
         expect(Text::humanize('kittens-are_cats'))->equals('kittens are cats');
         expect(Text::humanize(" \t Awesome-Phalcon \t "))->equals('Awesome Phalcon');
     });
 }
 /**
  * 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(Text::reduceSlashes('app/controllers//IndexController'))->equals('app/controllers/IndexController');
         expect(Text::reduceSlashes('http://foo//bar/baz/buz'))->equals('http://foo/bar/baz/buz');
         expect(Text::reduceSlashes('php://memory'))->equals('php://memory');
         expect(Text::reduceSlashes('http//https'))->equals('http/https');
     });
 }
Example #3
0
 /**
  * Tests the uderscore function
  *
  * @author Serghei Iakovlev <*****@*****.**>
  * @since  2015-11-09
  */
 public function testUnderscore()
 {
     $this->specify("underscore do not replace spaces", function () {
         expect(Text::underscore('start a horse'))->equals('start_a_horse');
         expect(Text::underscore("five\tcats"))->equals('five_cats');
         expect(Text::underscore(' look behind '))->equals('look_behind');
         expect(Text::underscore(" \t Awesome \t  \t Phalcon "))->equals('Awesome_Phalcon');
     });
 }
Example #4
0
 /**
  * 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(Text::lower('привет мир!'))->equals('привет мир!');
         expect(Text::lower('ПриВЕт Мир!'))->equals('привет мир!');
         expect(Text::lower('ПРИВЕТ МИР!'))->equals('привет мир!');
         expect(Text::lower('männer'))->equals('männer');
         expect(Text::lower('mÄnnER'))->equals('männer');
         expect(Text::lower('MÄNNER'))->equals('männer');
     });
 }
Example #5
0
 /**
  * Tests custom separator
  *
  * @issue  11215
  * @author Serghei Iakovlev <*****@*****.**>
  * @since  2016-06-27
  */
 public function testTextDynamicStringCustomSeparator()
 {
     $this->specify('Text::dynamic with custom separator does not return expected result', function () {
         $actual = Text::dynamic('{Hi=Hello}, my name is a Bob!', '{', '}', '=');
         expect($actual)->notContains('{');
         expect($actual)->notContains('}');
         expect($actual)->notContains('=');
         expect(preg_match('/^(Hi|Hello), my name is a Bob!$/', $actual))->equals(1);
         $actual = Text::dynamic("{Hi'Hello}, my name is a {Rob'Zyxep'Andres}!", '{', '}', "'");
         expect($actual)->notContains('{');
         expect($actual)->notContains('}');
         expect($actual)->notContains("'");
         expect(preg_match('/^(Hi|Hello), my name is a (Rob|Zyxep|Andres)!$/', $actual))->equals(1);
         $actual = Text::dynamic('{Hi/Hello}, my name is a {Stanislav/Nikos}!', '{', '}', '/');
         expect($actual)->notContains('{');
         expect($actual)->notContains('}');
         expect($actual)->notContains('/');
         expect(preg_match('/^(Hi|Hello), my name is a (Stanislav|Nikos)!$/', $actual))->equals(1);
     });
 }
Example #6
0
 /**
  * Tests the camelize function
  *
  * @author Nikolaos Dimopoulos <*****@*****.**>
  * @since  2014-09-29
  */
 public function testTextCamelizeString()
 {
     $this->specify('Text::camelize conversions do not return the correct string', function ($actual, $expected, $delimiter) {
         expect(Text::camelize($actual, $delimiter))->equals($expected);
     }, ['examples' => [['camelize', 'Camelize', null], ['CameLiZe', 'Camelize', null], ['cAmeLize', 'Camelize', null], ['123camelize', '123camelize', null], ['c_a_m_e_l_i_z_e', 'CAMELIZE', null], ['Camelize', 'Camelize', null], ['camel_ize', 'CamelIze', null], ['CameLize', 'Camelize', null], ["c_a-m_e-l_i-z_e", 'CAMELIZE', null], ["came_li_ze", 'CameLiZe', null], ["=_camelize", '=Camelize', "_"], ["camelize", 'Camelize', "_"], ["came_li_ze", 'CameLiZe', "_"], ["came#li#ze", 'CameLiZe', "#"], ["came li ze", 'CameLiZe', " "], ["came.li^ze", 'CameLiZe', ".^"], ["c_a-m_e-l_i-z_e", 'CAMELIZE', "-_"], ["came.li.ze", 'CameLiZe', "."], ["came-li-ze", 'CameLiZe', "-"], ["c+a+m+e+l+i+z+e", 'CAMELIZE', "+"]]]);
 }
Example #7
0
 /**
  * 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 = Text::increment($source, '-');
         expect($actual)->equals($expected);
     });
 }
Example #8
0
 /**
  * Tests the uncamelize function
  *
  * @author Nikolaos Dimopoulos <*****@*****.**>
  * @since  2014-09-29
  */
 public function testTextUncamelizeString()
 {
     $this->specify('Text::uncamelize conversions do not return the correct string', function ($actual, $expected, $delimiter) {
         expect(Text::uncamelize($actual, $delimiter))->equals($expected);
     }, ['examples' => [['camelize', 'camelize', null], ['CameLiZe', 'came_li_ze', null], ['cAmeLize', 'c_ame_lize', null], ['_camelize', '_camelize', null], ['123camelize', '123camelize', null], ['c_a_m_e_l_i_z_e', 'c_a_m_e_l_i_z_e', null], ['Camelize', 'camelize', null], ['camel_ize', 'camel_ize', null], ['CameLize', 'came_lize', null], ["Camelize", 'camelize', null], ["=Camelize", '=_camelize', "_"], ["Camelize", 'camelize', "_"], ["CameLiZe", 'came_li_ze', "_"], ["CameLiZe", 'came#li#ze', "#"], ["CameLiZe", 'came li ze', " "], ["CameLiZe", 'came.li.ze', "."], ["CameLiZe", 'came-li-ze', "-"], ["CAMELIZE", 'c/a/m/e/l/i/z/e', "/"]]]);
 }
Example #9
0
 /**
  * Tests the endsWith function with case sensitive flage
  *
  * @author Nikos Dimopoulos <*****@*****.**>
  * @since  2014-09-29
  */
 public function testTextEndsWithCaseSensitive()
 {
     $this->specify("endsWith does not return correct result with case sensitivity", function () {
         $actual = Text::endsWith("Hello", "hello", true);
         expect($actual)->true();
         $actual = Text::endsWith("Hello", "hello", false);
         expect($actual)->false();
         $actual = Text::endsWith("Hello", "O", false);
         expect($actual)->false();
     });
 }
Example #10
0
 /**
  * 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 = Text::random(Text::RANDOM_NOZERO, $i);
             expect(preg_match('/[1-9]+/', $source, $matches))->equals(1);
             expect($matches[0])->equals($source);
             expect(strlen($source))->equals($i);
         }
     });
 }