Skip to content
Snippets Groups Projects
SitoControllerTest.php 6.96 KiB
Newer Older
<?php
/**
 * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
 *
Laurent's avatar
Laurent committed
 * BOKEH is free software; you can redistribute it and/or modify
 * 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).
 *
Laurent's avatar
Laurent committed
 * BOKEH is distributed in the hope that it will be useful,
 * 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
Laurent's avatar
Laurent committed
 * along with BOKEH; if not, write to the Free Software
Laurent's avatar
Laurent committed
 * 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',
																							'id_items' => '25-28']
class SitoControllerHierarchicViewTest extends SitoControllerTestCase {
	public function setUp() {
		parent::setUp();
		$this->fixture('Class_SitothequeCategorie',
									 ['id' => 12,
										'parent_categorie' => $this->hackers,
										'libelle' => 'Collectifs' ]);


		$this->fixture('Class_Sitotheque',
									 ['id' => 280,
										'id_cat' => 12,
										'titre' => 'La quadrature du net',
										'description' => 'Internet et libertés',
										'url' => 'http://laquadrature.net']);

		$this->fixture('Class_Sitotheque',
									 ['id' => 281,
										'id_cat' => 12,
										'titre' => 'Framasoft',
										'description' => 'Degooglisons internet',
										'url' => 'http://framasoft.org']);

		Class_Profil::getCurrentProfil()
			->setCfgAccueil([
												'modules' => [
													'1' => 	[
														'division' => '2',
														'type_module' => 'SITO',
														'preferences' => [
																							'id_categorie' => '12',
																							"type_aff" => "3",
																							'id_items' => '280-281']
														]
													],
												'options' => 	[]]);

		$this->dispatch('/sito/viewcategory/id_cat/12/start_cat/12', true);
  /** @test */
	public function LinuxFrShouldNotBeShown() {
		$this->assertNotXPath('//ul[@class="sitotheque"]//a[@href="http://linuxfr.org"]',
											 $this->_response->getBody());
	}

	public function FramasoftShouldBeShown() {
		$this->assertXPath('//ul[@class="sitotheque"]//a[@href="http://framasoft.org"]',
											 $this->_response->getBody());
	}


	/** @test */
	public function breadCrumbShouldStartWithCollectifs() {
		$this->assertXPath('//div/a[1][@href="/sito/viewcategory/id_cat/12"]');
	}
Laurent's avatar
Laurent committed
class SitoControllerViewRecentTest extends SitoControllerTestCase {
	public function setUp() {
		parent::setUp();

		$this->dispatch('/sito/viewrecent/nb/2', true);
	}


	/** @test */
	public function linuxFrShouldBeVisible() {
		$this->assertXPath('//div[@class="contenu"]//div[@class="sitotheque"]//a[@href="http://linuxfr.org"]',
											 $this->_response->getBody());
	}
}



class SitoControllerViewSelectionTest extends SitoControllerTestCase {
	public function setUp() {
		parent::setUp();

		$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 {
	public function setUp() {
		parent::setUp();

		$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 {
	public function setUp() {
		parent::setUp();

		$this->dispatch('/sito/sitoview/id/5', true);

	}

	/** @test */
	public function siteLinuxFrShouldBeVisible() {
		$this->assertXPath('//div[@class="contenu"]//div[@class="sitotheque"]//a[@href="http://linuxfr.org"]',
											 $this->_response->getBody());
	}
}



class SitoControllerSitoWebThumbnailUrl extends SitoControllerTestCase {
	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());