/** * Test load() * * @depends testNew * @dataProvider providerLoad * @depends PostingTest::testCreateCategories */ public function testLoad($catid, $exists) { $category = new KunenaForumCategory(); if ($exists) { $this->assertTrue($category->load($catid), 'Check that category exists'); } else { $this->assertFalse($category->load($catid), 'Check that category does not exist'); } $this->assertEquals($catid, $category->id, 'Check that category id is correct'); }
/** * Returns the global KunenaForumCategory object, only creating it if it doesn't already exist. * * @param int $identifier The category to load - Can be only an integer. * @param bool $reload Reload category from the database. * * @return KunenaForumCategory The Category object. * * @since 1.6 */ public static function get($identifier = null, $reload = false) { KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; if (self::$_instances === false) { self::loadCategories(); } if ($identifier instanceof KunenaForumCategory) { KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return $identifier; } if (!is_numeric($identifier)) { KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; $category = new KunenaForumCategory(); $category->load(); return $category; } $id = intval($identifier); if (empty(self::$_instances[$id])) { self::$_instances[$id] = new KunenaForumCategory(array('id' => $id)); self::$_instances[$id]->load(); } elseif ($reload) { self::$_instances[$id]->load(); } KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null; return self::$_instances[$id]; }
/** * @param int|array $keys * @return bool */ public function load( $keys = null ) { if ( is_array( $keys ) ) { return false; } $this->_category->load( (int) $keys ); if ( ! $this->_category->exists() ) { $this->_category->set( 'id', 0 ); } $this->category( $this->_category ); return true; }