Skip to content
Snippets Groups Projects
AbonneControllerSuggestionAchatTest.php 36 KiB
Newer Older
  /** @test */
  public function shouldDisplayWebserviceError() {
    $this->assertXPathContentContains('//div',
                                      'Erreurs du webservice');
  }




class ModulesControllerAbonneSuggestionAchatTest extends Admin_AbstractControllerTestCase {
  public function setUp() {
    parent::setUp();
    Class_Profil::getCurrentProfil()
      ->setCfgModules(['abonne' => ['suggestion-achat-add' => ['help-text' => 'Entrez votre suggestion']]]);
    $this->dispatch('/admin/modules/abonne?id_profil=2&action1=suggestion-achat-add&type_module=abonne&config=site', true);
  }
  /** @test */
  public function titleShouldBeProperty() {
    $this->assertXPathContentContains('//h1', 'Propriétés du module : Suggestions d\'achat');
  }
  /** @test */
  public function textareHelpTextShouldContainsEntrezVotreSuggestion() {
    $this->assertXPathContentContains('//textarea[@name="help-text"]',
                                      'Entrez votre suggestion');
  }
  /** @test */
  public function textareHelpTextShouldBeCkeditor() {
    $this->assertXPathContentContains('//script',
                                      'CKEDITOR.replace(\'cke-help-text\'');
  }
class AbonneControllerSuggestionAchatBibSelectOrderTest extends AbstractControllerTestCase {
  public function setUp() {
    parent::setUp();

    $this->fixture('Class_Bib', ['id' => 11, 'libelle' => 'Test']);
    $this->fixture('Class_Bib', ['id' => 12, 'libelle' => 'Mer']);
    $this->fixture('Class_Bib', ['id' => 13, 'libelle' => 'Agence']);
    $this->fixture('Class_Bib', ['id' => 14, 'libelle' => 'Plage']);

    $this->dispatch('abonne/suggestion-achat-add', true);
  }

  /** @test */
  public function BibSelectShouldBeAgence() {
    $this->assertXPath('//form//select[@name="bib_id"]//option[2][@value="13"]');
  }

  /** @test */
  public function BibSelectShouldBeMer() {
    $this->assertXPath('//form//select[@name="bib_id"]//option[3][@value="12"]');
  }

  /** @test */
  public function BibSelectShouldBePlage() {
    $this->assertXPath('//form//select[@name="bib_id"]//option[4][@value="14"]');
  }

  /** @test */
  public function BibSelectShouldBeTest() {
    $this->assertXPath('//form//select[@name="bib_id"]//option[5][@value="11"]');
  }
}
class AbonneControllerSuggestionAchatInactiveTest
  extends AbstractControllerTestCase {

  protected $_storm_default_to_volatile = true;

  public function setUp() {
    parent::setUp();
    $this->fixture('Class_AdminVar', ['id' => 'DISABLE_SUGGESTIONS',
                                      'valeur' => '1']);
  public function provider() {
    return [['/abonne/suggestion-achat'],
            ['/abonne/suggestion-achat-add'],
            ['/abonne/suggestion-achat-ok']];
  /**
   * @test
   * @dataProvider provider
   **/
  public function shouldContainsDisabledMessage($url) {
    $this->dispatch($url, true);
    $this->assertXPathContentContains('//div',
                                      'les suggestions d\'achats ne sont pas possibles pour le moment.',
                                      $this->_response->getBody());
}




class AbonneControllerSuggestionAchatAddPostAndRecordsFoundTest extends AbonneControllerSuggestionAchatAddPostTestCase {
  protected $_storm_default_to_volatile = true;

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

    Class_AdminVar::set('SEARCH_RECORD_BEFORE_SUGGEST', 1);

    $mock_transport = new MockMailTransport();
    Zend_Mail::setDefaultTransport($mock_transport);

    $search_result = $this
      ->mock()->beStrict()
      ->whenCalled('fetchRecords')
      ->answers([$this->fixture('Class_Notice',
                                ['id' => 1,
                                 'titre_principal' => 'Trolls de Troy'])]);

    $search_engine = $this
      ->mock()
      ->whenCalled('lancerRecherche')
      ->answers($search_result);

    Class_MoteurRecherche::setInstance($search_engine);

    $this->postDispatch('/opac/abonne/suggestion-achat-add',
                        ['DocType' => Class_TypeDoc::LIVRE,
                         'Site' => '12',
                         'titre' => 'Trolls de Troy']);
  }


  /** @test */
  public function recordsListShouldContainsTrollsDeTroy() {
    $this->assertXPathContentContains('//div', 'Trolls de Troy', $this->_response->getBody());
  }
}




class AbonneControllerSuggestionAchatAddPostWithValidateSuggestionTest extends AbonneControllerSuggestionAchatAddPostTestCase {

  protected $_storm_default_to_volatile = true;


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

    Class_AdminVar::set('SEARCH_RECORD_BEFORE_SUGGEST', 1);

    $mock_transport = new MockMailTransport();
    Zend_Mail::setDefaultTransport($mock_transport);

    $search_result = $this
      ->mock()->beStrict()
      ->whenCalled('fetchRecords')
      ->answers([$this->fixture('Class_Notice',
                                ['id' => 1,
                                 'titre_principal' => 'Le mystère de la patate. Une enquête de l\'inspecteur Lapou'])]);

    $search_engine = $this
      ->mock()
      ->whenCalled('lancerRecherche')
      ->answers($search_result);

    Class_MoteurRecherche::setInstance($search_engine);

    $this->postDispatch('/opac/abonne/suggestion-achat-add/validate_suggestion/1',
                        ['titre' => 'Le mystère de la patate',
                         'auteur' => 'Bénédicte Guettier',
                         'type_doc_id' => Class_TypeDoc::LIVRE,
                         'commentaire' => 'Une enquête de l\'inspecteur Lapou']);
  }


  /** @test */
  public function responseShouldRedirect() {
    $this->assertRedirect();
  }


  /** @test */
  public function assertFlashMessengerShouldContainsSuggestionAdded() {
    $this->assertFlashMessengerContentContains('Suggestion d\'achat enregistrée');
  }
Sebastien ANDRE's avatar
Sebastien ANDRE committed
}