From e3de9d7dd1331f9718e04cc98e9ca7cfa27cf4aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C3=A9cureuil?= Date: Sun, 17 May 2020 14:46:00 +0200 Subject: Sync with master of moonmoon ( version 9.0.0-rc) Source from https://github.com/Emmafrs/moonmoon/ --- common/tests/PlanetTest.php | 84 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 common/tests/PlanetTest.php (limited to 'common/tests/PlanetTest.php') 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 @@ +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); + } + +} -- cgit v1.2.1