Révision 6ff32cea
Ajouté par Florent Torregrosa il y a environ 9 ans
drupal7/modules/simpletest/tests/common.test | ||
---|---|---|
1440 | 1440 |
$this->assertTrue(strpos($javascript, $inline) > 0, 'Rendered JavaScript footer returns the inline code.'); |
1441 | 1441 |
} |
1442 | 1442 |
|
1443 |
/** |
|
1444 |
* Test the 'javascript_always_use_jquery' variable. |
|
1445 |
*/ |
|
1446 |
function testJavaScriptAlwaysUseJQuery() { |
|
1447 |
// The default front page of the site should use jQuery and other standard |
|
1448 |
// scripts and settings. |
|
1449 |
$this->drupalGet(''); |
|
1450 |
$this->assertRaw('misc/jquery.js', 'Default behavior: The front page of the site includes jquery.js.'); |
|
1451 |
$this->assertRaw('misc/drupal.js', 'Default behavior: The front page of the site includes drupal.js.'); |
|
1452 |
$this->assertRaw('Drupal.settings', 'Default behavior: The front page of the site includes Drupal settings.'); |
|
1453 |
$this->assertRaw('basePath', 'Default behavior: The front page of the site includes the basePath Drupal setting.'); |
|
1454 |
|
|
1455 |
// The default front page should not use jQuery and other standard scripts |
|
1456 |
// and settings when the 'javascript_always_use_jquery' variable is set to |
|
1457 |
// FALSE. |
|
1458 |
variable_set('javascript_always_use_jquery', FALSE); |
|
1459 |
$this->drupalGet(''); |
|
1460 |
$this->assertNoRaw('misc/jquery.js', 'When "javascript_always_use_jquery" is FALSE: The front page of the site does not include jquery.js.'); |
|
1461 |
$this->assertNoRaw('misc/drupal.js', 'When "javascript_always_use_jquery" is FALSE: The front page of the site does not include drupal.js.'); |
|
1462 |
$this->assertNoRaw('Drupal.settings', 'When "javascript_always_use_jquery" is FALSE: The front page of the site does not include Drupal settings.'); |
|
1463 |
$this->assertNoRaw('basePath', 'When "javascript_always_use_jquery" is FALSE: The front page of the site does not include the basePath Drupal setting.'); |
|
1464 |
variable_del('javascript_always_use_jquery'); |
|
1465 |
|
|
1466 |
// When only settings have been added via drupal_add_js(), drupal_get_js() |
|
1467 |
// should still return jQuery and other standard scripts and settings. |
|
1468 |
$this->resetStaticVariables(); |
|
1469 |
drupal_add_js(array('testJavaScriptSetting' => 'test'), 'setting'); |
|
1470 |
$javascript = drupal_get_js(); |
|
1471 |
$this->assertTrue(strpos($javascript, 'misc/jquery.js') !== FALSE, 'Default behavior: The JavaScript returned by drupal_get_js() when only settings have been added includes jquery.js.'); |
|
1472 |
$this->assertTrue(strpos($javascript, 'misc/drupal.js') !== FALSE, 'Default behavior: The JavaScript returned by drupal_get_js() when only settings have been added includes drupal.js.'); |
|
1473 |
$this->assertTrue(strpos($javascript, 'Drupal.settings') !== FALSE, 'Default behavior: The JavaScript returned by drupal_get_js() when only settings have been added includes Drupal.settings.'); |
|
1474 |
$this->assertTrue(strpos($javascript, 'basePath') !== FALSE, 'Default behavior: The JavaScript returned by drupal_get_js() when only settings have been added includes the basePath Drupal setting.'); |
|
1475 |
$this->assertTrue(strpos($javascript, 'testJavaScriptSetting') !== FALSE, 'Default behavior: The JavaScript returned by drupal_get_js() when only settings have been added includes the added Drupal settings.'); |
|
1476 |
|
|
1477 |
// When only settings have been added via drupal_add_js() and the |
|
1478 |
// 'javascript_always_use_jquery' variable is set to FALSE, drupal_get_js() |
|
1479 |
// should not return jQuery and other standard scripts and settings, nor |
|
1480 |
// should it return the requested settings (since they cannot actually be |
|
1481 |
// addded to the page without jQuery). |
|
1482 |
$this->resetStaticVariables(); |
|
1483 |
variable_set('javascript_always_use_jquery', FALSE); |
|
1484 |
drupal_add_js(array('testJavaScriptSetting' => 'test'), 'setting'); |
|
1485 |
$javascript = drupal_get_js(); |
|
1486 |
$this->assertTrue(strpos($javascript, 'misc/jquery.js') === FALSE, 'When "javascript_always_use_jquery" is FALSE: The JavaScript returned by drupal_get_js() when only settings have been added does not include jquery.js.'); |
|
1487 |
$this->assertTrue(strpos($javascript, 'misc/drupal.js') === FALSE, 'When "javascript_always_use_jquery" is FALSE: The JavaScript returned by drupal_get_js() when only settings have been added does not include drupal.js.'); |
|
1488 |
$this->assertTrue(strpos($javascript, 'Drupal.settings') === FALSE, 'When "javascript_always_use_jquery" is FALSE: The JavaScript returned by drupal_get_js() when only settings have been added does not include Drupal.settings.'); |
|
1489 |
$this->assertTrue(strpos($javascript, 'basePath') === FALSE, 'When "javascript_always_use_jquery" is FALSE: The JavaScript returned by drupal_get_js() when only settings have been added does not include the basePath Drupal setting.'); |
|
1490 |
$this->assertTrue(strpos($javascript, 'testJavaScriptSetting') === FALSE, 'When "javascript_always_use_jquery" is FALSE: The JavaScript returned by drupal_get_js() when only settings have been added does not include the added Drupal settings.'); |
|
1491 |
variable_del('javascript_always_use_jquery'); |
|
1492 |
|
|
1493 |
// When a regular file has been added via drupal_add_js(), drupal_get_js() |
|
1494 |
// should return jQuery and other standard scripts and settings. |
|
1495 |
$this->resetStaticVariables(); |
|
1496 |
drupal_add_js('misc/collapse.js'); |
|
1497 |
$javascript = drupal_get_js(); |
|
1498 |
$this->assertTrue(strpos($javascript, 'misc/jquery.js') !== FALSE, 'Default behavior: The JavaScript returned by drupal_get_js() when a custom JavaScript file has been added includes jquery.js.'); |
|
1499 |
$this->assertTrue(strpos($javascript, 'misc/drupal.js') !== FALSE, 'Default behavior: The JavaScript returned by drupal_get_js() when a custom JavaScript file has been added includes drupal.js.'); |
|
1500 |
$this->assertTrue(strpos($javascript, 'Drupal.settings') !== FALSE, 'Default behavior: The JavaScript returned by drupal_get_js() when a custom JavaScript file has been added includes Drupal.settings.'); |
|
1501 |
$this->assertTrue(strpos($javascript, 'basePath') !== FALSE, 'Default behavior: The JavaScript returned by drupal_get_js() when a custom JavaScript file has been added includes the basePath Drupal setting.'); |
|
1502 |
$this->assertTrue(strpos($javascript, 'misc/collapse.js') !== FALSE, 'Default behavior: The JavaScript returned by drupal_get_js() when a custom JavaScript file has been added includes the custom file.'); |
|
1503 |
|
|
1504 |
// When a regular file has been added via drupal_add_js() and the |
|
1505 |
// 'javascript_always_use_jquery' variable is set to FALSE, drupal_get_js() |
|
1506 |
// should still return jQuery and other standard scripts and settings |
|
1507 |
// (since the file is assumed to require jQuery by default). |
|
1508 |
$this->resetStaticVariables(); |
|
1509 |
variable_set('javascript_always_use_jquery', FALSE); |
|
1510 |
drupal_add_js('misc/collapse.js'); |
|
1511 |
$javascript = drupal_get_js(); |
|
1512 |
$this->assertTrue(strpos($javascript, 'misc/jquery.js') !== FALSE, 'When "javascript_always_use_jquery" is FALSE: The JavaScript returned by drupal_get_js() when a custom JavaScript file has been added includes jquery.js.'); |
|
1513 |
$this->assertTrue(strpos($javascript, 'misc/drupal.js') !== FALSE, 'When "javascript_always_use_jquery" is FALSE: The JavaScript returned by drupal_get_js() when a custom JavaScript file has been added includes drupal.js.'); |
|
1514 |
$this->assertTrue(strpos($javascript, 'Drupal.settings') !== FALSE, 'When "javascript_always_use_jquery" is FALSE: The JavaScript returned by drupal_get_js() when a custom JavaScript file has been added includes Drupal.settings.'); |
|
1515 |
$this->assertTrue(strpos($javascript, 'basePath') !== FALSE, 'When "javascript_always_use_jquery" is FALSE: The JavaScript returned by drupal_get_js() when a custom JavaScript file has been added includes the basePath Drupal setting.'); |
|
1516 |
$this->assertTrue(strpos($javascript, 'misc/collapse.js') !== FALSE, 'When "javascript_always_use_jquery" is FALSE: The JavaScript returned by drupal_get_js() when a custom JavaScript file has been added includes the custom file.'); |
|
1517 |
variable_del('javascript_always_use_jquery'); |
|
1518 |
|
|
1519 |
// When a file that does not require jQuery has been added via |
|
1520 |
// drupal_add_js(), drupal_get_js() should still return jQuery and other |
|
1521 |
// standard scripts and settings by default. |
|
1522 |
$this->resetStaticVariables(); |
|
1523 |
drupal_add_js('misc/collapse.js', array('requires_jquery' => FALSE)); |
|
1524 |
$javascript = drupal_get_js(); |
|
1525 |
$this->assertTrue(strpos($javascript, 'misc/jquery.js') !== FALSE, 'Default behavior: The JavaScript returned by drupal_get_js() when a custom JavaScript file that does not require jQuery has been added includes jquery.js.'); |
|
1526 |
$this->assertTrue(strpos($javascript, 'misc/drupal.js') !== FALSE, 'Default behavior: The JavaScript returned by drupal_get_js() when a custom JavaScript file that does not require jQuery has been added includes drupal.js.'); |
|
1527 |
$this->assertTrue(strpos($javascript, 'Drupal.settings') !== FALSE, 'Default behavior: The JavaScript returned by drupal_get_js() when a custom JavaScript file that does not require jQuery has been added includes Drupal.settings.'); |
|
1528 |
$this->assertTrue(strpos($javascript, 'basePath') !== FALSE, 'Default behavior: The JavaScript returned by drupal_get_js() when a custom JavaScript file that does not require jQuery has been added includes the basePath Drupal setting.'); |
|
1529 |
$this->assertTrue(strpos($javascript, 'misc/collapse.js') !== FALSE, 'Default behavior: The JavaScript returned by drupal_get_js() when a custom JavaScript file that does not require jQuery has been added includes the custom file.'); |
|
1530 |
|
|
1531 |
// When a file that does not require jQuery has been added via |
|
1532 |
// drupal_add_js() and the 'javascript_always_use_jquery' variable is set |
|
1533 |
// to FALSE, drupal_get_js() should not return jQuery and other standard |
|
1534 |
// scripts and setting, but it should still return the requested file. |
|
1535 |
$this->resetStaticVariables(); |
|
1536 |
variable_set('javascript_always_use_jquery', FALSE); |
|
1537 |
drupal_add_js('misc/collapse.js', array('requires_jquery' => FALSE)); |
|
1538 |
$javascript = drupal_get_js(); |
|
1539 |
$this->assertTrue(strpos($javascript, 'misc/jquery.js') === FALSE, 'When "javascript_always_use_jquery" is FALSE: The JavaScript returned by drupal_get_js() when a custom JavaScript file that does not require jQuery has been added does not include jquery.js.'); |
|
1540 |
$this->assertTrue(strpos($javascript, 'misc/drupal.js') === FALSE, 'When "javascript_always_use_jquery" is FALSE: The JavaScript returned by drupal_get_js() when a custom JavaScript file that does not require jQuery has been added does not include drupal.js.'); |
|
1541 |
$this->assertTrue(strpos($javascript, 'Drupal.settings') === FALSE, 'When "javascript_always_use_jquery" is FALSE: The JavaScript returned by drupal_get_js() when a custom JavaScript file that does not require jQuery has been added does not include Drupal.settings.'); |
|
1542 |
$this->assertTrue(strpos($javascript, 'basePath') === FALSE, 'When "javascript_always_use_jquery" is FALSE: The JavaScript returned by drupal_get_js() when a custom JavaScript file that does not require jQuery has been added does not include the basePath Drupal setting.'); |
|
1543 |
$this->assertTrue(strpos($javascript, 'misc/collapse.js') !== FALSE, 'When "javascript_always_use_jquery" is FALSE: The JavaScript returned by drupal_get_js() when a custom JavaScript file that does not require jQuery has been added includes the custom file.'); |
|
1544 |
variable_del('javascript_always_use_jquery'); |
|
1545 |
|
|
1546 |
// When 'javascript_always_use_jquery' is set to FALSE and a file that does |
|
1547 |
// not require jQuery is added, followed by one that does, drupal_get_js() |
|
1548 |
// should return jQuery and other standard scripts and settings, in |
|
1549 |
// addition to both of the requested files. |
|
1550 |
$this->resetStaticVariables(); |
|
1551 |
variable_set('javascript_always_use_jquery', FALSE); |
|
1552 |
drupal_add_js('misc/collapse.js', array('requires_jquery' => FALSE)); |
|
1553 |
drupal_add_js('misc/ajax.js'); |
|
1554 |
$javascript = drupal_get_js(); |
|
1555 |
$this->assertTrue(strpos($javascript, 'misc/jquery.js') !== FALSE, 'When "javascript_always_use_jquery" is FALSE: The JavaScript returned by drupal_get_js() when at least one custom JavaScript file that requires jQuery has been added includes jquery.js.'); |
|
1556 |
$this->assertTrue(strpos($javascript, 'misc/drupal.js') !== FALSE, 'When "javascript_always_use_jquery" is FALSE: The JavaScript returned by drupal_get_js() when at least one custom JavaScript file that requires jQuery has been added includes drupal.js.'); |
|
1557 |
$this->assertTrue(strpos($javascript, 'Drupal.settings') !== FALSE, 'When "javascript_always_use_jquery" is FALSE: The JavaScript returned by drupal_get_js() when at least one custom JavaScript file that requires jQuery has been added includes Drupal.settings.'); |
|
1558 |
$this->assertTrue(strpos($javascript, 'basePath') !== FALSE, 'When "javascript_always_use_jquery" is FALSE: The JavaScript returned by drupal_get_js() when at least one custom JavaScript file that requires jQuery has been added includes the basePath Drupal setting.'); |
|
1559 |
$this->assertTrue(strpos($javascript, 'misc/collapse.js') !== FALSE, 'When "javascript_always_use_jquery" is FALSE: The JavaScript returned by drupal_get_js() when at least one custom JavaScript file that requires jQuery has been added includes the first custom file.'); |
|
1560 |
$this->assertTrue(strpos($javascript, 'misc/ajax.js') !== FALSE, 'When "javascript_always_use_jquery" is FALSE: The JavaScript returned by drupal_get_js() when at least one custom JavaScript file that requires jQuery has been added includes the second custom file.'); |
|
1561 |
variable_del('javascript_always_use_jquery'); |
|
1562 |
} |
|
1563 |
|
|
1443 | 1564 |
/** |
1444 | 1565 |
* Test drupal_add_js() sets preproccess to false when cache is set to false. |
1445 | 1566 |
*/ |
... | ... | |
1668 | 1789 |
$query_string = variable_get('css_js_query_string', '0'); |
1669 | 1790 |
$this->assertRaw(drupal_get_path('module', 'node') . '/node.js?' . $query_string, 'Query string was appended correctly to js.'); |
1670 | 1791 |
} |
1792 |
|
|
1793 |
/** |
|
1794 |
* Resets static variables related to adding JavaScript to a page. |
|
1795 |
*/ |
|
1796 |
function resetStaticVariables() { |
|
1797 |
drupal_static_reset('drupal_add_js'); |
|
1798 |
drupal_static_reset('drupal_add_library'); |
|
1799 |
drupal_static_reset('drupal_get_library'); |
|
1800 |
} |
|
1671 | 1801 |
} |
1672 | 1802 |
|
1673 | 1803 |
/** |
Formats disponibles : Unified diff
Update core to 7.36