Skip to content
Snippets Groups Projects
CmsControllerCalendarActionTest.php 16.3 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
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
 */
abstract class CmsControllerCalendarActionTestCase extends AbstractControllerTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  protected
    $_nanook2;

  public function setUp() {
    parent::setUp();

    $this->cfg_accueil =
      ['modules' =>
       [ '1' => [
                 'division' => '1',
                 'type_module' => 'CALENDAR',
                 'preferences' => [
                                   'titre' => 'Rendez-vous',
                                   'rss_avis' => false,
                                   'id_categorie' => '12-2',
                                   'display_cat_select' => true,
                                   'enabled_filters' => 'date;place;custom_field_2;zork',
                                   'display_event_info' => 'none']]],
       'options' =>   []];


    $this->fixture('Class_Profil',
                   ['id' => 3,
                    'browser' => 'opac',
                    'libelle' => 'Rendez-vous',
                    'cfg_accueil' => $this->cfg_accueil]);

    Class_AdminVar::newInstanceWithId('CACHE_ACTIF',
                                      ['valeur' => '1']);

    $this->_nanook2 = $this->fixture('Class_Article',
                                     ['id' => 4,
                                      'titre' => 'Nanook 2 en prod !',
                                      'contenu' => 'youpi !',
                                      'events_debut' => '2011-02-17',
                                      'events_fin' => '2011-02-22']);

    Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Article')
      ->whenCalled('getArticlesByPreferences')
      ->answers([$this->_nanook2]);
  }


  function tearDown() {
    Class_AdminVar::getLoader()->find('CACHE_ACTIF')->setValeur('0');
    parent::tearDown();
  }
}




class CmsControllerCalendarActionCacheTest extends CmsControllerCalendarActionTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    $cache = Storm_Test_ObjectWrapper::mock();
    $cache->whenCalled('save')
          ->answers(true);

    Storm_Cache::setDefaultZendCache($cache);
    $module_cal = new ZendAfi_View_Helper_Accueil_Calendar(1, $this->cfg_accueil['modules']['1']);
    $module_cal->setView(new ZendAfi_Controller_Action_Helper_View());
  }


  /**
   * Test non-regression vu sur Bucarest (prenait le layout normal au lieu du layout iframe)
   * @test
   */
  function calendarShouldNotBeInAnIframeEventWithCacheActive() {
    $this->dispatch('/cms/calendar/id_profil/3/id_module/1/render/ajax');
    // ça plantait lors de la réutilisation du cache, donc 2 dispatchs
    $this->bootstrap();
    $this->dispatch('/cms/calendar/id_profil/3/id_module/1/render/ajax');
    $this->assertNotXPath('//div[@id="site_web_wrapper"]');
  }
}




class CmsControllerCalendarActionLanguageEnTest extends CmsControllerCalendarActionTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    $this->dispatch('/cms/calendar/id_profil/3/id_module/1/select_id_categorie/2/date/2011-02/language/en/render/ajax');
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test */
  function withLocaleEnMonthShouldBeFebruary() {
    $this->assertXPathContentContains('//td[@class="calendar_title_month"]/a', "february", $this->_response->getBody());
  }
Patrick Barroca's avatar
Patrick Barroca committed
  /** @test **/
  function calendarShouldContains3AwithClassCalendarTitleMonthClickable() {
    $this->assertXPathCount('//a[@class="calendar_title_month_clickable"]',3);
  }
}




class CmsControllerCalendarActionWithFiltersTest extends CmsControllerCalendarActionTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  protected $_opac4;
  protected $_date;

  public function setupCustomFields() {
    Class_CustomField_Meta::beVolatile();
    $theme = $this->fixture('Class_CustomField',
                            ['id' => 2,
                             'priority' => 3,
                             'label' => 'Theme',
                             'field_type' => Class_CustomField_Meta::SELECT,
                             'options_list' => 'sigb;opac',
                             'model' => 'Article']);

    $this->fixture('Class_CustomField_Value',
                   ['id' => 5,
                    'custom_field_id' => $theme->getId(),
                    'model_id' => $this->_nanook2->getId(),
                    'value' => 'sigb']);

    $this->fixture('Class_CustomField_Value',
                   ['id' => 2,
                    'custom_field_id' => $theme->getId(),
                    'model_id' => $this->_opac4->getId(),
                    'value' => 'opac']);
  }


  public function setUp() {
    parent::setUp();
    $this->_opac4 = $this->fixture('Class_Article',
                                   ['id' => 5,
                                    'titre' => 'OPAC 4 en prod !',
                                    'contenu' => 'youpi !',
                                    'events_debut' => '2011-02-17',
                                    'events_fin' => '2011-02-22']);
    $this->setupCustomFields();

    $common_preferences = ['display_order' => 'EventDebut',
                           'id_categorie' => '',
                           'events_only' => true,
                           'id_bib' => 0,
                           'id_lieu' => '',
                           'custom_fields' => [2 => 'opac'],
                           'published' => true];

    $time_source = new TimeSourceForTest('2014-06-06 14:14:14');
    ZendAfi_View_Helper_CalendarContent::setTimeSource($time_source);
    ZendAfi_View_Helper_Calendar_Months::setTimeSource($time_source);

    Class_Article::getLoader()
      ->whenCalled('getArticlesByPreferences')
      ->with(array_merge($common_preferences, ['event_date' => '2014-07']))
      ->answers([$this->_opac4])

      ->whenCalled('getArticlesByPreferences')
      ->with(array_merge($common_preferences, ['event_date' => '',
                                               'event_start_after' => '2014-07',
                                               'event_end_after' => '',
                                               'limit' => 3]))
      ->answers([])
      ->beStrict();

    $this->dispatch('/cms/calendar/id_profil/3/id_module/1/date/2014-07/custom_field_2/opac/render/ajax', true);
  }


  /** @test **/
  public function calendarWithCustomFieldFiltersShouldBuildPreferencesForGetArticlesByPreferences() {
    $this->assertXPathContentContains('//a[@class="calendar_event_title"]',
                                      'OPAC 4 en prod !');
  }


  /** @test */
  public function monthFilterShouldContainsCustomField2Music() {
    $this->assertXPathContentContains('//li[@class="date"]//li[not(@class="selected")]/a[contains(@href, "/cms/calendar/id_module/1/custom_field_2/opac/date/2014-11")]',
                                      'Novembre');
  }


  /** @test */
  public function selectedMonthFilterShouldHaveClassSelected() {
    $this->assertXPath('//li[@class="date"]//li[@class="selected"]/a[contains(@href, "/cms/calendar/id_module/1/custom_field_2/opac/date/2014-07")]');
  }


  /** @test */
  public function themeFilterShouldContainsDate() {
    $this->assertXPathContentContains('//li[@class="custom_field_2"]//li//a[contains(@href, "/cms/calendar/id_module/1/custom_field_2/sigb/date/2014-07")]',
                                      'sigb');
  }


  /** @test */
  public function themeFilterHeaderShouldBeThemeOPAC() {
    $this->assertXPathContentContains('//li[@class="custom_field_2"]/h2', 'Theme: opac');
  }


  /** @test */
  public function monthFilterShouldHaveTitleMoisJuillet() {
    $this->assertXPathContentContains('//ul[@class="filters"]/li[@class="date"]/h2',
                                      'Mois: Juillet');
  }
Ghislain Loas's avatar
Ghislain Loas committed
class CmsControllerCalendarActionWithDayTest extends AbstractControllerTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();

    $cfg_accueil = ['modules' =>
                    [ '1' => [
                              'division' => '1',
                              'type_module' => 'CALENDAR',
                              'preferences' => ['mode-affichage' => 'article',
                                                'display_full_page' => 0]]],
                    'options' =>  []];


    $this->fixture('Class_Profil',
                   ['id' => 3,
                    'browser' => 'opac',
                    'libelle' => 'Plop',
                    'cfg_accueil' => $cfg_accueil]);


    $this->fixture('Class_Article',
                   ['id' => 5,
                    'titre' => 'News of the 15th September',
                    'contenu' => 'youpi !',
                    'events_debut' => '2014-09-15',
                    'events_fin' => '2014-09-15']);

    $this->fixture('Class_Article',
                   ['id' => 2,
                    'titre' => 'News of the 30th September',
                    'contenu' => 'youpi !',
                    'events_debut' => '2014-09-28',
                    'events_fin' => '2014-09-30']);

    $time_source = new TimeSourceForTest('2014-09-02 14:14:14');
    ZendAfi_View_Helper_CalendarContent::setTimeSource($time_source);
    ZendAfi_View_Helper_Calendar_Table::setTimeSource($time_source);

    Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Article')
      ->whenCalled('getArticlesByPreferences')
      ->with(['display_order' => 'EventDebut',
              'id_categorie' => '',
              'events_only' => true,
              'event_date' => '2014-09',
              'id_bib' => 0,
              'id_lieu' => '',
              'custom_fields' => [],
              'published' => true])
      ->answers([Class_Article::find(2), Class_Article::find(5)])

      ->whenCalled('getArticlesByPreferences')
      ->with(['display_order' => 'EventDebut',
              'id_categorie' => '',
              'events_only' => true,
              'event_date' => '2014-09',
              'id_bib' => 0,
              'id_lieu' => '',
              'custom_fields' => [],
              'published' => true,
              'event_end_after' => '2014-09-02'])
      ->answers([Class_Article::find(2), Class_Article::find(5)])

      ->whenCalled('getArticlesByPreferences')
      ->with(['display_order' => 'EventDebut',
              'id_categorie' => '',
              'events_only' => true,
              'event_date' => '',
              'id_bib' => 0,
              'id_lieu' => '',
              'custom_fields' => [],
              'published' => true,
              'event_start_after' => '2014-09',
              'event_end_after' => '',
              'limit' => 3])
      ->answers([Class_Article::find(2), Class_Article::find(5)])

      ->whenCalled('getArticlesByPreferences')
      ->with(['display_order' => 'EventDebut',
              'id_categorie' => '',
              'events_only' => true,
              'event_date' => '2014-09-30',
              'id_bib' => 0,
              'id_lieu' => '',
              'custom_fields' => [],
              'published' => true])
      ->answers([Class_Article::find(2)])
      ->beStrict();

    $this->dispatch('cms/calendar/date/2014-09-30/id_profil/3/id_module/1/opac/render/ajax', true);
  }


  /** @test */
  public function currentMonthLinkShouldHaveReadyAjaxClass() {
    $this->assertXPath('//table[@class="calendar_main"]//td[@class="calendar_title_month"]//a[contains(@class, "calendar_ajax_ready")]');
  }


  /** @test */
  public function newsOfThe30thShouldBePresent() {
    $this->assertXPathContentContains('//div[@class="calendar"]//article//header//h2//a', 'News of the 30th September');
  }


  /** @test **/
  public function newsOfThe15ThSeptemberEventShouldNotBPresent() {
    $this->assertNotXPathContentContains('//div[@id="boite_1"][@class="calendar"]//article//header', 'News of the 15th September', $this->_response->getBody());
  }


  /** @test */
  public function newsOfThe15thSeptemberShouldBeClickableAtThe15Th() {
    $this->assertXPath('//div[@class="calendar"]//table//a[contains(@class, "day_clickable")][contains(@href, "date/2014-09-15")]');
  }
class CmsControllerCalendarActionHeaderTest extends AbstractControllerTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
  public function setUp() {
    parent::setUp();
    $this->cfg_accueil = [
                          'modules' => [
                                        '1' => [
                                                'division' => '1',
                                                'type_module' => 'CALENDAR',
                                                'preferences' => [
                                                                  'titre' => 'Rendez-vous',
                                                                  'rss_avis' => false,
                                                                  'id_categorie' => '12-2',
                                                                  'display_cat_select' => true,
                                                                  'enabled_filters' => 'date;place;custom_field_2;zork',
                                                                  'display_event_info' => 'none'
                                                ]
                                        ]
                          ],
                          'options' => []
    ];


    $this->fixture('Class_Profil',
                   ['id' => 3,
                    'browser' => 'opac',
                    'libelle' => 'Rendez-vous',
                    'cfg_accueil' => $this->cfg_accueil]);

    $this->dispatch('/index/index/id_profil/3');
  }

  /** @test */
  public function calendarHeaderShouldContainsThreeLinks() {
    $this->assertXPathCount(3, '//td[@class="calendar_title_month"]/a');
    $this->assertXPathContentContains('//td[@class="calendar_title_month"]/a[1]', '«');
    $this->assertXPathContentContains('//td[@class="calendar_title_month"]/a[3]', '»');
  }
class CmsControllerCalendarActionWithOutDateTest extends AbstractControllerTestCase {
Patrick Barroca's avatar
Patrick Barroca committed
    parent::setUp();

    $time_source = new TimeSourceForTest('2014-09-02 14:14:14');
    ZendAfi_View_Helper_CalendarContent::setTimeSource($time_source);
    ZendAfi_View_Helper_Calendar_Table::setTimeSource($time_source);

    Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Article')
      ->whenCalled('getArticlesByPreferences')
      ->with(['display_order' => 'EventDebut',
              'id_categorie' => '',
              'events_only' => true,
              'event_date' => '',
              'id_bib' => 0,
              'id_lieu' => '',
              'custom_fields' => [],
              'published' => true,
              'event_start_after' => '2014-09',
              'event_end_after' => '',
              'limit' => 3])
      ->answers([])

      ->whenCalled('getArticlesByPreferences')
      ->with(['display_order' => 'EventDebut',
              'id_categorie' => '',
              'events_only' => true,
              'event_date' => '2014-09',
              'id_bib' => 0,
              'id_lieu' => '',
              'custom_fields' => [],
              'published' => true,
              'event_end_after' => '2014-09-02'])
      ->answers([$this->fixture('Class_Article',
                                ['id' => 1,
                                 'titre' => 'Kitchen',
                                 'contenu' => 'Cook'])])

      ->whenCalled('getArticlesByPreferences')
      ->with(['display_order' => 'EventDebut',
              'id_categorie' => '',
              'events_only' => true,
              'event_date' => '2014-09',
              'id_bib' => 0,
              'id_lieu' => '',
              'custom_fields' => [],
              'published' => true])
      ->answers([])
      ->beStrict();

    $this->dispatch('/cms/calendar/render/ajax', true);
  }


  /** @test */
  public function gatArticleByPreferencesShouldBeCallWithEventDAteAfter() {
    $this->assertXPathContentContains('//div', 'Kitchen', $this->_response->getBody());
  }