[go: nahoru, domu]

Skip to content

Commit

Permalink
Added ShortcodeUtils with methods for converting VideoPress ids to sh…
Browse files Browse the repository at this point in the history
…ortcodes and vice versa
  • Loading branch information
aforcier committed Jan 30, 2016
1 parent 920ea46 commit 1857d7e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
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));
}
}
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;
}
}

0 comments on commit 1857d7e

Please sign in to comment.