16
16
class StrUtilityTest extends TestCase
17
17
{
18
18
public $ sampleText = 'somE TexT 444 for? tE34st! @#56$%^ <> ' ;
19
+ public $ basePath = __DIR__ . '/../ ' ;
19
20
20
21
public function testToCamelCaseCanReturnStringValue ()
21
22
{
@@ -122,7 +123,7 @@ public function testDotNotationCanReturnStringValue()
122
123
public function testDotNotationCanReturnStringLikeDotNotation ()
123
124
{
124
125
$ string = strHelpersTest::dotNotation ($ this ->sampleText );
125
- $ this ->assertEquals ('some.text .444.for.te34st .56 ' , $ string );
126
+ $ this ->assertEquals ('somE.TexT .444.for.tE34st .56 ' , $ string );
126
127
}
127
128
128
129
public function testEntitiesWrapperCanReturnStringValue ()
@@ -201,9 +202,10 @@ public function testAlternateCanReturnStringValueIfBothParamAreNull()
201
202
$ this ->assertEquals ('not defined ' , $ string );
202
203
}
203
204
204
- public function testTranslateCanReturnStringData ()
205
+ public function testTranslateCanReturnStringValue ()
205
206
{
206
- $ string = strHelpersTest::translate ('app.title ' );
207
+ $ translatePath = strHelpersTest::translatePath (realpath ($ this ->basePath ), 'en ' );
208
+ $ string = strHelpersTest::translate ($ translatePath . 'app.title ' );
207
209
$ this ->assertIsString ($ string );
208
210
}
209
211
@@ -216,18 +218,28 @@ public function testTranslateCanThrowExceptionIfLangFileDoesNotExists()
216
218
public function testTranslateCanThrowExceptionIfLangFileDoesNotInArrayType ()
217
219
{
218
220
$ this ->expectException (LanguageFileIsNotArrayException::class);
219
- $ string = strHelpersTest::translate ('app.title ' );
221
+ $ translatePath = strHelpersTest::translatePath (realpath ($ this ->basePath ), 'en ' );
222
+ strHelpersTest::translate ($ translatePath . 'auth.title ' );
220
223
}
221
224
225
+ // public function testTranslateCanReturnReplaceParamIfGivenKeyDoesNotExists()
226
+ // {
227
+ // $translatePath = strHelpersTest::translatePath(realpath($this->basePath), 'en');
228
+ // $string = strHelpersTest::translate($translatePath . 'app.site', 'replace text');
229
+ // $this->assertEquals('replace text', $string);
230
+ // }
231
+
222
232
public function testFilePathCanReturnStringValue ()
223
233
{
224
- $ filePath = strHelpersTest::filePath ('lang.en.app ' );
234
+ $ basePath = realpath ($ this ->basePath );
235
+ $ filePath = strHelpersTest::filePath ($ basePath . '.lang.en.app ' );
225
236
$ this ->assertIsString ($ filePath );
226
237
}
227
238
228
239
public function testFilePathReturnedFilePathIfExists ()
229
240
{
230
- $ filePath = strHelpersTest::filePath ('lang.en.app ' );
241
+ $ basePath = realpath ($ this ->basePath );
242
+ $ filePath = strHelpersTest::filePath ($ basePath . '.lang.en.app ' );
231
243
$ this ->assertFileExists ($ filePath );
232
244
$ this ->assertFileEquals ('lang/en/app.php ' , $ filePath );
233
245
$ this ->assertFileIsReadable ($ filePath );
@@ -236,7 +248,7 @@ public function testFilePathReturnedFilePathIfExists()
236
248
public function testPathThrowAnExceptionsIfFileDoesNotExists ()
237
249
{
238
250
$ this ->expectException (FileDoesNotExistsException::class);
239
- $ filePath = strHelpersTest::filePath ('lang.en.config.auth ' );
251
+ strHelpersTest::filePath ('lang.en.config.auth ' );
240
252
}
241
253
242
254
public function testWrapperCanReturnStringValue ()
@@ -783,4 +795,46 @@ public function testDecrementByCanDecrementGivenString()
783
795
$ string = strHelpersTest::decrementBy ('bar1 ' , '* ' );
784
796
$ this ->assertEquals ('bar*0 ' , $ string );
785
797
}
798
+
799
+ public function testRmLastWordCanReturnStringValue ()
800
+ {
801
+ $ string = strHelpersTest::rmLastWord ('foo bar baz ' );
802
+ $ this ->assertIsString ($ string );
803
+ }
804
+
805
+ public function testRmLastWordCanRemoveLastWordOfGivenString ()
806
+ {
807
+ $ string = strHelpersTest::rmLastWord ('foo bar baz 123 ' );
808
+ $ this ->assertEquals ('foo bar baz ' , $ string );
809
+ }
810
+
811
+ public function testRmFirstWordCanReturnStringValue ()
812
+ {
813
+ $ string = strHelpersTest::rmFirstWord ('foo bar baz ' );
814
+ $ this ->assertIsString ($ string );
815
+ }
816
+
817
+ public function testRmFirstWordCanRemoveFirstWordOfGivenString ()
818
+ {
819
+ $ string = strHelpersTest::rmFirstWord ('12 123 foo bar baz ' );
820
+ $ this ->assertEquals ('123 foo bar baz ' , $ string );
821
+ }
822
+
823
+ public function testIsSlugCanReturnBooleanValue ()
824
+ {
825
+ $ slug = strHelpersTest::is_slug ('foo-bar-baz ' );
826
+ $ this ->assertIsBool ($ slug );
827
+ }
828
+
829
+ public function testIsSlugReturnFalseIfGivenStringIsNotASlug ()
830
+ {
831
+ $ slug = strHelpersTest::is_slug ('foo bar baz ' );
832
+ $ this ->assertNotTrue ($ slug );
833
+ }
834
+
835
+ public function testIsSlugReturnTrueIfGivenStringIsASlug ()
836
+ {
837
+ $ slug = strHelpersTest::is_slug ('132Foo-12bar-3432az ' );
838
+ $ this ->assertTrue ($ slug );
839
+ }
786
840
}
0 commit comments