add unit testing
This commit is contained in:
0
core/lib/Thelia/Core/Template/Loop/Argument/Argument.php
Normal file → Executable file
0
core/lib/Thelia/Core/Template/Loop/Argument/Argument.php
Normal file → Executable file
0
core/lib/Thelia/Core/Template/Loop/Argument/ArgumentCollection.php
Normal file → Executable file
0
core/lib/Thelia/Core/Template/Loop/Argument/ArgumentCollection.php
Normal file → Executable file
129
core/lib/Thelia/Tests/Core/Template/Loop/Argument/ArgumentTest.php
Executable file
129
core/lib/Thelia/Tests/Core/Template/Loop/Argument/ArgumentTest.php
Executable file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Core\Template\Loop\Argument;
|
||||
|
||||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
use Thelia\Type;
|
||||
use Thelia\Type\TypeCollection;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class ArgumentTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
function testArgumentCollectionConstruction()
|
||||
{
|
||||
$collection = new ArgumentCollection(
|
||||
new Argument(
|
||||
'arg0',
|
||||
new TypeCollection(
|
||||
new Type\AnyType()
|
||||
)
|
||||
),
|
||||
new Argument(
|
||||
'arg1',
|
||||
new TypeCollection(
|
||||
new Type\AnyType()
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$collection->addArgument(
|
||||
new Argument(
|
||||
'arg2',
|
||||
new TypeCollection(
|
||||
new Type\AnyType()
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertAttributeEquals(
|
||||
array(
|
||||
0 => new Argument(
|
||||
'arg0',
|
||||
new TypeCollection(
|
||||
new Type\AnyType()
|
||||
)
|
||||
),
|
||||
1 => new Argument(
|
||||
'arg1',
|
||||
new TypeCollection(
|
||||
new Type\AnyType()
|
||||
)
|
||||
),
|
||||
2 => new Argument(
|
||||
'arg2',
|
||||
new TypeCollection(
|
||||
new Type\AnyType()
|
||||
)
|
||||
),
|
||||
),
|
||||
'arguments',
|
||||
$collection
|
||||
);
|
||||
}
|
||||
|
||||
function testArgumentCollectionFetch()
|
||||
{
|
||||
$collection = new ArgumentCollection(
|
||||
new Argument(
|
||||
'arg0',
|
||||
new TypeCollection(
|
||||
new Type\AnyType()
|
||||
)
|
||||
),
|
||||
new Argument(
|
||||
'arg1',
|
||||
new TypeCollection(
|
||||
new Type\AnyType()
|
||||
)
|
||||
),
|
||||
new Argument(
|
||||
'arg2',
|
||||
new TypeCollection(
|
||||
new Type\AnyType()
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
$arguments = \PHPUnit_Framework_Assert::readAttribute($collection, 'arguments');
|
||||
|
||||
$collection->rewind();
|
||||
while ($collection->valid()) {
|
||||
|
||||
$argument = $collection->current();
|
||||
|
||||
$this->assertEquals(
|
||||
$argument,
|
||||
$arguments[$collection->key()]
|
||||
);
|
||||
|
||||
$collection->next();
|
||||
}
|
||||
}
|
||||
}
|
||||
82
core/lib/Thelia/Tests/Type/TypeTest.php
Executable file
82
core/lib/Thelia/Tests/Type/TypeTest.php
Executable file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Type;
|
||||
|
||||
use Thelia\Type;
|
||||
use Thelia\Type\TypeCollection;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class TypeTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
function testTypeCollectionConstruction()
|
||||
{
|
||||
$collection = new TypeCollection(
|
||||
new Type\AnyType(),
|
||||
new Type\AnyType()
|
||||
);
|
||||
|
||||
$collection->addType(
|
||||
new Type\AnyType()
|
||||
);
|
||||
|
||||
$this->assertAttributeEquals(
|
||||
array(
|
||||
new Type\AnyType(),
|
||||
new Type\AnyType(),
|
||||
new Type\AnyType(),
|
||||
),
|
||||
'types',
|
||||
$collection
|
||||
);
|
||||
}
|
||||
|
||||
function testTypeCollectionFetch()
|
||||
{
|
||||
$collection = new TypeCollection(
|
||||
new Type\AnyType(),
|
||||
new Type\AnyType(),
|
||||
new Type\AnyType()
|
||||
);
|
||||
|
||||
|
||||
$types = \PHPUnit_Framework_Assert::readAttribute($collection, 'types');
|
||||
|
||||
$collection->rewind();
|
||||
while ($collection->valid()) {
|
||||
|
||||
$type = $collection->current();
|
||||
|
||||
$this->assertEquals(
|
||||
$type,
|
||||
$types[$collection->key()]
|
||||
);
|
||||
|
||||
$collection->next();
|
||||
}
|
||||
}
|
||||
}
|
||||
0
core/lib/Thelia/Type/AnyType.php
Normal file → Executable file
0
core/lib/Thelia/Type/AnyType.php
Normal file → Executable file
4
core/lib/Thelia/Type/TypeCollection.php
Normal file → Executable file
4
core/lib/Thelia/Type/TypeCollection.php
Normal file → Executable file
@@ -80,7 +80,7 @@ class TypeCollection implements \Iterator
|
||||
*/
|
||||
public function next()
|
||||
{
|
||||
++$this->types;
|
||||
$this->position++;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,7 +91,7 @@ class TypeCollection implements \Iterator
|
||||
*/
|
||||
public function key()
|
||||
{
|
||||
return $this->types;
|
||||
return $this->position;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
0
core/lib/Thelia/Type/TypeInterface.php
Normal file → Executable file
0
core/lib/Thelia/Type/TypeInterface.php
Normal file → Executable file
Reference in New Issue
Block a user