1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.blog.test.po

File BlogPostInlinePage.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

10
32
12
1
203
103
17
0.53
2.67
12
1.42

Classes

Class Line # Actions
BlogPostInlinePage 39 32 0% 17 10
0.814814881.5%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.blog.test.po;
21   
22    import java.util.ArrayList;
23    import java.util.List;
24   
25    import org.apache.commons.lang.StringUtils;
26    import org.openqa.selenium.By;
27    import org.openqa.selenium.WebElement;
28    import org.openqa.selenium.support.FindBy;
29    import org.xwiki.test.ui.po.InlinePage;
30    import org.xwiki.test.ui.po.editor.wysiwyg.EditorElement;
31    import org.xwiki.test.ui.po.editor.wysiwyg.RichTextAreaElement;
32   
33    /**
34    * The "Inline form" edit mode page for a blog post.
35    *
36    * @version $Id: a49657b7ea0f14f9139d9a9b73bda780ec950077 $
37    * @since 4.2M1
38    */
 
39    public class BlogPostInlinePage extends InlinePage
40    {
41    /**
42    * The blog post title input field.
43    */
44    @FindBy(id = "Blog.BlogPostClass_0_title")
45    private WebElement titleInput;
46   
47    /**
48    * The list of available categories to choose from.
49    */
50    @FindBy(className = "blog-categories-list")
51    private WebElement categoryList;
52   
53    /**
54    * The check box used to hide the blog post from the other users.
55    */
56    @FindBy(id = "Blog.BlogPostClass_0_hidden")
57    private WebElement hiddenCheckBox;
58   
59    /**
60    * The WYSIWYG editor used to edit the blog post content.
61    */
62    private final EditorElement contentEditor = new EditorElement("Blog.BlogPostClass_0_content");
63   
64    /**
65    * The WYSIWYG editor used to edit the blog post summary.
66    */
67    private final EditorElement summaryEditor = new EditorElement("Blog.BlogPostClass_0_extract");
68   
69    /**
70    * Sets the value of the title input field.
71    *
72    * @param title the new blog post title
73    */
 
74  2 toggle public void setTitle(String title)
75    {
76  2 titleInput.clear();
77  2 titleInput.sendKeys(title);
78    }
79   
80    /**
81    * @return the value of the title input field
82    */
 
83  2 toggle public String getTitle()
84    {
85  2 return titleInput.getAttribute("value");
86    }
87   
88    /**
89    * Sets the value of the blog post content field.
90    *
91    * @param content the new blog post content
92    */
 
93  2 toggle public void setContent(String content)
94    {
95  2 RichTextAreaElement richTextArea = contentEditor.getRichTextArea();
96  2 richTextArea.clear();
97  2 richTextArea.sendKeys(content);
98    }
99   
 
100  1 toggle @Override
101    public String getContent()
102    {
103  1 return contentEditor.getRichTextArea().getText();
104    }
105   
106    /**
107    * Selects the specified categories.
108    *
109    * @param categories the list of categories to select
110    */
 
111  2 toggle public void setCategories(List<String> categories)
112    {
113  2 for (String categoryName : categories) {
114  3 String categoryReference = categoryName;
115  3 if (categoryReference.indexOf('.') < 0) {
116  3 categoryReference = "Blog." + categoryName;
117    }
118  3 String categoryXPath =
119    "//input[@name = 'Blog.BlogPostClass_0_category' and @value = '" + categoryReference + "']";
120  3 for (WebElement category : categoryList.findElements(By.xpath(categoryXPath))) {
121  3 if (!category.isSelected()) {
122  2 category.click();
123    }
124    }
125    }
126    }
127   
128    /**
129    * @return the list of selected categories
130    */
 
131  1 toggle public List<String> getCategories()
132    {
133  1 List<String> categories = new ArrayList<String>();
134  1 for (WebElement category : categoryList.findElements(By
135    .xpath("//input[@name = 'Blog.BlogPostClass_0_category']"))) {
136  7 if (category.isSelected()) {
137  1 categories.add(StringUtils.substringAfter(category.getAttribute("value"), "."));
138    }
139    }
140  1 return categories;
141    }
142   
143    /**
144    * @return {@code true} if the blog post has been published, {@code false} otherwise
145    */
 
146  1 toggle public boolean isPublished()
147    {
148  1 for (WebElement publishCheckBox : getDriver().findElements(By.id("Blog.BlogPostClass_0_published"))) {
149  1 return publishCheckBox.isSelected();
150    }
151    // When editing a published blog post the publish check box is not displayed.
152  0 return true;
153    }
154   
155    /**
156    * Publish the blog post after it is saved.
157    *
158    * @param published whether to publish the blog post or not
159    */
 
160  1 toggle public void setPublished(boolean published)
161    {
162  1 for (WebElement publishCheckBox : getDriver().findElements(By.id("Blog.BlogPostClass_0_published"))) {
163  1 if (publishCheckBox.isSelected() != published) {
164  1 publishCheckBox.click();
165    }
166    }
167    }
168   
169    /**
170    * @return {@code true} if the blog post is hidden, {@code false} otherwise
171    */
 
172  0 toggle public boolean isHidden()
173    {
174  0 return hiddenCheckBox.isSelected();
175    }
176   
177    /**
178    * Controls whether the blog post is visible for the rest of the users.
179    *
180    * @param hidden {@code true} to hide the blog post, {@code false} to make it visible for the other the users
181    */
 
182  0 toggle public void setHidden(boolean hidden)
183    {
184  0 if (hiddenCheckBox.isSelected() != hidden) {
185  0 hiddenCheckBox.click();
186    }
187    }
188   
189    /**
190    * Wait for the WYSIWYG editors used to edit the blog content and summary to load.
191    */
 
192  2 toggle public void waitToLoad()
193    {
194  2 contentEditor.waitToLoad();
195  2 summaryEditor.waitToLoad();
196    }
197   
 
198  2 toggle @Override
199    protected BlogPostViewPage createViewPage()
200    {
201  2 return new BlogPostViewPage();
202    }
203    }