diff options
author | Nicolas Lécureuil <neoclust@mageia.org> | 2020-05-17 14:46:00 +0200 |
---|---|---|
committer | Nicolas Lécureuil <neoclust@mageia.org> | 2020-05-17 14:46:00 +0200 |
commit | e3de9d7dd1331f9718e04cc98e9ca7cfa27cf4aa (patch) | |
tree | 336981502f93ceb9fa5ed33ea3b47dcefc5a8402 /common/tests/PlanetTest.php | |
parent | ff32e499745367b816d10f25e63ff3328214c32f (diff) | |
download | planet-e3de9d7dd1331f9718e04cc98e9ca7cfa27cf4aa.tar planet-e3de9d7dd1331f9718e04cc98e9ca7cfa27cf4aa.tar.gz planet-e3de9d7dd1331f9718e04cc98e9ca7cfa27cf4aa.tar.bz2 planet-e3de9d7dd1331f9718e04cc98e9ca7cfa27cf4aa.tar.xz planet-e3de9d7dd1331f9718e04cc98e9ca7cfa27cf4aa.zip |
Sync with master of moonmoon ( version 9.0.0-rc)HEADuser/wally/upstream-10-devmaster
Source from https://github.com/Emmafrs/moonmoon/
Diffstat (limited to 'common/tests/PlanetTest.php')
-rw-r--r-- | common/tests/PlanetTest.php | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/common/tests/PlanetTest.php b/common/tests/PlanetTest.php new file mode 100644 index 0000000..5cec1ce --- /dev/null +++ b/common/tests/PlanetTest.php @@ -0,0 +1,84 @@ +<?php + +use PHPUnit\Framework\TestCase; + +class FoolCategory { + + protected $name; + + function __construct($name) + { + $this->name = $name; + } + + function get_label() + { + return $this->name; + } +} + +class FoolItem +{ + protected $categories; + + function __construct($categories) + { + foreach ($categories as $c) + $this->categories[] = new FoolCategory($c); + } + + function get_categories() { + return $this->categories; + } +} + +class PlanetTest extends TestCase +{ + + protected $planet; + protected $items; + + public function setUp() + { + $this->planet = new Planet(); + + $this->items = array( + new FoolItem(array('catA', 'catB', 'catC')), + new FoolItem(array('catB')), + new FoolItem(array('catA')), + new FoolItem(array('catC')) + ); + } + + protected function _after() + { + unset($this->planet); + } + + public function testFilterItemsByCategoryWithInvalidCategory() + { + $this->assertEquals(count($this->planet->_filterItemsByCategory($this->items, null)), count($this->items)); + $this->assertEquals(count($this->planet->_filterItemsByCategory($this->items, ' ')), count($this->items)); + } + + public function testFilterItemsByCategoryWithNonUsedCategory() + { + $this->assertEquals(count($this->planet->_filterItemsByCategory($this->items, 'catD')), 0); + } + + public function testFilterItemsByCategoryWithValidCategory() + { + $this->assertEquals(count($this->planet->_filterItemsByCategory($this->items, 'catA')), 2); + $this->assertEquals(count($this->planet->_filterItemsByCategory($this->items, 'catB')), 2); + $this->assertEquals(count($this->planet->_filterItemsByCategory($this->items, 'catC')), 2); + $this->assertEquals(count($this->planet->_filterItemsByCategory($this->items, 'CATA')), 2); + } + + public function testFilterItemsByCategoryWithMultipleCategory() + { + $this->assertEquals(count($this->planet->_filterItemsByCategory($this->items, 'catA,catB')), 3); + $this->assertEquals(count($this->planet->_filterItemsByCategory($this->items, 'catA,catB,catC')), 4); + $this->assertEquals(count($this->planet->_filterItemsByCategory($this->items, 'catA, catB')), 3); + } + +} |