-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit '0b9c6088555e856e9fc7cdfe3e1e7b835ea4f08d' into develop
Conflicts: libs/utils/WordPressUtils/build.gradle libs/utils/WordPressUtils/src/main/java/org/wordpress/android/util/AppLog.java libs/utils/WordPressUtils/src/main/java/org/wordpress/android/util/helpers/SwipeToRefreshHelper.java
- Loading branch information
Showing
3 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
WordPressUtils/src/androidTest/java/org/wordpress/android/util/ShortcodeUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.wordpress.android.util; | ||
|
||
import android.test.InstrumentationTestCase; | ||
|
||
public class ShortcodeUtilsTest extends InstrumentationTestCase { | ||
public void testGetVideoPressShortcodeFromId() { | ||
assertEquals("[wpvideo abcd1234]", ShortcodeUtils.getVideoPressShortcodeFromId("abcd1234")); | ||
} | ||
|
||
public void testGetVideoPressShortcodeFromNullId() { | ||
assertEquals("", ShortcodeUtils.getVideoPressShortcodeFromId(null)); | ||
} | ||
|
||
public void testGetVideoPressIdFromCorrectShortcode() { | ||
assertEquals("abcd1234", ShortcodeUtils.getVideoPressIdFromShortCode("[wpvideo abcd1234]")); | ||
} | ||
|
||
public void testGetVideoPressIdFromInvalidShortcode() { | ||
assertEquals("", ShortcodeUtils.getVideoPressIdFromShortCode("[other abcd1234]")); | ||
} | ||
|
||
public void testGetVideoPressIdFromNullShortcode() { | ||
assertEquals("", ShortcodeUtils.getVideoPressIdFromShortCode(null)); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
WordPressUtils/src/main/java/org/wordpress/android/util/ShortcodeUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.wordpress.android.util; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class ShortcodeUtils { | ||
public static String getVideoPressShortcodeFromId(String videoPressId) { | ||
if (videoPressId == null || videoPressId.isEmpty()) { | ||
return ""; | ||
} | ||
|
||
return "[wpvideo " + videoPressId + "]"; | ||
} | ||
|
||
public static String getVideoPressIdFromShortCode(String shortcode) { | ||
String videoPressId = ""; | ||
|
||
if (shortcode != null) { | ||
String videoPressShortcodeRegex = "^\\[wpvideo (.*)]$"; | ||
|
||
Pattern pattern = Pattern.compile(videoPressShortcodeRegex); | ||
Matcher matcher = pattern.matcher(shortcode); | ||
|
||
if (matcher.find()) { | ||
videoPressId = matcher.group(1); | ||
} | ||
} | ||
|
||
return videoPressId; | ||
} | ||
} |