File tree Expand file tree Collapse file tree 3 files changed +57
-1
lines changed
androidTest/java/org/wordpress/android/util
main/java/org/wordpress/android/util Expand file tree Collapse file tree 3 files changed +57
-1
lines changed Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ android {
3232 buildToolsVersion " 23.0.2"
3333
3434 defaultConfig {
35- versionName " 1.8 .0"
35+ versionName " 1.9 .0"
3636 minSdkVersion 14
3737 targetSdkVersion 23
3838 }
Original file line number Diff line number Diff line change 1+ package org .wordpress .android .util ;
2+
3+ import android .test .InstrumentationTestCase ;
4+
5+ public class ShortcodeUtilsTest extends InstrumentationTestCase {
6+ public void testGetVideoPressShortcodeFromId () {
7+ assertEquals ("[wpvideo abcd1234]" , ShortcodeUtils .getVideoPressShortcodeFromId ("abcd1234" ));
8+ }
9+
10+ public void testGetVideoPressShortcodeFromNullId () {
11+ assertEquals ("" , ShortcodeUtils .getVideoPressShortcodeFromId (null ));
12+ }
13+
14+ public void testGetVideoPressIdFromCorrectShortcode () {
15+ assertEquals ("abcd1234" , ShortcodeUtils .getVideoPressIdFromShortCode ("[wpvideo abcd1234]" ));
16+ }
17+
18+ public void testGetVideoPressIdFromInvalidShortcode () {
19+ assertEquals ("" , ShortcodeUtils .getVideoPressIdFromShortCode ("[other abcd1234]" ));
20+ }
21+
22+ public void testGetVideoPressIdFromNullShortcode () {
23+ assertEquals ("" , ShortcodeUtils .getVideoPressIdFromShortCode (null ));
24+ }
25+ }
Original file line number Diff line number Diff line change 1+ package org .wordpress .android .util ;
2+
3+ import java .util .regex .Matcher ;
4+ import java .util .regex .Pattern ;
5+
6+ public class ShortcodeUtils {
7+ public static String getVideoPressShortcodeFromId (String videoPressId ) {
8+ if (videoPressId == null || videoPressId .isEmpty ()) {
9+ return "" ;
10+ }
11+
12+ return "[wpvideo " + videoPressId + "]" ;
13+ }
14+
15+ public static String getVideoPressIdFromShortCode (String shortcode ) {
16+ String videoPressId = "" ;
17+
18+ if (shortcode != null ) {
19+ String videoPressShortcodeRegex = "^\\ [wpvideo (.*)]$" ;
20+
21+ Pattern pattern = Pattern .compile (videoPressShortcodeRegex );
22+ Matcher matcher = pattern .matcher (shortcode );
23+
24+ if (matcher .find ()) {
25+ videoPressId = matcher .group (1 );
26+ }
27+ }
28+
29+ return videoPressId ;
30+ }
31+ }
You can’t perform that action at this time.
0 commit comments