Skip to content

Commit 727fd71

Browse files
committed
Add NestedRule struct class
1 parent c3b3e0c commit 727fd71

File tree

4 files changed

+898
-3
lines changed

4 files changed

+898
-3
lines changed

Struct/FilterRule.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ class FilterRule extends Base
2929
* @param bool $active Active flag. Set by default.
3030
* @param FilterTests $filterTests Filter tests
3131
* @param FilterActions $filterActions Filter actions
32+
* @param NestedRule $child NestedRule child
3233
* @return self
3334
*/
3435
public function __construct(
3536
$name,
3637
$active,
3738
FilterTests $filterTests,
38-
FilterActions $filterActions = NULL
39+
FilterActions $filterActions = NULL,
40+
NestedRule $child = NULL
3941
)
4042
{
4143
parent::__construct();
@@ -46,6 +48,10 @@ public function __construct(
4648
{
4749
$this->setChild('filterActions', $filterActions);
4850
}
51+
if($child instanceof NestedRule)
52+
{
53+
$this->setChild('nestedRule', $child);
54+
}
4955
}
5056

5157
/**
@@ -132,6 +138,27 @@ public function setFilterActions(FilterActions $filterActions)
132138
return $this->setChild('filterActions', $filterActions);
133139
}
134140

141+
/**
142+
* Gets child
143+
*
144+
* @return NestedRule
145+
*/
146+
public function getChildRule()
147+
{
148+
return $this->getChild('nestedRule');
149+
}
150+
151+
/**
152+
* Sets child
153+
*
154+
* @param NestedRule $child
155+
* @return self
156+
*/
157+
public function setChildRule(NestedRule $child)
158+
{
159+
return $this->setChild('nestedRule', $child);
160+
}
161+
135162
/**
136163
* Returns the array representation of this class
137164
*

Struct/NestedRule.php

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<?php
2+
/**
3+
* This file is part of the Zimbra API in PHP library.
4+
*
5+
* © Nguyen Van Nguyen <nguyennv1981@gmail.com>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace Zimbra\Mail\Struct;
12+
13+
use Zimbra\Struct\Base;
14+
15+
/**
16+
* NestedRule struct class
17+
*
18+
* @package Zimbra
19+
* @subpackage Mail
20+
* @category Struct
21+
* @author Nguyen Van Nguyen - nguyennv1981@gmail.com
22+
* @copyright Copyright © 2013 by Nguyen Van Nguyen.
23+
*/
24+
class NestedRule extends Base
25+
{
26+
/**
27+
* Constructor method for NestedRule
28+
* @param FilterTests $filterTests Filter tests
29+
* @param FilterActions $filterActions Filter actions
30+
* @param NestedRule $child NestedRule child
31+
* @return self
32+
*/
33+
public function __construct(
34+
FilterTests $filterTests,
35+
FilterActions $filterActions = NULL,
36+
NestedRule $child = NULL
37+
)
38+
{
39+
parent::__construct();
40+
$this->setChild('filterTests', $filterTests);
41+
if($filterActions instanceof FilterActions)
42+
{
43+
$this->setChild('filterActions', $filterActions);
44+
}
45+
if($child instanceof NestedRule)
46+
{
47+
$this->setChild('nestedRule', $child);
48+
}
49+
}
50+
51+
/**
52+
* Gets filter tests
53+
*
54+
* @return FilterTests
55+
*/
56+
public function getFilterTests()
57+
{
58+
return $this->getChild('filterTests');
59+
}
60+
61+
/**
62+
* Sets filter tests
63+
*
64+
* @param FilterTests $filterTests
65+
* @return self
66+
*/
67+
public function setFilterTests(FilterTests $filterTests)
68+
{
69+
return $this->setChild('filterTests', $filterTests);
70+
}
71+
72+
/**
73+
* Gets filter actions
74+
*
75+
* @return FilterActions
76+
*/
77+
public function getFilterActions()
78+
{
79+
return $this->getChild('filterActions');
80+
}
81+
82+
/**
83+
* Sets filter actions
84+
*
85+
* @param FilterActions $filterActions
86+
* @return self
87+
*/
88+
public function setFilterActions(FilterActions $filterActions)
89+
{
90+
return $this->setChild('filterActions', $filterActions);
91+
}
92+
93+
/**
94+
* Gets child
95+
*
96+
* @return NestedRule
97+
*/
98+
public function getChildRule()
99+
{
100+
return $this->getChild('nestedRule');
101+
}
102+
103+
/**
104+
* Sets child
105+
*
106+
* @param NestedRule $child
107+
* @return self
108+
*/
109+
public function setChildRule(NestedRule $child)
110+
{
111+
return $this->setChild('nestedRule', $child);
112+
}
113+
114+
/**
115+
* Returns the array representation of this class
116+
*
117+
* @param string $name
118+
* @return array
119+
*/
120+
public function toArray($name = 'nestedRule')
121+
{
122+
return parent::toArray($name);
123+
}
124+
125+
/**
126+
* Method returning the xml representation of this class
127+
*
128+
* @param string $name
129+
* @return SimpleXML
130+
*/
131+
public function toXml($name = 'nestedRule')
132+
{
133+
return parent::toXml($name);
134+
}
135+
}

Tests/Struct/FilterRuleTest.php

Lines changed: 169 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,22 +161,26 @@ public function testFilterRule()
161161
];
162162
$filterActions = new \Zimbra\Mail\Struct\FilterActions($actions);
163163

164+
$child = new \Zimbra\Mail\Struct\NestedRule($filterTests);
164165
$filterRule = new \Zimbra\Mail\Struct\FilterRule(
165-
$name, true, $filterTests, $filterActions
166+
$name, true, $filterTests, $filterActions, $child
166167
);
167168
$this->assertSame($name, $filterRule->getName());
168169
$this->assertTrue($filterRule->getActive());
169170
$this->assertSame($filterTests, $filterRule->getFilterTests());
170171
$this->assertSame($filterActions, $filterRule->getFilterActions());
172+
$this->assertSame($child, $filterRule->getChildRule());
171173

172174
$filterRule->setName($name)
173175
->setActive(true)
174176
->setFilterTests($filterTests)
175-
->setFilterActions($filterActions);
177+
->setFilterActions($filterActions)
178+
->setChildRule($child);
176179
$this->assertSame($name, $filterRule->getName());
177180
$this->assertTrue($filterRule->getActive());
178181
$this->assertSame($filterTests, $filterRule->getFilterTests());
179182
$this->assertSame($filterActions, $filterRule->getFilterActions());
183+
$this->assertSame($child, $filterRule->getChildRule());
180184

181185
$xml = '<?xml version="1.0"?>' . "\n"
182186
.'<filterRule name="' . $name . '" active="true">'
@@ -223,6 +227,36 @@ public function testFilterRule()
223227
.'</actionNotify>'
224228
.'<actionStop index="' . $index . '" />'
225229
.'</filterActions>'
230+
.'<nestedRule>'
231+
.'<filterTests condition="' . FilterCondition::ALL_OF() . '">'
232+
.'<addressBookTest index="' . $index . '" negative="true" header="' . $header . '" />'
233+
.'<addressTest index="' . $index . '" negative="true" header="' . $header . '" part="' . $part . '" stringComparison="' . $comparison . '" value="' . $value . '" caseSensitive="true" />'
234+
.'<attachmentTest index="' . $index . '" negative="true" />'
235+
.'<bodyTest index="' . $index . '" negative="true" value="' . $value . '" caseSensitive="true" />'
236+
.'<bulkTest index="' . $index . '" negative="true" />'
237+
.'<contactRankingTest index="' . $index . '" negative="true" header="' . $header . '" />'
238+
.'<conversationTest index="' . $index . '" negative="true" where="' . $where . '" />'
239+
.'<currentDayOfWeekTest index="' . $index . '" negative="true" value="' . $value . '" />'
240+
.'<currentTimeTest index="' . $index . '" negative="true" dateComparison="' . $comparison . '" time="' . $time . '" />'
241+
.'<dateTest index="' . $index . '" negative="true" dateComparison="' . $comparison . '" d="' . $date . '" />'
242+
.'<facebookTest index="' . $index . '" negative="true" />'
243+
.'<flaggedTest index="' . $index . '" negative="true" flagName="' . $flag . '" />'
244+
.'<headerExistsTest index="' . $index . '" negative="true" header="' . $header . '" />'
245+
.'<headerTest index="' . $index . '" negative="true" header="' . $header . '" stringComparison="' . $comparison . '" value="' . $value . '" caseSensitive="true" />'
246+
.'<importanceTest index="' . $index . '" negative="true" imp="' . Importance::HIGH() . '" />'
247+
.'<inviteTest index="' . $index . '" negative="true">'
248+
.'<method>' . $method . '</method>'
249+
.'</inviteTest>'
250+
.'<linkedinTest index="' . $index . '" negative="true" />'
251+
.'<listTest index="' . $index . '" negative="true" />'
252+
.'<meTest index="' . $index . '" negative="true" header="' . $header . '" />'
253+
.'<mimeHeaderTest index="' . $index . '" negative="true" header="' . $header . '" stringComparison="' . $comparison . '" value="' . $value . '" caseSensitive="true" />'
254+
.'<sizeTest index="' . $index . '" negative="true" numberComparison="' . $comparison . '" s="' . $size . '" />'
255+
.'<socialcastTest index="' . $index . '" negative="true" />'
256+
.'<trueTest index="' . $index . '" negative="true" />'
257+
.'<twitterTest index="' . $index . '" negative="true" />'
258+
.'</filterTests>'
259+
.'</nestedRule>'
226260
.'</filterRule>';
227261
$this->assertXmlStringEqualsXmlString($xml, (string) $filterRule);
228262

@@ -400,6 +434,139 @@ public function testFilterRule()
400434
'index' => $index,
401435
),
402436
),
437+
'nestedRule' => array(
438+
'filterTests' => array(
439+
'condition' => FilterCondition::ALL_OF()->value(),
440+
'addressBookTest' => array(
441+
'index' => $index,
442+
'negative' => true,
443+
'header' => $header,
444+
),
445+
'addressTest' => array(
446+
'index' => $index,
447+
'negative' => true,
448+
'header' => $header,
449+
'part' => $part,
450+
'stringComparison' => $comparison,
451+
'value' => $value,
452+
'caseSensitive' => true,
453+
),
454+
'attachmentTest' => array(
455+
'index' => $index,
456+
'negative' => true,
457+
),
458+
'bodyTest' => array(
459+
'index' => $index,
460+
'negative' => true,
461+
'value' => $value,
462+
'caseSensitive' => true,
463+
),
464+
'bulkTest' => array(
465+
'index' => $index,
466+
'negative' => true,
467+
),
468+
'contactRankingTest' => array(
469+
'index' => $index,
470+
'negative' => true,
471+
'header' => $header,
472+
),
473+
'conversationTest' => array(
474+
'index' => $index,
475+
'negative' => true,
476+
'where' => $where,
477+
),
478+
'currentDayOfWeekTest' => array(
479+
'index' => $index,
480+
'negative' => true,
481+
'value' => $value,
482+
),
483+
'currentTimeTest' => array(
484+
'index' => $index,
485+
'negative' => true,
486+
'dateComparison' => $comparison,
487+
'time' => $time,
488+
),
489+
'dateTest' => array(
490+
'index' => $index,
491+
'negative' => true,
492+
'dateComparison' => $comparison,
493+
'd' => $date,
494+
),
495+
'facebookTest' => array(
496+
'index' => $index,
497+
'negative' => true,
498+
),
499+
'flaggedTest' => array(
500+
'index' => $index,
501+
'negative' => true,
502+
'flagName' => $flag,
503+
),
504+
'headerExistsTest' => array(
505+
'index' => $index,
506+
'negative' => true,
507+
'header' => $header,
508+
),
509+
'headerTest' => array(
510+
'index' => $index,
511+
'negative' => true,
512+
'header' => $header,
513+
'stringComparison' => $comparison,
514+
'value' => $value,
515+
'caseSensitive' => true,
516+
),
517+
'importanceTest' => array(
518+
'index' => $index,
519+
'negative' => true,
520+
'imp' => Importance::HIGH()->value(),
521+
),
522+
'inviteTest' => array(
523+
'index' => $index,
524+
'negative' => true,
525+
'method' => array(
526+
$method,
527+
),
528+
),
529+
'linkedinTest' => array(
530+
'index' => $index,
531+
'negative' => true,
532+
),
533+
'listTest' => array(
534+
'index' => $index,
535+
'negative' => true,
536+
),
537+
'meTest' => array(
538+
'index' => $index,
539+
'negative' => true,
540+
'header' => $header,
541+
),
542+
'mimeHeaderTest' => array(
543+
'index' => $index,
544+
'negative' => true,
545+
'header' => $header,
546+
'stringComparison' => $comparison,
547+
'value' => $value,
548+
'caseSensitive' => true,
549+
),
550+
'sizeTest' => array(
551+
'index' => $index,
552+
'negative' => true,
553+
'numberComparison' => $comparison,
554+
's' => $size,
555+
),
556+
'socialcastTest' => array(
557+
'index' => $index,
558+
'negative' => true,
559+
),
560+
'trueTest' => array(
561+
'index' => $index,
562+
'negative' => true,
563+
),
564+
'twitterTest' => array(
565+
'index' => $index,
566+
'negative' => true,
567+
),
568+
),
569+
),
403570
),
404571
);
405572
$this->assertEquals($array, $filterRule->toArray());

0 commit comments

Comments
 (0)