Newer
Older
<?php
/**
* Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
*
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
abstract class SitoControllerTestCase extends AbstractControllerTestCase {
protected $hackers;
public function setUp() {
parent::setUp();
$this->hackers=$this->fixture('Class_SitothequeCategorie',
['id' => 3,
'libelle' => 'Hackers']);
$this->fixture('Class_Sitotheque',
['id' => 5,
'id_cat' => 3,
'titre' => 'LinuxFr',
'description' => 'Pour tous les linuxiens',
'url' => 'http://linuxfr.org']);
$this->fixture('Class_Sitotheque',
['id' => 28,
'id_cat' => 0,
'titre' => 'Hurd',
'description' => 'Pour tous les Gnus',
'url' => 'http://hurd.gnu.org']);
Class_Profil::getCurrentProfil()
->setCfgAccueil([
'modules' => [
'1' => [
'division' => '2',
'type_module' => 'SITO',
'preferences' => ['id_categorie' => '3',

lbrun
committed
'rss_status' => 1,
'nb_aff' => 1,
'display_order' => 'Selection']
abstract class SitoControllerViewCategoryAndRecentTestCase extends SitoControllerTestCase {
public function setUp() {
parent::setUp();
$collectif = $this->fixture('Class_SitothequeCategorie',
['id' => 12,
'parent_categorie' => $this->hackers,
'libelle' => 'Collectifs' ]);
$associations = $this->fixture('Class_SitothequeCategorie',
['id' => 17,
'parent_categorie' => $collectif,
'libelle' => 'Associations' ]);
$libre = $this->fixture('Class_SitothequeCategorie',
['id' => 19,
'parent_categorie' => $associations,
'libelle' => 'Libre' ]);
$quadrature = $this->fixture('Class_Sitotheque',
['id' => 280,
'categorie' => $libre,
'titre' => 'La quadrature du net',
'description' => 'Internet et libertés',
'url' => 'http://laquadrature.net']);
$quadrature->setDateMaj('1970-01-01 00:00:00');
$this->fixture('Class_Sitotheque',
['id' => 282,
'categorie' => $associations,
'titre' => 'April',
'description' => 'Promouvoir le logiciel libre',
'url' => 'http://april.org']);
$framasoft = $this->fixture('Class_Sitotheque',
['id' => 281,
'categorie' => $collectif,
'titre' => 'Framasoft',
'description' => 'Degooglisons internet',
'url' => 'http://framasoft.org']);
$framasoft->setDateMaj('9999-12-12 00:00:00');
}
}
abstract class SitoControllerViewCategoryTestCase extends SitoControllerViewCategoryAndRecentTestCase {
public function setUp() {
parent::setUp();
Class_Profil::getCurrentProfil()
->setCfgAccueil(['modules' => ['1' => ['division' => '2',
'type_module' => 'SITO',
'preferences' => ['id_categorie' => '12',
'type_aff' => '3',
class SitoControllerViewCategoryTest extends SitoControllerViewCategoryTestCase {
public function setUp() {
parent::setUp();
$this->dispatch('/sito/viewcategory/id_cat/12/start_cat/12', true);
}
public function linuxFrShouldNotBeShown() {
$this->assertNotXPath('//div[@class="sitotheque"]//a[@href="http://linuxfr.org"]',
$this->_response->getBody());
}
/** @test */
public function framasoftShouldBeShown() {
$this->assertXPath('//div[@class="sitotheque"]//a[@href="http://framasoft.org"]',
$this->_response->getBody());
}
/** @test */
public function catAssocShouldContains2sites() {
$this->assertXPathContentContains('//div//a[@href="/sito/viewcategory/start_cat/12/id_cat/17"]', 'Associations (2)',
$this->_response->getBody());
}

efalcy
committed
/** @test */
public function breadCrumbShouldStartWithCollectifs() {
$this->assertXPath('//div/a[1][@href="/sito/viewcategory/start_cat/12/id_cat/12"]',
$this->_response->getBody());
}
class SitoControllerViewRecentTest extends SitoControllerTestCase {
/** @test */
public function linuxFrShouldBeVisible() {
$this->assertXPath('//div[@class="contenu"]//div[@class="sitotheque"]//a[@href="http://linuxfr.org"]',
$this->_response->getBody());
}
}
abstract class SitoControllerViewRecentTestCase extends SitoControllerViewCategoryAndRecentTestCase {
public function setUp() {
parent::setUp();
Class_Profil::getCurrentProfil()
->setCfgAccueil(['modules' => ['1' => ['division' => '2',
'type_module' => 'SITO',
'preferences' => ['id_categorie' => '12',
'type_aff' => '2',
'id_items' => '280-281']]],
'options' => []]);
}
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
class SitoControllerViewRecentWithCategoryTest extends SitoControllerViewRecentTestCase {
public function setUp() {
parent::setUp();
$this->dispatch('/sito/viewrecent/nb/10/id_cat/12', true);
}
/** @test */
public function linuxFrShouldNotBeShown() {
$this->assertNotXPath('//div[@class="sitotheque"]//a[@href="http://linuxfr.org"]',
$this->_response->getBody());
}
/** @test */
public function framasoftShouldBeShownFirst() {
$this->assertXPath('(//div[@class="sitotheque"])[1]//a[@href="http://framasoft.org"]',
$this->_response->getBody());
}
/** @test */
public function aprilShouldBeShownSecond() {
$this->assertXPath('(//div[@class="sitotheque"])[2]//a[@href="http://april.org"]',
$this->_response->getBody());
}
/** @test */
public function quadratureShouldBeShownLast() {
$this->assertXPath('(//div[@class="sitotheque"])[3]//a[@href="http://laquadrature.net"]',
$this->_response->getBody());
}
class SitoControllerViewCategorySearchTest extends SitoControllerViewCategoryTestCase {
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Sitotheque')
->whenCalled('findAllBy')
->with(['where' => 'titre like \'%framasoft%\'',
'order' => 'titre',
'limitPage' => [1, 25],
'id_cat' => [17, 19, 12]])
->answers([Class_Sitotheque::find(281)]);
$this->dispatch('/sito/viewcategory/start_cat/12/title_search/framasoft', true);
}
/** @test */
public function framasoftShouldBeShown() {
$this->assertXPath('//div[@class="sitotheque"]//a[@href="http://framasoft.org"]',
$this->_response->getBody());
}
public function linuxFrShouldNotBeShown() {
$this->assertNotXPath('//div[@class="sitotheque"]//a[@href="http://linuxfr.org"]',
$this->_response->getBody());
}
/** @test */
public function formTitleSearchShouldContainsStartCat() {
$this->assertXPath('//form[@id="list_search_form"][@action="/sito/viewcategory/start_cat/12"]',
$this->_response->getBody());
}
class SitoControllerViewSelectionTest extends SitoControllerTestCase {
$this->dispatch('/sito/viewselection/id_module/1', true);;
/** @test */
public function siteLinuxFrShouldBeVisible() {
$this->assertXPath('//div[@class="contenu"]//div[@class="sitotheque"]//a[@href="http://linuxfr.org"]',
$this->_response->getBody());
}
/** @test */
public function siteHurdDotOrgShouldBeVisible() {
$this->assertXPath('//div[@class="contenu"]//div[@class="sitotheque"]//a[@href="http://hurd.gnu.org"]',
$this->_response->getBody());
}
/** @test */
public function descriptionSiteLinuxFrShouldBeVisible() {
$this->assertXPathContentContains('//div[@class="contenu"]//div[@class="sitotheque"]',
'Pour tous les linuxiens');
}
class SitoControllerSitoViewTest extends SitoControllerTestCase {
$this->dispatch('/sito/sitoview/id_items/25-28/id_categorie/3', true);
/** @test */
public function siteLinuxFrShouldBeVisible() {
$this->assertXPath('//div[@class="contenu"]//div[@class="sitotheque"]//a[@href="http://linuxfr.org"]',
$this->_response->getBody());
}
/** @test */
public function siteHurdDotOrgShouldBeVisible() {
$this->assertXPath('//div[@class="contenu"]//div[@class="sitotheque"]//a[@href="http://hurd.gnu.org"]',
$this->_response->getBody());
}
/** @test */
public function descriptionSiteLinuxFrShouldBeVisible() {
$this->assertXPathContentContains('//div[@class="contenu"]//div[@class="sitotheque"]',
'Pour tous les linuxiens');
}
class SitoControllerSitoViewIdTest extends SitoControllerTestCase {
/** @test */
public function siteLinuxFrShouldBeVisible() {
$this->assertXPath('//div[@class="contenu"]//div[@class="sitotheque"]//a[@href="http://linuxfr.org"]',
$this->_response->getBody());
}
class SitoControllerSitoWebThumbnailUrl extends SitoControllerTestCase {
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
public function setup() {
parent::setUp();
Class_AdminVar::newInstanceWithId('BLUGA_API_KEY', ['valeur' => '123456'])->save();
$filesystem = Storm_Test_ObjectWrapper::mock();
$filesystem
->whenCalled('fileExists')
->answers(false);
$thumbnailer = Storm_Test_ObjectWrapper::mock();
$thumbnailer
->whenCalled('fetchUrlToFile')
->answers(true);
Class_WebService_WebSiteThumbnail::setThumbnailer($thumbnailer);
Class_WebService_WebSiteThumbnail::setFileWriter($filesystem);
$this->dispatch('/sito/webthumbnail?url=http://linuxfr.org');
}
public function tearDown() {
Class_WebService_WebSiteThumbnail::setThumbnailer(null);
Class_WebService_WebSiteThumbnail::setFileWriter(null);
parent::tearDown();
}
/** @test */
public function siteLinuxThumbnailUrlShouldBelinuxfrOrgDotJpg() {
$this->assertRedirectTo(BASE_URL.'/userfiles/web_thumbnails/linuxfr_org.jpg',
$this->getResponseLocation());
}
class SitoControllerRssWithProfileTest extends SitoControllerViewCategoryTestCase {
public function setUp() {
parent::setUp();
Class_Profil::getCurrentProfil()
->setCfgAccueil(['modules' => ['1' => ['division' => '2',
'type_module' => 'SITO',
'preferences' => ['id_categorie' => '19',
'type_aff' => '3',
'id_items' => '281',
'options' => []]);
$this->dispatch('sito/sito-rss?id_module=1&id_profil=2');
}
/** @test */
public function rssShouldOnlyContainsTwoSitos() {
$this->assertXPathCount('//item', 2,$this->_response->getBody());
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
}
/** @test */
public function linuxFrShouldNotBeShown() {
$this->assertNotXPathContentContains('link', 'http://april.org');
}
/** @test */
public function framasoftShouldBeShown() {
$this->assertXPathContentContains('//link', 'http://framasoft.org');
}
/** @test */
public function laquadratureShouldBeShown() {
$this->assertXPathContentContains('//link', 'http://laquadrature.net');
}
}
class SitoControllerRssWithoutProfileTest extends AbstractControllerTestCase {
public function setUp() {
parent::setUp();
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Profil')
->whenCalled('find')
->answers(null);
$this->dispatch('sito/sito-rss');
}
/** @test */
public function titleShouldBeFluxIndisponible() {
$this->assertXPathContentContains('//channel/title', 'Flux indisponible', $this->_response->getBody());
}
}

lbrun
committed
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
class SitoControllerPaginationTest extends SitoControllerTestCase {
public function setUp() {
parent::setUp();
$this->dispatch('/sito/widget-page/id_module/1/id_division/2/page/2', true);
}
/** @test */
public function linuxFrShouldBeVisible() {
$this->assertXPath('//div[@class="contenu"]//div[@class="sitotheque"]//a[@href="http://linuxfr.org"]',
$this->_response->getBody());
}
/** @test */
public function page1LinkShouldBePresent() {
$this->assertXPathContentContains('//div[@class="paginationControl"]//a[contains(@href, "/page/1")]', '1', $this->_response->getBody());
}
/** @test */
public function suivantLinkShouldNotBePresent() {
$this->assertXPathContentContains('//div[@class="paginationControl"]//span[@class="disabled"]', 'Suivant', $this->_response->getBody());
}
}