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
c2036dfb
Commit
c2036dfb
authored
Apr 23, 2016
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(mvc) setup initial framework unit tests
parent
d8e91d1e
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
394 additions
and
0 deletions
+394
-0
PHPunit.xml
src/opnsense/mvc/tests/PHPunit.xml
+21
-0
config.php
src/opnsense/mvc/tests/app/config/config.php
+19
-0
TestModel.php
...vc/tests/app/models/OPNsense/Base/BaseModel/TestModel.php
+38
-0
TestModel.xml
...vc/tests/app/models/OPNsense/Base/BaseModel/TestModel.xml
+16
-0
BaseModelTest.php
...ense/mvc/tests/app/models/OPNsense/Base/BaseModelTest.php
+71
-0
Field_Framework_TestCase.php
...els/OPNsense/Base/FieldTypes/Field_Framework_TestCase.php
+89
-0
IntegerFieldTest.php
.../app/models/OPNsense/Base/FieldTypes/IntegerFieldTest.php
+89
-0
setup.php
src/opnsense/mvc/tests/setup.php
+51
-0
No files found.
src/opnsense/mvc/tests/PHPunit.xml
0 → 100644
View file @
c2036dfb
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
bootstrap=
"./setup.php"
backupGlobals=
"false"
backupStaticAttributes=
"false"
verbose=
"true"
colors=
"false"
convertErrorsToExceptions=
"true"
convertNoticesToExceptions=
"true"
convertWarningsToExceptions=
"true"
processIsolation=
"false"
stopOnFailure=
"false"
syntaxCheck=
"true"
>
<groups>
<exclude>
<group>
Ignore
</group>
</exclude>
</groups>
<testsuite
name=
"OPNsense - Testsuite"
>
<directory
suffix=
"Test.php"
>
./app
</directory>
</testsuite>
</phpunit>
\ No newline at end of file
src/opnsense/mvc/tests/app/config/config.php
0 → 100644
View file @
c2036dfb
<?php
return
new
\Phalcon\Config
(
array
(
'application'
=>
array
(
'controllersDir'
=>
__DIR__
.
'/../../../app/controllers/'
,
'modelsDir'
=>
__DIR__
.
'/../../../app/models/'
,
'viewsDir'
=>
__DIR__
.
'/../../../app/views/'
,
'pluginsDir'
=>
__DIR__
.
'/../../../app/plugins/'
,
'libraryDir'
=>
__DIR__
.
'/../../../app/library/'
,
'cacheDir'
=>
__DIR__
.
'/../../../app/cache/'
,
'baseUri'
=>
'/opnsense_gui/'
,
),
'globals'
=>
array
(
'config_path'
=>
'/conf/'
,
'temp_path'
=>
'/tmp/'
,
'debug'
=>
false
,
'simulate_mode'
=>
false
)
));
src/opnsense/mvc/tests/app/models/OPNsense/Base/BaseModel/TestModel.php
0 → 100644
View file @
c2036dfb
<?php
/**
* Copyright (C) 2016 Deciso B.V.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
namespace
tests\OPNsense\Base\BaseModel
;
use
OPNsense\Base\BaseModel
;
/**
* Class TestModel
*/
class
TestModel
extends
BaseModel
{
}
src/opnsense/mvc/tests/app/models/OPNsense/Base/BaseModel/TestModel.xml
0 → 100644
View file @
c2036dfb
<model>
<mount>
//tests/OPNsense/TestModel
</mount>
<description>
OPNsense RecursiveModel test
</description>
<items>
<!-- container -->
<general>
<!-- fields -->
<FromEmail
type=
"EmailField"
>
<default>
sample@example.com
</default>
<Required>
Y
</Required>
</FromEmail>
</general>
</items>
</model>
src/opnsense/mvc/tests/app/models/OPNsense/Base/BaseModelTest.php
0 → 100644
View file @
c2036dfb
<?php
/**
* Copyright (C) 2016 Deciso B.V.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
namespace
tests\OPNsense\Base
;
require_once
'BaseModel/TestModel.php'
;
class
BaseModelTest
extends
\PHPUnit_Framework_TestCase
{
private
static
$model
=
null
;
public
function
testCanBeCreated
()
{
BaseModelTest
::
$model
=
new
BaseModel\TestModel
();
$this
->
assertInstanceOf
(
'tests\OPNsense\Base\BaseModel\TestModel'
,
BaseModelTest
::
$model
);
}
/**
* @depends testCanBeCreated
*/
public
function
testGeneralAvailable
()
{
$this
->
assertNotNull
(
BaseModelTest
::
$model
->
general
);
}
/**
* @depends testGeneralAvailable
*/
public
function
testCanSetStringValue
()
{
BaseModelTest
::
$model
->
general
->
FromEmail
=
"test@test.nl"
;
$this
->
assertEquals
(
BaseModelTest
::
$model
->
general
->
FromEmail
,
"test@test.nl"
);
}
/**
* @expectedException InvalidArgumentException
* @expectedExceptionMessage FromEmailXXX not an attribute of general
* @depends testGeneralAvailable
*/
public
function
testCannotSetNonExistingField
()
{
BaseModelTest
::
$model
->
general
->
FromEmailXXX
=
"test@test.nl"
;
}
}
src/opnsense/mvc/tests/app/models/OPNsense/Base/FieldTypes/Field_Framework_TestCase.php
0 → 100644
View file @
c2036dfb
<?php
/**
* Copyright (C) 2016 Deciso B.V.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
namespace
tests\OPNsense\Base\FieldTypes
;
/**
* Class Field_Framework_TestCase
* @package tests\OPNsense\Base\FieldTypes
*/
class
Field_Framework_TestCase
extends
\PHPUnit_Framework_TestCase
{
/**
* Validate and throw exception
* @param $field feld type
* @throws \Phalcon\Validation\Exception
*/
public
function
validateThrow
(
$field
)
{
$validation
=
new
\Phalcon\Validation
();
foreach
(
$field
->
getValidators
()
as
$validator
)
{
$validation
->
add
(
"testfield"
,
$validator
);
}
$messages
=
$validation
->
validate
(
array
(
"testfield"
=>
(
string
)
$field
));
if
(
count
(
$messages
))
{
foreach
(
$messages
as
$message
)
{
throw
new
\Phalcon\Validation\Exception
(
$message
->
getType
());
}
}
return
;
}
/**
* Validate and return exceptions
* @param $field feld type
* @return array
*/
public
function
validate
(
$field
)
{
$result
=
array
();
$validation
=
new
\Phalcon\Validation
();
foreach
(
$field
->
getValidators
()
as
$validator
)
{
$validation
->
add
(
"testfield"
,
$validator
);
}
$messages
=
$validation
->
validate
(
array
(
"testfield"
=>
(
string
)
$field
));
if
(
count
(
$messages
))
{
foreach
(
$messages
as
$message
)
{
$result
[]
=
$message
->
getType
();
}
}
return
$result
;
}
/**
* do not test
* @group Ignore
*/
public
function
testIgnore
()
{
return
;
}
}
\ No newline at end of file
src/opnsense/mvc/tests/app/models/OPNsense/Base/FieldTypes/IntegerFieldTest.php
0 → 100644
View file @
c2036dfb
<?php
/**
* Copyright (C) 2016 Deciso B.V.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
namespace
tests\OPNsense\Base\FieldTypes
;
// @CodingStandardsIgnoreStart
require_once
'Field_Framework_TestCase.php'
;
// @CodingStandardsIgnoreEnd
use
\OPNsense\Base\FieldTypes\IntegerField
;
class
IntegerFieldTest
extends
Field_Framework_TestCase
{
/**
* test construct
*/
public
function
testCanBeCreated
()
{
$this
->
assertInstanceOf
(
'\OPNsense\Base\FieldTypes\IntegerField'
,
new
IntegerField
());
}
/**
* @expectedException \Phalcon\Validation\Exception
* @expectedExceptionMessage MaxMinValidator
*/
public
function
testValueLargerThenMax
()
{
$field
=
new
IntegerField
();
$field
->
setMaximumValue
(
100
);
$field
->
setMinimumValue
(
10
);
$field
->
setValue
(
"120"
);
$this
->
validateThrow
(
$field
);
}
/**
* @expectedException \Phalcon\Validation\Exception
* @expectedExceptionMessage MaxMinValidator
*/
public
function
testValueSmallerThenMin
()
{
$field
=
new
IntegerField
();
$field
->
setMaximumValue
(
100
);
$field
->
setMinimumValue
(
10
);
$field
->
setValue
(
"5"
);
$this
->
validateThrow
(
$field
);
}
/**
* not a number
*/
public
function
testNotANumber
()
{
$field
=
new
IntegerField
();
$field
->
setMaximumValue
(
100
);
$field
->
setMinimumValue
(
10
);
$field
->
setValue
(
"5x1"
);
$this
->
assertContains
(
'IntegerValidator'
,
$this
->
validate
(
$field
));
}
}
src/opnsense/mvc/tests/setup.php
0 → 100644
View file @
c2036dfb
<?php
/**
* Copyright (C) 2016 Deciso B.V.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
use
Phalcon\Di
;
use
Phalcon\Di\FactoryDefault
;
ini_set
(
'display_errors'
,
1
);
error_reporting
(
E_ALL
);
/**
* Read the configuration
*/
$config
=
include
__DIR__
.
"/app/config/config.php"
;
/**
* Read auto-loader
*/
include
__DIR__
.
"/../app/config/loader.php"
;
$di
=
new
FactoryDefault
();
Di
::
reset
();
$di
->
set
(
'config'
,
$config
);
Di
::
setDefault
(
$di
);
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