From a40bce49a4305216279ca9d5c4066eddd4d8997b Mon Sep 17 00:00:00 2001
From: Alex Arnaud <alex.arnaud@biblibre.com>
Date: Tue, 13 Jan 2015 09:26:50 +0100
Subject: [PATCH] hotline#18512 - Add tests for adding / viewing article
 comments

---
 .../AbonneControllerCmsAvisTest.php           | 99 +++++++++++++++++++
 1 file changed, 99 insertions(+)
 create mode 100644 tests/application/modules/opac/controllers/AbonneControllerCmsAvisTest.php

diff --git a/tests/application/modules/opac/controllers/AbonneControllerCmsAvisTest.php b/tests/application/modules/opac/controllers/AbonneControllerCmsAvisTest.php
new file mode 100644
index 00000000000..31697ceef17
--- /dev/null
+++ b/tests/application/modules/opac/controllers/AbonneControllerCmsAvisTest.php
@@ -0,0 +1,99 @@
+<?php
+/**
+ * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
+ *
+ * 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).
+ *
+ * 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
+ * along with BOKEH; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA 
+ */
+
+abstract class AbonneControllerCmsAvisTestCase extends AbstractControllerTestCase {
+	public function setUp() {
+		parent::setUp();
+
+		$this->fixture('Class_Article', ['id' => 1,
+																		'titre' => 'Je suis Charlie',
+																		'contenu' => 'C\'est de la balle d\'être Charlie',
+																		'avis' => 1]);
+
+	}
+}
+
+class AbonneControllerCmsAvisViewArticleWithoutCommentTest extends AbonneControllerCmsAvisTestCase {
+	public function setUp() {
+		parent::setUp();
+
+		$this->dispatch('/cms/articleview/id/1', true);
+	}
+
+
+	/** @test */
+	public function ArticleJeSuisCharlieShouldHaveLinkToAddComment() {
+		$this->assertXPathContentContains('//a[contains(@onclick, "/opac/abonne/cmsavis?id=1")]', 'Donner ou modifier votre avis');
+	}
+
+
+	/** @test */
+	public function ArticleWithoutCommentShouldNotHaveLinkToAccessLibrariansComments() {
+		$this->assertNotXPathContentContains('//a[contains(@onclick, "showAvis(1")]', 'Avis de bibliothécaires');
+	}
+
+
+	/** @test */
+	public function ArticleWithoutCommentShouldNotHaveLinkToAccessBorrowersComments() {
+		$this->assertNotXPathContentContains('//a[contains(@onclick, "showAvis(1")]', 'Avis de lecteurs du portail');
+	}
+}
+
+
+
+class AbonneControllerCmsAvisViewArticleWithCommentTest extends AbonneControllerCmsAvisTestCase {
+	public function setUp() {
+		parent::setUp();
+
+		$this->fixture('Class_Users' , ['id' => 112,
+																	'login' => 'max',
+																	 'password' => 'maxLaMenace']);
+
+		$this->fixture('Class_Avis' , ['id' => 7,
+																	'id_user' => 112,
+																	'id_cms' => '1',
+																	'entete' => 'Pas mal !',
+																	'avis' => 'J\'aime cet article',
+																	'note' => 4,
+																	'status' => 1]);
+
+		$this->dispatch('/cms/articleview/id/1', true);
+	}
+
+
+	/** @test */
+	public function ArticleJeSuisCharlieShouldHaveLinkToAccessBorrowersComments() {
+		$this->assertXPathContentContains('//a[contains(@onclick, "showAvis(1")]', 'Avis de lecteur du portail');
+	}
+
+
+	/** @test */
+	public function ArticleJeSuisCharlieShouldHaveOneBorrowersComments() {
+		$this->assertXPathContentContains('//div[@id="avis_1"]/ul[@class="notice_info"]/li[1]', "</a>\n1");
+	}
+
+
+	/** @test */
+	public function ArticleJeSuisCharlieShouldHaveFourStarsImage() {
+		$this->assertXPathContentContains('//div[@id="avis_1"]/ul[@class="notice_info"]/li[1]', "<img class=\"note_critique note-4");
+	}
+}
+
-- 
GitLab