mirror of
https://github.com/FreshRSS/FreshRSS.git
synced 2026-01-19 10:47:58 -05:00
* Rework the travis file to enable PHPUnit
I realized that unit tests weren't executed on Travis. While working on
this file to enable these tests, I started to think we could simplify
it.
I separated jobs so:
- PHP linter and tests are only performed on PHP 7.3
- Translations are tested separatly so they can fail (it was already the
case but it was hard to understand the way it was done)
- PHP 5.6 only checks syntax issues
- the last job checks css, js, etc. (it didn't change)
PHPUnit is not executed on 5.6 because only the version 5 is available
while the latest version is the 8 (https://phpunit.de/supported-versions.html).
I think it's easier to read (each job is more explicit) but I'm not a
Travis expert so maybe there's some room for improvements.
* Fix failing tests
The category `_name` regression was introduced in commit b323ed084.
I wasn't able to understand when and why Search tests was wrong.
The rest is about upgrade of PHPUnit.
115 lines
2.5 KiB
PHP
115 lines
2.5 KiB
PHP
<?php
|
|
|
|
class FreshRSS_Category extends Minz_Model {
|
|
private $id = 0;
|
|
private $name;
|
|
private $nbFeed = -1;
|
|
private $nbNotRead = -1;
|
|
private $feeds = null;
|
|
private $hasFeedsWithError = false;
|
|
private $isDefault = false;
|
|
private $attributes = [];
|
|
|
|
public function __construct($name = '', $feeds = null) {
|
|
$this->_name($name);
|
|
if (isset($feeds)) {
|
|
$this->_feeds($feeds);
|
|
$this->nbFeed = 0;
|
|
$this->nbNotRead = 0;
|
|
foreach ($feeds as $feed) {
|
|
$this->nbFeed++;
|
|
$this->nbNotRead += $feed->nbNotRead();
|
|
$this->hasFeedsWithError |= $feed->inError();
|
|
}
|
|
}
|
|
}
|
|
|
|
public function id() {
|
|
return $this->id;
|
|
}
|
|
public function name() {
|
|
return $this->name;
|
|
}
|
|
public function isDefault() {
|
|
return $this->isDefault;
|
|
}
|
|
public function nbFeed() {
|
|
if ($this->nbFeed < 0) {
|
|
$catDAO = FreshRSS_Factory::createCategoryDao();
|
|
$this->nbFeed = $catDAO->countFeed($this->id());
|
|
}
|
|
|
|
return $this->nbFeed;
|
|
}
|
|
public function nbNotRead() {
|
|
if ($this->nbNotRead < 0) {
|
|
$catDAO = FreshRSS_Factory::createCategoryDao();
|
|
$this->nbNotRead = $catDAO->countNotRead($this->id());
|
|
}
|
|
|
|
return $this->nbNotRead;
|
|
}
|
|
public function feeds() {
|
|
if ($this->feeds === null) {
|
|
$feedDAO = FreshRSS_Factory::createFeedDao();
|
|
$this->feeds = $feedDAO->listByCategory($this->id());
|
|
$this->nbFeed = 0;
|
|
$this->nbNotRead = 0;
|
|
foreach ($this->feeds as $feed) {
|
|
$this->nbFeed++;
|
|
$this->nbNotRead += $feed->nbNotRead();
|
|
$this->hasFeedsWithError |= $feed->inError();
|
|
}
|
|
}
|
|
|
|
return $this->feeds;
|
|
}
|
|
|
|
public function hasFeedsWithError() {
|
|
return $this->hasFeedsWithError;
|
|
}
|
|
|
|
public function attributes($key = '') {
|
|
if ($key == '') {
|
|
return $this->attributes;
|
|
} else {
|
|
return isset($this->attributes[$key]) ? $this->attributes[$key] : null;
|
|
}
|
|
}
|
|
|
|
public function _id($id) {
|
|
$this->id = $id;
|
|
if ($id == FreshRSS_CategoryDAO::DEFAULTCATEGORYID) {
|
|
$this->_name(_t('gen.short.default_category'));
|
|
}
|
|
}
|
|
public function _name($value) {
|
|
$this->name = mb_strcut(trim($value), 0, 255, 'UTF-8');
|
|
}
|
|
public function _isDefault($value) {
|
|
$this->isDefault = $value;
|
|
}
|
|
public function _feeds($values) {
|
|
if (!is_array($values)) {
|
|
$values = array($values);
|
|
}
|
|
|
|
$this->feeds = $values;
|
|
}
|
|
|
|
public function _attributes($key, $value) {
|
|
if ('' == $key) {
|
|
if (is_string($value)) {
|
|
$value = json_decode($value, true);
|
|
}
|
|
if (is_array($value)) {
|
|
$this->attributes = $value;
|
|
}
|
|
} elseif (null === $value) {
|
|
unset($this->attributes[$key]);
|
|
} else {
|
|
$this->attributes[$key] = $value;
|
|
}
|
|
}
|
|
}
|