Conjunto de cambios d5990f8 en sipes para modules_contrib/token/token.test


Ignorar:
Fecha y hora:
26/05/2016 18:08:08 (hace 8 años)
Autor:
José Gregorio Puentes <jpuentes@…>
Branches:
stable, version-3.0
Children:
bfe9e03
Parents:
4f375e3
Mensaje:

se actualizo el modulo

Fichero:
1 editado

Leyenda

No modificado
Añadido
Eliminado
  • modules_contrib/token/token.test

    r177a560 rd5990f8  
    1515    $modules[] = 'token_test';
    1616    parent::setUp($modules);
     17
     18    // Clear the token static cache.
     19    token_get_values('reset');
    1720  }
    1821
     
    2225
    2326  function assertTokens($type, $object, array $tokens, array $options = array()) {
    24     $values = token_get_values($type, $object, TRUE, $options);
     27    $values = token_get_values($type, $object, FALSE, $options);
    2528    $values = array_combine($values->tokens, $values->values);
    2629    foreach ($tokens as $token => $expected) {
     
    215218      $output = token_replace($input);
    216219      $this->assertEqual($output, $expected);
     220    }
     221  }
     222
     223  /**
     224   * Test token caching.
     225   */
     226  function testTokenCaching() {
     227    // Run global tokens once so that the cache is primed.
     228    $tokens = array(
     229      'option-foo' => '',
     230    );
     231    $this->assertTokens('global', NULL, $tokens);
     232
     233    // Run global tokens again with different options. This should return a
     234    // different value for the [option-foo] token.
     235    $tokens = array(
     236      'option-foo' => 'bar',
     237    );
     238    $this->assertTokens('global', NULL, $tokens, array('foo' => 'bar'));
     239  }
     240
     241  /**
     242   * Test the token_scan() function.
     243   */
     244  function testTokenScan() {
     245    $tests = array(
     246      array('text' => 'Test [foo] [[bar]] test.', 'tokens' => array('foo', 'bar')),
     247      array('text' => 'Test [foo] [] test.',    'tokens' => array('foo')),
     248      array('text' => 'Test [foo][] test.',     'tokens' => array('foo')),
     249      array('text' => 'Test [foo][bar] test.',  'tokens' => array('foo', 'bar')),
     250      // Test the e-mail token syntax.
     251      array('text' => 'Test %foo %%bar test.',   'tokens' => array('foo', 'bar'), 'leading' => '%', 'trailing' => ''),
     252      array('text' => 'Test %foo % test.',      'tokens' => array('foo'),        'leading' => '%', 'trailing' => ''),
     253      array('text' => 'Test %foo% test.',       'tokens' => array('foo'),        'leading' => '%', 'trailing' => ''),
     254      array('text' => 'Test %foo%%bar test.',    'tokens' => array('foo', 'bar'), 'leading' => '%', 'trailing' => ''),
     255      // Test the rules token syntax.
     256      array('text' => 'Test [global:foo] [global:bar] test.', 'tokens' => array('foo', 'bar'), 'leading' => '[global:'),
     257      array('text' => 'Test [node:foo] [node:] test.', 'tokens' => array('foo'), 'leading' => '[node:'),
     258      array('text' => 'Test [node:foo][node:] test.', 'tokens' => array('foo'), 'leading' => '[node:'),
     259      array('text' => 'Test [node:foo][node:bar] test.', 'tokens' => array('foo', 'bar'), 'leading' => '[node:'),
     260    );
     261    foreach ($tests as $test) {
     262      $test += array('leading' => TOKEN_PREFIX, 'trailing' => TOKEN_SUFFIX);
     263      $this->assertEqual(token_scan($test['text'], $test['leading'], $test['trailing']), $test['tokens']);
    217264    }
    218265  }
     
    282329    );
    283330    $this->assertTokens('node', $node, $tokens);
     331
     332    // Check that a new revision of a node returns different tokens.
     333    $node->revision = TRUE;
     334    $node->title = 'New revision';
     335    node_save($node);
     336    $this->assertTokens('node', $node, array('title' => 'New revision'));
    284337  }
    285338}
     
    479532    );
    480533    $this->assertTokens('node', $node, $tokens);
     534
     535    // Reload the node which will not have $node->menu defined and re-test.
     536    $loaded_node = node_load($node->nid);
     537    // We have to reset the token static cache because tokens are cached by
     538    // node ID only and not if the node object has changed.
     539    $this->assertTokens('node', $loaded_node, $tokens, array('reset' => TRUE));
     540
     541    // Regression test for http://drupal.org/node/1317926 to ensure the
     542    // original node object is not changed when calling menu_node_prepare().
     543    $this->assertTrue(!isset($loaded_node->menu), t('The $node->menu property was not modified during token replacement.'), 'Regression');
     544
    481545  }
    482546}
Nota: Vea TracChangeset para ayuda en el uso del visor de conjuntos de cambios.