]>
git.agnieray.net Git - galette.git/blob - tests/Galette/IO/tests/units/News.php
37079649dcb60a626fef7ca673747ac491e91a83
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
10 * Copyright © 2017-2023 The Galette Team
12 * This file is part of Galette (http://galette.tuxfamily.org).
14 * Galette is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * Galette is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
28 * @package GaletteTests
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2017-2023 The Galette Team
32 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
34 * @link http://galette.tuxfamily.org
38 namespace Galette\IO\test\units
;
47 * @package GaletteTests
48 * @author Johan Cwiklinski <johan@x-tnd.be>
49 * @copyright 2017-2023 The Galette Team
50 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
51 * @link http://galette.tuxfamily.org
54 class News
extends atoum
56 private \Galette\Core\I18n
$i18n;
61 * @param string $method Method name
65 public function beforeTestMethod($method)
67 $this->i18n
= new \Galette\Core\
I18n();
77 public function testLoadNews()
79 //ensure allow_url_fopen is on
80 ini_set('allow_url_fopen', true);
81 //load news without caching
82 $news = new \Galette\IO\
News('https://galette.eu/site/feed.xml', true);
83 $posts = $news->getPosts();
85 ->size
->isGreaterThan(0);
93 public function testCacheNews()
95 //will use default lang to build RSS URL
96 $file = GALETTE_CACHE_DIR
. md5('https://galette.eu/site/feed.xml') . '.cache';
98 //ensure file does not exists
99 $this->boolean(file_exists($file))->isFalse
;
101 //load news with caching
102 $news = new \Galette\IO\
News('https://galette.eu/site/feed.xml');
104 $posts = $news->getPosts();
106 ->size
->isGreaterThan(0);
108 //ensure file does exists
109 $this->boolean(file_exists($file))->isTrue
;
111 $dformat = 'Y-m-d H:i:s';
112 $mdate = \DateTime
::createFromFormat(
120 $expired = $mdate->sub(
121 new \
DateInterval('PT25H')
123 $touched = touch($file, $expired->getTimestamp());
124 $this->boolean($touched)->isTrue
;
126 $news = new \Galette\IO\
News('https://galette.eu/site/feed.xml');
127 $mnewdate = \DateTime
::createFromFormat(
134 $isnewdate = $mnewdate > $mdate;
135 $this->boolean($isnewdate)->isTrue
;
143 * Test news loading with allow_url_fopen off
147 public function testLoadNewsWExeption()
149 $this->assert('News cannot be loaded')
150 ->if($this->function->ini_get
= 0)
151 ->given($news = new \Galette\IO\
News('https://galette.eu/site/feed.xml', true))
153 ->array($news->getPosts())