*** Keywords ***

Suite Setup
    Open browser  ${front-page}  browser=${BROWSER}  desired_capabilities=Capture Page Screenshot

Suite Teardown
    Close All Browsers

Log in
    [Documentation]  Log in to the site as ${userid} using ${password}. There
    ...              is no guarantee of where in the site you are once this is
    ...              done. (You are responsible for knowing where you are and
    ...              where you want to be)
    [Arguments]  ${userid}  ${password}

    Go to  ${PLONE_URL}/login_form
    Page should contain element  __ac_name
    Page should contain element  __ac_password
    Page should contain button  Log in
    Input text  __ac_name  ${userid}
    Input text  __ac_password  ${password}
    Click Button  Log in

Log in as site owner
    [Documentation]  Log in as the SITE_OWNER provided by plone.app.testing,
    ...              with all the rights and privileges of that user.
    Log in  ${SITE_OWNER_NAME}  ${SITE_OWNER_PASSWORD}

Log in as test user

    Log in  ${TEST_USER_NAME}  ${TEST_USER_PASSWORD}

Log out
    Go to  ${PLONE_URL}/logout
    Page should contain  logged out

Add image
    [arguments]  ${title}  ${filename}

    Open Add New Menu
    Click Link  link=Image
    Wait Until Page Contains Element  title
    Input Text  title  ${title}
    Choose File  name=image_file  ${PATH_TO_TEST_FILES}/${filename}
    Click button  name=form.button.save
    Page Should Contain  Changes saved.

Open Menu
    [Arguments]  ${elementId}

    Element Should Be Visible  css=dl#${elementId} span
    Element Should Not Be Visible  css=dl#${elementId} dd.actionMenuContent
    Click link  css=dl#${elementId} dt.actionMenuHeader a
    Wait until keyword succeeds  5s  1s  Element Should Be Visible  css=dl#${elementId} dd.actionMenuContent

Open Add New Menu
    Open Menu  plone-contentmenu-factories

Open Display Menu
    Open Menu  plone-contentmenu-display

# This is prettyphoto specific and may change in future versions of
# the prettyPhoto library.
Apply prettyPhoto View
    Open Display Menu
    Click Link  link=Thumbnail view (prettyPhoto)
    Wait Until Page Contains  View changed.

Open prettyPhoto Gallery
    Click Link  xpath=//a[@rel="prettyPhoto[gallery]"][1]
    Wait Until keyword succeeds  5s  1s  Element Should Be Visible  css=div.pp_pic_holder

    Sleep  2  # Let prettyPhoto come up

Click On prettyPhoto Controls
    [Arguments]  ${elementClassname}

    Click Element  css=a.${elementClassname}
    Sleep  2  # Let image change
    Element Should Be Visible  css=#fullResImage

Click On Next in prettyPhoto Gallery
    Click On prettyPhoto Controls  pp_next

Click On Previous in prettyPhoto Gallery
    Click On prettyPhoto Controls  pp_previous

Be Sure prettyPhoto Shows Image
    [Arguments]  ${imageId}  ${imageTitle}

    Wait Until Keyword Succeeds  5s  1s  prettyPhoto URL Should Contain  ${imageId}
    Element Should Contain  css=div.pp_pic_holder div.ppt  ${imageTitle}

Close prettyPhoto Gallery
    Click Element  css=a.pp_close
    Sleep  2  # Let prettyPhoto close
    Element Should Not Be Visible  css=div.pp_pic_holder

prettyPhoto URL Should Contain
    [Arguments]  ${imageId}
    ${url}=  Get Element Attribute  css=#fullResImage@src
    Should Contain  ${url}  ${imageId}
