Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
93872326
Commit
93872326
authored
Aug 08, 2016
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(unittests) extend BaseModel tests for
https://github.com/opnsense/core/issues/864
parent
710f00e8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
153 additions
and
0 deletions
+153
-0
TestModel.xml
...vc/tests/app/models/OPNsense/Base/BaseModel/TestModel.xml
+10
-0
BaseModelTest.php
...ense/mvc/tests/app/models/OPNsense/Base/BaseModelTest.php
+143
-0
No files found.
src/opnsense/mvc/tests/app/models/OPNsense/Base/BaseModel/TestModel.xml
View file @
93872326
...
...
@@ -12,5 +12,15 @@
<Required>
Y
</Required>
</FromEmail>
</general>
<arraytypes>
<item
type=
"ArrayField"
>
<number
type=
"IntegerField"
>
<MinimumValue>
1
</MinimumValue>
<MaximumValue>
65535
</MaximumValue>
<ValidationMessage>
not a valid number
</ValidationMessage>
<Required>
Y
</Required>
</number>
</item>
</arraytypes>
</items>
</model>
src/opnsense/mvc/tests/app/models/OPNsense/Base/BaseModelTest.php
View file @
93872326
...
...
@@ -29,6 +29,8 @@
namespace
tests\OPNsense\Base
;
use
\OPNsense\Core\Config
;
require_once
'BaseModel/TestModel.php'
;
class
BaseModelTest
extends
\PHPUnit_Framework_TestCase
...
...
@@ -67,4 +69,145 @@ class BaseModelTest extends \PHPUnit_Framework_TestCase
{
BaseModelTest
::
$model
->
general
->
FromEmailXXX
=
"test@test.nl"
;
}
/**
* @depends testGeneralAvailable
*/
public
function
testCanAssignArrayType
()
{
// purge test items (if any)
foreach
(
BaseModelTest
::
$model
->
arraytypes
->
item
->
__items
as
$nodeid
=>
$node
)
{
BaseModelTest
::
$model
->
arraytypes
->
item
->
Del
(
$nodeid
);
}
// generate new items
for
(
$i
=
1
;
$i
<=
10
;
$i
++
)
{
$node
=
BaseModelTest
::
$model
->
arraytypes
->
item
->
Add
();
$node
->
number
=
$i
;
}
// flush to disk
BaseModelTest
::
$model
->
serializeToConfig
();
Config
::
getInstance
()
->
save
();
// load from disk
Config
::
getInstance
()
->
forceReload
();
BaseModelTest
::
$model
=
new
BaseModel\TestModel
();
// read items, logically the sequence should be the same as the generated items
$i
=
1
;
foreach
(
BaseModelTest
::
$model
->
arraytypes
->
item
->
__items
as
$node
)
{
$this
->
assertEquals
(
$i
,
(
string
)
$node
->
number
);
$i
++
;
}
}
/**
* @depends testCanAssignArrayType
*/
public
function
testCanDeleteSpecificItem
()
{
foreach
(
BaseModelTest
::
$model
->
arraytypes
->
item
->
__items
as
$nodeid
=>
$node
)
{
if
((
string
)
$node
->
number
==
5
)
{
BaseModelTest
::
$model
->
arraytypes
->
item
->
Del
(
$nodeid
);
}
}
// item with number 5 should be deleted
foreach
(
BaseModelTest
::
$model
->
arraytypes
->
item
->
__items
as
$nodeid
=>
$node
)
{
$this
->
assertNotEquals
((
string
)
$node
->
number
,
5
);
}
// 9 items left
$this
->
assertEquals
(
count
(
BaseModelTest
::
$model
->
arraytypes
->
item
->
__items
),
9
);
}
/**
* @depends testCanAssignArrayType
*/
public
function
testArrayIsKeydByUUID
()
{
foreach
(
BaseModelTest
::
$model
->
arraytypes
->
item
->
__items
as
$nodeid
=>
$node
)
{
$this
->
assertCount
(
5
,
explode
(
'-'
,
$nodeid
));
}
}
/**
* @depends testCanAssignArrayType
*/
public
function
testValidationOk
()
{
// nothing changed, valid config
BaseModelTest
::
$model
->
serializeToConfig
();
}
/**
* @depends testCanAssignArrayType
* @expectedException \Phalcon\Validation\Exception
* @expectedExceptionMessage not a valid number
*/
public
function
testValidationNOK
()
{
// replace all numbers
foreach
(
BaseModelTest
::
$model
->
arraytypes
->
item
->
__items
as
$nodeid
=>
$node
)
{
$node
->
number
=
"XXX"
;
}
BaseModelTest
::
$model
->
serializeToConfig
();
}
/**
* @depends testGeneralAvailable
*/
public
function
testsetNodeByReferenceFound
()
{
$this
->
assertEquals
(
BaseModelTest
::
$model
->
setNodeByReference
(
'general.FromEmail'
,
'test@test.com'
),
true
);
}
/**
* @depends testGeneralAvailable
*/
public
function
testsetNodeByReferenceNotFound
()
{
$this
->
assertEquals
(
BaseModelTest
::
$model
->
setNodeByReference
(
'general.FromEmailxx'
,
'test@test.com'
),
false
);
}
/**
* @depends testCanDeleteSpecificItem
*/
public
function
testGenerateXML
()
{
$xml
=
BaseModelTest
::
$model
->
toXML
();
$this
->
assertInstanceOf
(
\SimpleXMLElement
::
class
,
$xml
);
$this
->
assertNotEquals
(
count
(
$xml
->
OPNsense
),
0
);
$this
->
assertNotEquals
(
count
(
$xml
->
OPNsense
->
TestModel
),
0
);
$this
->
assertNotEquals
(
count
(
$xml
->
OPNsense
->
TestModel
->
general
),
0
);
// expect 9 detail items at this point
$this
->
assertEquals
(
count
(
$xml
->
OPNsense
->
TestModel
->
arraytypes
->
item
),
9
);
}
/**
* @depends testCanDeleteSpecificItem
*/
public
function
testSetNode
()
{
$data
=
array
();
$i
=
100
;
foreach
(
BaseModelTest
::
$model
->
arraytypes
->
item
->
__items
as
$nodeid
=>
$node
)
{
$data
[
$node
->
__reference
]
=
$i
;
$i
++
;
}
foreach
(
$data
as
$key
=>
$value
)
{
$node
=
BaseModelTest
::
$model
->
getNodeByReference
(
$key
);
$node
->
setNodes
(
array
(
'number'
=>
$value
));
}
foreach
(
BaseModelTest
::
$model
->
arraytypes
->
item
->
__items
as
$nodeid
=>
$node
)
{
$this
->
assertGreaterThan
(
99
,
(
string
)
$node
->
number
);
}
}
/**
* @depends testCanDeleteSpecificItem
*/
public
function
testGetNodes
()
{
$data
=
BaseModelTest
::
$model
->
arraytypes
->
item
->
getNodes
();
$this
->
assertEquals
(
count
(
$data
),
9
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment