Exemplo n.º 1
0
    // validate elevation language
    if ( !$http->hasPostVariable( 'ezfind-elevate-language' ) )
    {
        $feedback['missing_language'] = true;
        $doStorage = false;
    }

    // Do storage, and create the associated feedback
    if ( $doStorage )
    {
        // Filter the not yet filtered fields
        $queryString = htmlspecialchars( $http->postVariable( 'ezfind-elevate-searchquery' ), ENT_QUOTES );
        $languageCode = htmlspecialchars( $http->postVariable( 'ezfind-elevate-language' ), ENT_QUOTES );

        // Do actual storage here.
        $conf = eZFindElevateConfiguration::add( $queryString, $http->postVariable( 'elevateObjectID' ), $languageCode );

        // Give feedback message
        if ( $conf instanceof eZFindElevateConfiguration )
        {
            $feedback['creation_ok'] = $conf;
            $tpl->resetVariables();

            // redirect to the original page if any.
            // Useful to not duplicate storage code and input validation : the storage form can be submitted from another place.
            //    Pseudo-code example:   redirectURI='/ezfind/elevation_detail/86'
            if ( $http->hasPostVariable( 'redirectURI' ) )
            {
                $module->redirectTo( $http->postVariable( 'redirectURI' ) );
            }
        }
 /**
  * test for fetchConfigurationForObject()
  */
 public function testFetchConfigurationForObject()
 {
     // clean up the table beforehand
     $db = eZDB::instance();
     $rows = $db->query('TRUNCATE TABLE ezfind_elevate_configuration;');
     # start 1 : invalid object ID
     $expected1 = null;
     $configuration1 = eZFindElevateConfiguration::fetchConfigurationForObject('non numeric');
     self::assertEquals($expected1, $configuration1);
     # end 1
     # start 2 : simple fetch with default parameters.
     $queryString = "test 1";
     $objectID = 1;
     $language = "eng-GB";
     eZFindElevateConfiguration::add($queryString, $objectID, $language);
     $expected2 = array($language => array(new eZFindElevateConfiguration(array('search_query' => $queryString, 'contentobject_id' => $objectID, 'language_code' => $language))));
     $configuration2 = eZFindElevateConfiguration::fetchConfigurationForObject($objectID);
     self::assertEquals($expected2, $configuration2);
     # end 2
     # start 3 : group by language disabled.
     $expected3 = array(new eZFindElevateConfiguration(array('search_query' => $queryString, 'contentobject_id' => $objectID, 'language_code' => $language)));
     $configuration3 = eZFindElevateConfiguration::fetchConfigurationForObject($objectID, false);
     self::assertEquals($expected3, $configuration3);
     # end 3
     # start 4 : filtering by language code
     $additionalLanguage = "esl-ES";
     eZFindElevateConfiguration::add($queryString, $objectID, $additionalLanguage);
     $expected4 = array($additionalLanguage => array(new eZFindElevateConfiguration(array('search_query' => $queryString, 'contentobject_id' => $objectID, 'language_code' => $additionalLanguage))));
     $configuration4 = eZFindElevateConfiguration::fetchConfigurationForObject($objectID, true, $additionalLanguage);
     self::assertEquals($expected4, $configuration4);
     # end 4
     # start 5 : testing the countOnly parameter
     $expected5 = 1;
     $configuration5 = eZFindElevateConfiguration::fetchConfigurationForObject($objectID, true, $additionalLanguage, null, true);
     self::assertEquals($expected5, $configuration5);
     # end 5
     # start 6 : testing the limit parameter
     $expected6 = 2;
     $configuration6 = eZFindElevateConfiguration::fetchConfigurationForObject($objectID, true, null, 1, true);
     self::assertEquals($expected6, $configuration6);
     # end 6
     # start 7 : filtering by search query
     $additionalQueryString = "test 2";
     eZFindElevateConfiguration::add($additionalQueryString, $objectID, $language);
     $expected7 = 2;
     $configuration7 = eZFindElevateConfiguration::fetchConfigurationForObject($objectID, true, null, null, true, $queryString);
     self::assertEquals($expected7, $configuration7);
     # end 7
 }