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

solves #2625: Add feature to disable the featured page image inheritance #2626

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Optional;
import java.util.Set;

import com.adobe.cq.wcm.core.components.models.Image;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
Expand Down Expand Up @@ -344,9 +345,10 @@ public static Resource getWrappedImageResourceWithInheritance(Resource resource,
String fileReference = properties.get(DownloadResource.PN_REFERENCE, String.class);
Resource fileResource = resource.getChild(DownloadResource.NN_FILE);
boolean imageFromPageImage = properties.get(PN_IMAGE_FROM_PAGE_IMAGE, StringUtils.isEmpty(fileReference) && fileResource == null);
boolean disablePageImageInheritance = currentStyle != null ? currentStyle.get(Image.PN_PAGE_IMAGE_INHERITANCE_DISABLED, false) : false;
boolean altValueFromPageImage = properties.get(PN_ALT_VALUE_FROM_PAGE_IMAGE, imageFromPageImage);

if (imageFromPageImage) {
if (!disablePageImageInheritance && imageFromPageImage) {
Resource inheritedResource = null;
String linkURL = properties.get(ImageResource.PN_LINK_URL, String.class);
boolean actionsEnabled = (currentStyle != null) ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ public interface Image extends Component {
*/
String PN_IMAGE_FROM_PAGE_IMAGE = "imageFromPageImage";

/**
* Name of the content policy property that will indicate if the image inheritance the featured image of the page is disabled.
*
* @since com.adobe.cq.wcm.core.components.models 12.29.0
*/
String PN_PAGE_IMAGE_INHERITANCE_DISABLED = "disablePageImageInheritance";

/**
* Name of the resource property that will indicate if the value of the {@code alt} attribute should be inherited
* from the featured image of the page.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@
checked="{Boolean}false"
uncheckedValue="false"
value="{Boolean}true"/>
<disablePageImageInheritance
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
fieldDescription="When checked, it will not inherit the featured image from the page."
name="./disablePageImageInheritance"
text="Disable Page Image Inheritance"
checked="{Boolean}false"
uncheckedValue="false"
value="{Boolean}true"/>
<decorative
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ public void setup(CQClient client, String contextPath, String label, String imag

// 2.
policyPath = Commons.createPagePolicy(client, defaultPageTemplate, label, new HashMap<String, String>() {{
put("clientlibs", clientlibs);
put("clientlibs", clientlibs);
}});

// 4.
proxyPath = imageRT;

// 6.
compPath = Commons.addComponentWithRetry(client, proxyPath,testPage + Commons.relParentCompPath, "image", null,
RequestConstants.TIMEOUT_TIME_MS, RequestConstants.RETRY_TIME_INTERVAL,
HttpStatus.SC_OK, HttpStatus.SC_CREATED);
RequestConstants.TIMEOUT_TIME_MS, RequestConstants.RETRY_TIME_INTERVAL,
HttpStatus.SC_OK, HttpStatus.SC_CREATED);

// 7.
editorPage = new PageEditorPage(testPage);
Expand All @@ -106,8 +106,8 @@ public void setup(CQClient client, String contextPath, String label, String imag

public void cleanup(CQClient client) throws ClientException, InterruptedException {
client.deletePageWithRetry(testPage, true,false,
RequestConstants.TIMEOUT_TIME_MS, RequestConstants.RETRY_TIME_INTERVAL,
HttpStatus.SC_OK);
RequestConstants.TIMEOUT_TIME_MS, RequestConstants.RETRY_TIME_INTERVAL,
HttpStatus.SC_OK);
}

public void setMinimalProps() throws InterruptedException, TimeoutException {
Expand Down Expand Up @@ -183,7 +183,7 @@ public void testAddImage() throws TimeoutException, InterruptedException {
Commons.closeSidePanel();
Commons.switchContext("ContentFrame");
assertTrue(image.isImagePresentWithAltTextAndTitle(testPage, originalDamDescription, originalDamTitle), "Image should be present with alt text " + originalDamDescription
+ " and title " + originalDamTitle);
+ " and title " + originalDamTitle);
}

public void testDragImageToComponent(boolean imageV3) throws TimeoutException, InterruptedException {
Expand Down Expand Up @@ -221,7 +221,7 @@ public void testAddAltTextAndTitle() throws TimeoutException, InterruptedExcepti
Commons.closeSidePanel();
Commons.switchContext("ContentFrame");
assertTrue(image.isImagePresentWithAltTextAndTitle(testPage, altText, captionText), "Image should be present with alt text " + altText
+ " and title " + captionText);
+ " and title " + captionText);
}

public void testSetAssetWithoutDescriptionAsDecorative(boolean imageV3) throws InterruptedException, TimeoutException {
Expand All @@ -243,7 +243,7 @@ public void testSetAssetWithoutDescription() throws InterruptedException, Timeou
editDialog.openMetadataTab();
Commons.saveConfigureDialog();
String assetWithoutDescriptionErrorMessageSelector = ".coral-Form-errorlabel, " +
"coral-tooltip[variant='error'] > coral-tooltip-content";
"coral-tooltip[variant='error'] > coral-tooltip-content";
assertEquals("Error: Please provide an asset which has a description that can be used as alt text.", $(assetWithoutDescriptionErrorMessageSelector).innerText());
}

Expand All @@ -252,7 +252,7 @@ public void testSetAssetWithoutDescriptionV3() throws InterruptedException, Time
dragImageWithoutDescription();
Commons.saveConfigureDialog();
String assetWithoutDescriptionErrorMessageSelector = ".coral-Form-errorlabel, " +
"coral-tooltip[variant='error'] > coral-tooltip-content";
"coral-tooltip[variant='error'] > coral-tooltip-content";
String errorIcon = "input[name='./alt'] + coral-icon[icon='alert']";
final WebDriver webDriver = WebDriverRunner.getWebDriver();
((JavascriptExecutor) webDriver).executeScript("arguments[0].scrollIntoView(true);", $(errorIcon));
Expand All @@ -272,7 +272,7 @@ public void testAddAltTextAndTitleV3() throws TimeoutException, InterruptedExcep
Commons.closeSidePanel();
Commons.switchContext("ContentFrame");
assertTrue(image.isImagePresentWithAltTextAndTitle(testPage, altText, captionText), "Image should be present with alt text " + altText
+ " and title " + captionText);
+ " and title " + captionText);
}

public void testDisableCaptionAsPopup() throws TimeoutException, InterruptedException {
Expand Down Expand Up @@ -402,7 +402,7 @@ public void testSetSizes() throws TimeoutException, InterruptedException {
editorPage.enterPreviewMode();
Commons.switchContext("ContentFrame");
assertTrue(image.isImagePresentWithSizes(testPage, "(min-width: 36em) 33.3vw, 100vw"), "Image with sizes attribute should be " +
"present");
"present");
}

public void testPageImageWithEmptyAltTextFromPageImage(boolean aem65) throws InterruptedException, ClientException {
Expand Down Expand Up @@ -484,6 +484,18 @@ public void testPageImageWithLinkedPage(boolean aem65) throws TimeoutException,
assertTrue(Commons.getCurrentUrl().endsWith(redirectPage+".html"),"Current page should be link URL set after redirection");
}

public void testPageImageWithFeaturedImageDisabled(boolean aem65) throws TimeoutException, InterruptedException, ClientException {
setPageImage(aem65, testPage, logoNodeName, true);
editorPage.open();
ImageEditDialog editDialog = image.getEditDialog();
Commons.openEditDialog(editorPage, compPath);
editDialog.openMetadataTab();
Commons.saveConfigureDialog();
editorPage.enterPreviewMode();
Commons.switchContext("ContentFrame");
assertFalse(image.isImagePresentWithFileName(climbingAssetFormatted),"image should not be rendered, page featured image inheritance is disabled");
}

public void testSetLinkWithTarget() throws TimeoutException, InterruptedException {
Commons.openSidePanel();
dragImage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,31 @@ public void testPageImageWithLinkedPage65() throws TimeoutException, Interrupted
imageTests.testPageImageWithLinkedPage(true);
}

/**
* Test: set page featured image with featured image disabled
*/
@Tag("IgnoreOnSDK")
@Test
@DisplayName("Test (6.5): set page featured image with featured image disabled")
public void testPageImageWithFeaturedImageDisabled65() throws TimeoutException, InterruptedException, ClientException {
testPageImageWithFeaturedImageDisabled(true);
}

/**
* Test: set page featured image with featured image disabled
*/
@Test
@DisplayName("Test: set page featured image with featured image disabled")
public void testPageImageWithFeaturedImageDisabledSdk() throws TimeoutException, InterruptedException, ClientException {
testPageImageWithFeaturedImageDisabled(false);
}

private void testPageImageWithFeaturedImageDisabled(boolean aem65) throws ClientException, TimeoutException, InterruptedException {
String policyPath = createComponentPolicy("/image-v3", new HashMap<String, String>() {{ put("disablePageImageInheritance", "true"); }} );
imageTests.testPageImageWithFeaturedImageDisabled(aem65);
deleteComponentPolicy("/image-v3", policyPath);
}

/**
* Test: set link with target on image
*/
Expand Down