Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 13457 #13465

Merged
merged 2 commits into from
Jan 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,44 +1,43 @@
package com.dotmarketing.portlets.templates.business;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import com.dotcms.IntegrationTestBase;
import com.dotcms.datagen.HTMLPageDataGen;
import com.dotcms.util.IntegrationTestInitService;
import com.dotmarketing.beans.ContainerStructure;
import com.dotmarketing.beans.Host;
import com.dotmarketing.beans.Inode;
import com.dotmarketing.business.APILocator;
import com.dotmarketing.business.CacheLocator;
import com.dotmarketing.business.UserAPI;
import com.dotmarketing.business.VersionableAPI;
import com.dotmarketing.exception.DotDataException;
import com.dotmarketing.exception.DotSecurityException;
import com.dotmarketing.portlets.AssetUtil;
import com.dotmarketing.portlets.containers.business.ContainerAPI;
import com.dotmarketing.portlets.containers.model.Container;
import com.dotmarketing.portlets.contentlet.business.HostAPI;
import com.dotmarketing.portlets.contentlet.model.Contentlet;
import com.dotmarketing.portlets.folders.model.Folder;
import com.dotmarketing.portlets.htmlpageasset.model.HTMLPageAsset;

import java.util.ArrayList;
import java.util.List;

import com.dotcms.IntegrationTestBase;
import com.dotcms.util.IntegrationTestInitService;

import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import com.dotmarketing.beans.ContainerStructure;
import com.dotmarketing.beans.Host;
import com.dotmarketing.beans.Inode;
import com.dotmarketing.business.APILocator;
import com.dotmarketing.business.CacheLocator;
import com.dotmarketing.portlets.AssetUtil;
import com.dotmarketing.portlets.containers.model.Container;
import com.dotmarketing.portlets.structure.model.Structure;
import com.dotmarketing.portlets.templates.model.Template;
import com.dotmarketing.util.InodeUtils;
import com.dotmarketing.util.UUIDGenerator;
import com.dotmarketing.util.UtilMethods;
import com.liferay.portal.model.User;

import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

public class TemplateAPITest extends IntegrationTestBase {

private static ContainerAPI containerAPI;
Expand Down Expand Up @@ -272,4 +271,39 @@ public void testFindTemplatesAssignedTo() throws DotDataException, DotSecurityEx
assertNotNull(result);
assertTrue(!result.isEmpty());
}

@Test
public void copyTemplate() throws Exception {
Template oldTemplate = null;
Template newTemplate = null;

try {
//Create a Template.
oldTemplate = new Template();
oldTemplate.setTitle("Title");
oldTemplate.setBody("<html><body> I'm mostly empty </body></html>");
oldTemplate = templateAPI.saveTemplate(oldTemplate, host, user, false);

//Copy Template.
newTemplate = templateAPI.copy(oldTemplate, user);

//Body should be the same.
Assert.assertEquals(oldTemplate.getBody(), newTemplate.getBody());

//Name, identifier, inode and mod_date shouldn't be the same.
Assert.assertNotEquals(oldTemplate.getTitle(), newTemplate.getTitle());
Assert.assertNotEquals(oldTemplate.getIdentifier(), newTemplate.getIdentifier());
Assert.assertNotEquals(oldTemplate.getInode(), newTemplate.getInode());
Assert.assertNotEquals(oldTemplate.getModDate(), newTemplate.getModDate());

} finally {
//Clean up.
if (oldTemplate != null) {
templateAPI.delete(oldTemplate, user, false);
}
if (newTemplate != null) {
templateAPI.delete(newTemplate, user, false);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.dotcms.business.CloseDBIfOpened;
import com.dotcms.business.WrapInTransaction;

import com.dotcms.rendering.velocity.viewtools.DotTemplateTool;
import com.dotmarketing.beans.Host;
import com.dotmarketing.beans.Identifier;
Expand Down Expand Up @@ -30,6 +29,7 @@
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.UtilMethods;
import com.dotmarketing.util.WebKeys;
import com.liferay.portal.model.User;

import java.util.ArrayList;
import java.util.Date;
Expand All @@ -39,8 +39,6 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.liferay.portal.model.User;

public class TemplateAPIImpl extends BaseWebAssetAPI implements TemplateAPI {

static PermissionAPI permissionAPI = APILocator.getPermissionAPI();
Expand Down Expand Up @@ -122,8 +120,6 @@ public Template copy(Template sourceTemplate, Host destination, boolean forceOve
newTemplate.setIdentifier(newIdentifier.getInode());
// persists the webasset
save(newTemplate);
List<Container> destinationContainers = getContainersInTemplate(newTemplate, user, respectFrontendRoles);


//Copy the host again
newIdentifier.setHostId(destination.getIdentifier());
Expand Down