View Javadoc
1   /**
2    * This file Copyright (c) 2016-2018 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
32   *
33   */
34  package info.magnolia.templating.predicates;
35  
36  import static org.junit.Assert.assertFalse;
37  import static org.junit.Assert.assertTrue;
38  
39  import info.magnolia.jcr.util.NodeTypes;
40  import info.magnolia.templating.functions.NavigationTemplatingFunctions;
41  import info.magnolia.test.mock.jcr.MockNode;
42  
43  import javax.jcr.RepositoryException;
44  
45  import org.junit.Test;
46  
47  public class NavigationItemPredicateTest {
48  
49      @Test
50      public void evaluatePageNodeWithoutHideInNavProperty() {
51          // GIVEN
52          NavigationItemPredicate predicate = new NavigationItemPredicate();
53          MockNode node = new MockNode("name", NodeTypes.Page.NAME);
54  
55          // WHEN THEN
56          assertTrue(predicate.evaluate(node));
57      }
58  
59      @Test
60      public void evaluatePageNodeWithHideInNavPropertySetToFalse() throws RepositoryException {
61          // GIVEN
62          NavigationItemPredicate predicate = new NavigationItemPredicate();
63          MockNode node = new MockNode("name", NodeTypes.Page.NAME);
64          node.setProperty(NavigationTemplatingFunctions.HIDE_IN_NAVIGATION_PROPERTY_NAME, false);
65  
66          // WHEN THEN
67          assertTrue(predicate.evaluate(node));
68      }
69  
70      @Test
71      public void evaluatePageNodeWithHideInNavPropertySetToTrue() throws RepositoryException {
72          // GIVEN
73          NavigationItemPredicate predicate = new NavigationItemPredicate();
74          MockNode node = new MockNode("name", NodeTypes.Page.NAME);
75          node.setProperty(NavigationTemplatingFunctions.HIDE_IN_NAVIGATION_PROPERTY_NAME, true);
76  
77          // WHEN THEN
78          assertFalse(predicate.evaluate(node));
79      }
80  
81      @Test
82      public void evaluateWithSpecificNodeTypeWithoutHideInNavProperty() {
83          // GIVEN
84          NavigationItemPredicate predicate = new NavigationItemPredicate("mgnl:dummy");
85          MockNode node = new MockNode("name", "mgnl:dummy");
86  
87          // WHEN THEN
88          assertTrue(predicate.evaluate(node));
89      }
90  
91      @Test
92      public void evaluateWithSpecificNodeTypWithHideInNavPropertySetToFalse() throws RepositoryException {
93          // GIVEN
94          NavigationItemPredicate predicate = new NavigationItemPredicate("mgnl:dummy");
95          MockNode node = new MockNode("name", "mgnl:dummy");
96          node.setProperty(NavigationTemplatingFunctions.HIDE_IN_NAVIGATION_PROPERTY_NAME, false);
97  
98          // WHEN THEN
99          assertTrue(predicate.evaluate(node));
100     }
101 
102     @Test
103     public void evaluateWithSpecificNodeTypWithHideInNavPropertySetToTrue() throws RepositoryException {
104         // GIVEN
105         NavigationItemPredicate predicate = new NavigationItemPredicate("mgnl:dummy");
106         MockNode node = new MockNode("name", "mgnl:dummy");
107         node.setProperty(NavigationTemplatingFunctions.HIDE_IN_NAVIGATION_PROPERTY_NAME, true);
108 
109         // WHEN THEN
110         assertFalse(predicate.evaluate(node));
111     }
112 
113     @Test
114     public void evaluateWithPageNodeTypeWhichDoesNotMatch() {
115         // GIVEN
116         NavigationItemPredicate predicate = new NavigationItemPredicate();
117         MockNode node = new MockNode("name", "mgnl:dummy");
118 
119         // WHEN THEN
120         assertFalse(predicate.evaluate(node));
121     }
122 
123     @Test
124     public void evaluateWithSpecificNodeWhichDoesNotMatch() {
125         // GIVEN
126         NavigationItemPredicate predicate = new NavigationItemPredicate("mgnl:dummy");
127         MockNode node = new MockNode("name", NodeTypes.Page.NAME);
128 
129         // WHEN THEN
130         assertFalse(predicate.evaluate(node));
131     }
132 }