diff --git a/core/modules/breakpoint/tests/Drupal/breakpoint/Tests/BreakpointMediaQueryTest.php b/core/modules/breakpoint/tests/Drupal/breakpoint/Tests/BreakpointMediaQueryTest.php deleted file mode 100644 index 1e2524f..0000000 --- a/core/modules/breakpoint/tests/Drupal/breakpoint/Tests/BreakpointMediaQueryTest.php +++ /dev/null @@ -1,125 +0,0 @@ - 'Breakpoint media query tests', - 'description' => 'Test validation of media queries.', - 'group' => 'Breakpoint', - ); - } - - /** - * Test valid media queries. - */ - public function testValidMediaQueries() { - $media_queries = array( - // Bartik breakpoints. - '(min-width: 0px)', - 'all and (min-width: 560px) and (max-width:850px)', - 'all and (min-width: 851px)', - // Seven breakpoints. - '(min-width: 0em)', - 'screen and (min-width: 40em)', - // Stark breakpoints. - '(min-width: 0px)', - 'all and (min-width: 480px) and (max-width: 959px)', - 'all and (min-width: 960px)', - // Other media queries. - '(orientation)', - 'all and (orientation)', - 'not all and (orientation)', - 'only all and (orientation)', - 'screen and (width)', - 'screen and (width: 0)', - 'screen and (width: 0px)', - 'screen and (width: 0em)', - 'screen and (min-width: -0)', - 'screen and (max-width: 0)', - 'screen and (max-width: 0.3)', - 'screen and (min-width)', - // Multiline and comments. - 'screen and /* this is a comment */ (min-width)', - "screen\nand /* this is a comment */ (min-width)", - "screen\n\nand /* this is\n a comment */ (min-width)", - // Unrecognized features are allowed. - 'screen and (-webkit-min-device-pixel-ratio: 7)', - 'screen and (min-orientation: landscape)', - 'screen and (max-orientation: landscape)', - ); - - foreach ($media_queries as $media_query) { - $this->assertTrue(Breakpoint::isValidMediaQuery($media_query), $media_query . ' is valid.'); - } - } - - /** - * Test invalid media queries. - */ - public function testInvalidMediaQueries() { - $media_queries = array( - '', - 'not (orientation)', - 'only (orientation)', - 'all and not all', - 'screen and (width: 0xx)', - 'screen and (width: -8xx)', - 'screen and (width: -xx)', - 'screen and (width: xx)', - 'screen and (width: px)', - 'screen and (width: -8px)', - 'screen and (width: -0.8px)', - 'screen and (height: 0xx)', - 'screen and (height: -8xx)', - 'screen and (height: -xx)', - 'screen and (height: xx)', - 'screen and (height: px)', - 'screen and (height: -8px)', - 'screen and (height: -0.8px)', - 'screen and (device-width: 0xx)', - 'screen and (device-width: -8xx)', - 'screen and (device-width: -xx)', - 'screen and (device-width: xx)', - 'screen and (device-width: px)', - 'screen and (device-width: -8px)', - 'screen and (device-width: -0.8px)', - 'screen and (device-height: 0xx)', - 'screen and (device-height: -8xx)', - 'screen and (device-height: -xx)', - 'screen and (device-height: xx)', - 'screen and (device-height: px)', - 'screen and (device-height: -8px)', - 'screen and (device-height: -0.8px)', - 'screen and (min-orientation)', - 'screen and (max-orientation)', - 'screen and (orientation: bogus)', - '(orientation: bogus)', - 'screen and (ori"entation: bogus)', - ); - - foreach ($media_queries as $media_query) { - try { - $this->assertFalse(Breakpoint::isValidMediaQuery($media_query), $media_query . ' is not valid.'); - } - catch (InvalidBreakpointMediaQueryException $e) { - $this->assertTrue(TRUE, sprintf('%s is not valid.', $media_query)); - } - } - } -} diff --git a/core/modules/breakpoint/tests/Drupal/breakpoint/Tests/BreakpointMediaQueryUnitTest.php b/core/modules/breakpoint/tests/Drupal/breakpoint/Tests/BreakpointMediaQueryUnitTest.php new file mode 100644 index 0000000..6626af1 --- /dev/null +++ b/core/modules/breakpoint/tests/Drupal/breakpoint/Tests/BreakpointMediaQueryUnitTest.php @@ -0,0 +1,125 @@ + 'Breakpoint media query tests', + 'description' => 'Test validation of media queries.', + 'group' => 'Breakpoint', + ); + } + + /** + * Test valid media queries. + */ + public function testValidMediaQueries() { + $media_queries = array( + // Bartik breakpoints. + '(min-width: 0px)', + 'all and (min-width: 560px) and (max-width:850px)', + 'all and (min-width: 851px)', + // Seven breakpoints. + '(min-width: 0em)', + 'screen and (min-width: 40em)', + // Stark breakpoints. + '(min-width: 0px)', + 'all and (min-width: 480px) and (max-width: 959px)', + 'all and (min-width: 960px)', + // Other media queries. + '(orientation)', + 'all and (orientation)', + 'not all and (orientation)', + 'only all and (orientation)', + 'screen and (width)', + 'screen and (width: 0)', + 'screen and (width: 0px)', + 'screen and (width: 0em)', + 'screen and (min-width: -0)', + 'screen and (max-width: 0)', + 'screen and (max-width: 0.3)', + 'screen and (min-width)', + // Multiline and comments. + 'screen and /* this is a comment */ (min-width)', + "screen\nand /* this is a comment */ (min-width)", + "screen\n\nand /* this is\n a comment */ (min-width)", + // Unrecognized features are allowed. + 'screen and (-webkit-min-device-pixel-ratio: 7)', + 'screen and (min-orientation: landscape)', + 'screen and (max-orientation: landscape)', + ); + + foreach ($media_queries as $media_query) { + $this->assertTrue(Breakpoint::isValidMediaQuery($media_query), $media_query . ' is valid.'); + } + } + + /** + * Test invalid media queries. + */ + public function testInvalidMediaQueries() { + $media_queries = array( + '', + 'not (orientation)', + 'only (orientation)', + 'all and not all', + 'screen and (width: 0xx)', + 'screen and (width: -8xx)', + 'screen and (width: -xx)', + 'screen and (width: xx)', + 'screen and (width: px)', + 'screen and (width: -8px)', + 'screen and (width: -0.8px)', + 'screen and (height: 0xx)', + 'screen and (height: -8xx)', + 'screen and (height: -xx)', + 'screen and (height: xx)', + 'screen and (height: px)', + 'screen and (height: -8px)', + 'screen and (height: -0.8px)', + 'screen and (device-width: 0xx)', + 'screen and (device-width: -8xx)', + 'screen and (device-width: -xx)', + 'screen and (device-width: xx)', + 'screen and (device-width: px)', + 'screen and (device-width: -8px)', + 'screen and (device-width: -0.8px)', + 'screen and (device-height: 0xx)', + 'screen and (device-height: -8xx)', + 'screen and (device-height: -xx)', + 'screen and (device-height: xx)', + 'screen and (device-height: px)', + 'screen and (device-height: -8px)', + 'screen and (device-height: -0.8px)', + 'screen and (min-orientation)', + 'screen and (max-orientation)', + 'screen and (orientation: bogus)', + '(orientation: bogus)', + 'screen and (ori"entation: bogus)', + ); + + foreach ($media_queries as $media_query) { + try { + $this->assertFalse(Breakpoint::isValidMediaQuery($media_query), $media_query . ' is not valid.'); + } + catch (InvalidBreakpointMediaQueryException $e) { + $this->assertTrue(TRUE, sprintf('%s is not valid.', $media_query)); + } + } + } +} diff --git a/core/modules/comment/lib/Drupal/comment/Tests/Views/DefaultViewRecentComments.php b/core/modules/comment/lib/Drupal/comment/Tests/Views/DefaultViewRecentComments.php deleted file mode 100644 index 46d0318..0000000 --- a/core/modules/comment/lib/Drupal/comment/Tests/Views/DefaultViewRecentComments.php +++ /dev/null @@ -1,157 +0,0 @@ - 'Default View - Recent Comments', - 'description' => 'Test results for the Recent Comments view shipped with the module', - 'group' => 'Views Config', - ); - } - - public function setUp() { - parent::setUp(); - - // Create a new content type - $content_type = $this->drupalCreateContentType(); - - // Add a node of the new content type. - $node_data = array( - 'type' => $content_type->type, - ); - - $this->node = $this->drupalCreateNode($node_data); - - // Create some comments and attach them to the created node. - for ($i = 0; $i < $this->masterDisplayResults; $i++) { - $comment = entity_create('comment', array('node_type' => 'comment_node_' . $this->node->type)); - $comment->uid->target_id = 0; - $comment->nid->target_id = $this->node->nid; - $comment->subject->value = 'Test comment ' . $i; - $comment->comment_body->value = 'Test body ' . $i; - $comment->comment_body->format = 'full_html'; - - comment_save($comment); - } - - // Store all the nodes just created to access their properties on the tests. - $this->commentsCreated = entity_load_multiple('comment'); - } - - /** - * Tests the block defined by the comments_recent view. - */ - public function testBlockDisplay() { - $view = views_get_view('comments_recent'); - $view->setDisplay('block_1'); - $this->executeView($view); - - $map = array( - 'comment_nid' => 'nid', - 'comment_subject' => 'subject', - 'cid' => 'cid', - 'comment_changed' => 'changed' - ); - $expected_result = array(); - foreach (array_values($this->commentsCreated) as $key => $comment) { - $expected_result[$key]['nid'] = $comment->nid->target_id; - $expected_result[$key]['subject'] = $comment->subject->value; - $expected_result[$key]['cid'] = $comment->id(); - $expected_result[$key]['changed'] = $comment->changed->value; - } - $this->assertIdenticalResultset($view, $expected_result, $map); - - // Check the number of results given by the display is the expected. - $this->assertEqual(sizeof($view->result), $this->blockDisplayResults, - format_string('There are exactly @results comments. Expected @expected', - array('@results' => count($view->result), '@expected' => $this->blockDisplayResults) - ) - ); - } - - /** - * Tests the page defined by the comments_recent view. - */ - public function testPageDisplay() { - $view = views_get_view('comments_recent'); - $view->setDisplay('page_1'); - $this->executeView($view); - - $map = array( - 'comment_nid' => 'nid', - 'comment_subject' => 'subject', - 'comment_changed' => 'changed', - 'comment_changed' => 'created', - 'cid' => 'cid' - ); - $expected_result = array(); - foreach (array_values($this->commentsCreated) as $key => $comment) { - $expected_result[$key]['nid'] = $comment->nid->target_id; - $expected_result[$key]['subject'] = $comment->subject->value; - $expected_result[$key]['changed'] = $comment->changed->value; - $expected_result[$key]['created'] = $comment->created->value; - $expected_result[$key]['cid'] = $comment->id(); - } - $this->assertIdenticalResultset($view, $expected_result, $map); - - // Check the number of results given by the display is the expected. - $this->assertEqual(count($view->result), $this->pageDisplayResults, - format_string('There are exactly @results comments. Expected @expected', - array('@results' => count($view->result), '@expected' => $this->pageDisplayResults) - ) - ); - } -} diff --git a/core/modules/comment/lib/Drupal/comment/Tests/Views/DefaultViewRecentCommentsTest.php b/core/modules/comment/lib/Drupal/comment/Tests/Views/DefaultViewRecentCommentsTest.php new file mode 100644 index 0000000..3d3993f --- /dev/null +++ b/core/modules/comment/lib/Drupal/comment/Tests/Views/DefaultViewRecentCommentsTest.php @@ -0,0 +1,158 @@ + 'Default View - Recent Comments', + 'description' => 'Test results for the Recent Comments view shipped with the module', + 'group' => 'Views Config', + ); + } + + public function setUp() { + parent::setUp(); + + // Create a new content type + $content_type = $this->drupalCreateContentType(); + + // Add a node of the new content type. + $node_data = array( + 'type' => $content_type->type, + ); + + $this->node = $this->drupalCreateNode($node_data); + + // Create some comments and attach them to the created node. + for ($i = 0; $i < $this->masterDisplayResults; $i++) { + $comment = entity_create('comment', array('node_type' => 'comment_node_' . $this->node->type)); + $comment->uid->target_id = 0; + $comment->nid->target_id = $this->node->nid; + $comment->subject->value = 'Test comment ' . $i; + $comment->comment_body->value = 'Test body ' . $i; + $comment->comment_body->format = 'full_html'; + + comment_save($comment); + } + + // Store all the nodes just created to access their properties on the tests. + $this->commentsCreated = entity_load_multiple('comment'); + } + + /** + * Tests the block defined by the comments_recent view. + */ + public function testBlockDisplay() { + $view = views_get_view('comments_recent'); + $view->setDisplay('block_1'); + $this->executeView($view); + + $map = array( + 'comment_nid' => 'nid', + 'comment_subject' => 'subject', + 'cid' => 'cid', + 'comment_changed' => 'changed' + ); + $expected_result = array(); + foreach (array_values($this->commentsCreated) as $key => $comment) { + $expected_result[$key]['nid'] = $comment->nid->target_id; + $expected_result[$key]['subject'] = $comment->subject->value; + $expected_result[$key]['cid'] = $comment->id(); + $expected_result[$key]['changed'] = $comment->changed->value; + } + $this->assertIdenticalResultset($view, $expected_result, $map); + + // Check the number of results given by the display is the expected. + $this->assertEqual(sizeof($view->result), $this->blockDisplayResults, + format_string('There are exactly @results comments. Expected @expected', + array('@results' => count($view->result), '@expected' => $this->blockDisplayResults) + ) + ); + } + + /** + * Tests the page defined by the comments_recent view. + */ + public function testPageDisplay() { + $view = views_get_view('comments_recent'); + $view->setDisplay('page_1'); + $this->executeView($view); + + $map = array( + 'comment_nid' => 'nid', + 'comment_subject' => 'subject', + 'comment_changed' => 'changed', + 'comment_changed' => 'created', + 'cid' => 'cid' + ); + $expected_result = array(); + foreach (array_values($this->commentsCreated) as $key => $comment) { + $expected_result[$key]['nid'] = $comment->nid->target_id; + $expected_result[$key]['subject'] = $comment->subject->value; + $expected_result[$key]['changed'] = $comment->changed->value; + $expected_result[$key]['created'] = $comment->created->value; + $expected_result[$key]['cid'] = $comment->id(); + } + $this->assertIdenticalResultset($view, $expected_result, $map); + + // Check the number of results given by the display is the expected. + $this->assertEqual(count($view->result), $this->pageDisplayResults, + format_string('There are exactly @results comments. Expected @expected', + array('@results' => count($view->result), '@expected' => $this->pageDisplayResults) + ) + ); + } +} diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageBrowserDetectionTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageBrowserDetectionTest.php new file mode 100644 index 0000000..c953a15 --- /dev/null +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageBrowserDetectionTest.php @@ -0,0 +1,228 @@ + 'Browser language detection', + 'description' => 'Tests for the browser language detection.', + 'group' => 'Language', + ); + } + + /** + * Unit tests for the language_from_browser() function. + * + * @see language_from_browser(). + */ + function testLanguageFromBrowser() { + // The order of the languages is only important if the browser language + // codes are having the same qvalue, otherwise the one with the highest + // qvalue is prefered. The automatically generated generic tags are always + // having a lower qvalue. + + $languages = array( + // In our test case, 'en' has priority over 'en-US'. + 'en' => new Language(array( + 'langcode' => 'en', + )), + 'en-US' => new Language(array( + 'langcode' => 'en-US', + )), + // But 'fr-CA' has priority over 'fr'. + 'fr-CA' => new Language(array( + 'langcode' => 'fr-CA', + )), + 'fr' => new Language(array( + 'langcode' => 'fr', + )), + // 'es-MX' is alone. + 'es-MX' => new Language(array( + 'langcode' => 'es-MX', + )), + // 'pt' is alone. + 'pt' => new Language(array( + 'langcode' => 'pt', + )), + // Language codes with more then one dash are actually valid. + // eh-oh-laa-laa is the official language code of the Teletubbies. + 'eh-oh-laa-laa' => new Language(array( + 'langcode' => 'eh-oh-laa-laa', + )), + // Chinese languages. + 'zh-hans' => new Language(array( + 'langcode' => 'zh-hans', + )), + 'zh-hant' => new Language(array( + 'langcode' => 'zh-hant', + )), + 'zh-hant-tw' => new Language(array( + 'langcode' => 'zh-hant', + )), + ); + + $test_cases = array( + // Equal qvalue for each language, choose the site prefered one. + 'en,en-US,fr-CA,fr,es-MX' => 'en', + 'en-US,en,fr-CA,fr,es-MX' => 'en', + 'fr,en' => 'en', + 'en,fr' => 'en', + 'en-US,fr' => 'en-US', + 'fr,en-US' => 'en-US', + 'fr,fr-CA' => 'fr-CA', + 'fr-CA,fr' => 'fr-CA', + 'fr' => 'fr-CA', + 'fr;q=1' => 'fr-CA', + 'fr,es-MX' => 'fr-CA', + 'fr,es' => 'fr-CA', + 'es,fr' => 'fr-CA', + 'es-MX,de' => 'es-MX', + 'de,es-MX' => 'es-MX', + + // Different cases and whitespace. + 'en' => 'en', + 'En' => 'en', + 'EN' => 'en', + ' en' => 'en', + 'en ' => 'en', + 'en, fr' => 'en', + + // A less specific language from the browser matches a more specific one + // from the website, and the other way around for compatibility with + // some versions of Internet Explorer. + 'es' => 'es-MX', + 'es-MX' => 'es-MX', + 'pt' => 'pt', + 'pt-PT' => 'pt', + 'pt-PT;q=0.5,pt-BR;q=1,en;q=0.7' => 'en', + 'pt-PT;q=1,pt-BR;q=0.5,en;q=0.7' => 'en', + 'pt-PT;q=0.4,pt-BR;q=0.1,en;q=0.7' => 'en', + 'pt-PT;q=0.1,pt-BR;q=0.4,en;q=0.7' => 'en', + + // Language code with several dashes are valid. The less specific language + // from the browser matches the more specific one from the website. + 'eh-oh-laa-laa' => 'eh-oh-laa-laa', + 'eh-oh-laa' => 'eh-oh-laa-laa', + 'eh-oh' => 'eh-oh-laa-laa', + 'eh' => 'eh-oh-laa-laa', + + // Different qvalues. + 'fr,en;q=0.5' => 'fr-CA', + 'fr,en;q=0.5,fr-CA;q=0.25' => 'fr', + + // Silly wildcards are also valid. + '*,fr-CA;q=0.5' => 'en', + '*,en;q=0.25' => 'fr-CA', + 'en,en-US;q=0.5,fr;q=0.25' => 'en', + 'en-US,en;q=0.5,fr;q=0.25' => 'en-US', + + // Unresolvable cases. + '' => FALSE, + 'de,pl' => FALSE, + 'iecRswK4eh' => FALSE, + $this->randomName(10) => FALSE, + + // Chinese langcodes. + 'zh-cn, en-us;q=0.90, en;q=0.80, zh;q=0.70' => 'zh-hans', + 'zh-tw, en-us;q=0.90, en;q=0.80, zh;q=0.70' => 'zh-hant', + 'zh-hant, en-us;q=0.90, en;q=0.80, zh;q=0.70' => 'zh-hant', + 'zh-hans, en-us;q=0.90, en;q=0.80, zh;q=0.70' => 'zh-hans', + 'zh-cn' => 'zh-hans', + 'zh-sg' => 'zh-hans', + 'zh-tw' => 'zh-hant', + 'zh-hk' => 'zh-hant', + 'zh-mo' => 'zh-hant', + 'zh-hans' => 'zh-hans', + 'zh-hant' => 'zh-hant', + 'zh-chs' => 'zh-hans', + 'zh-cht' => 'zh-hant', + ); + + foreach ($test_cases as $accept_language => $expected_result) { + $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $accept_language; + $result = language_from_browser($languages); + $this->assertIdentical($result, $expected_result, format_string("Language selection '@accept-language' selects '@result', result = '@actual'", array('@accept-language' => $accept_language, '@result' => $expected_result, '@actual' => isset($result) ? $result : 'none'))); + } + } + + /** + * Tests for adding, editing and deleting mappings between browser language + * codes and Drupal language codes. + */ + function testUIBrowserLanguageMappings() { + // User to manage languages. + $admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages')); + $this->drupalLogin($admin_user); + + // Check that the configure link exists. + $this->drupalGet('admin/config/regional/language/detection'); + $this->assertLinkByHref('admin/config/regional/language/detection/browser'); + + // Check that defaults are loaded from language.mappings.yml. + $this->drupalGet('admin/config/regional/language/detection/browser'); + $this->assertField('edit-mappings-zh-cn-browser-langcode', 'zh-cn', 'Chinese browser language code found.'); + $this->assertField('edit-mappings-zh-cn-drupal-langcode', 'zh-hans-cn', 'Chinese Drupal language code found.'); + + // Delete zh-cn language code. + $browser_langcode = 'zh-cn'; + $this->drupalGet('admin/config/regional/language/detection/browser/delete/' . $browser_langcode); + $message = t('Are you sure you want to delete @browser_langcode?', array( + '@browser_langcode' => $browser_langcode, + )); + $this->assertRaw($message); + + // Confirm the delete. + $edit = array(); + $this->drupalPost('admin/config/regional/language/detection/browser/delete/' . $browser_langcode, $edit, t('Confirm')); + + // Check that ch-zn no longer exists. + $this->assertNoField('edit-mappings-zh-cn-browser-langcode', 'Chinese browser language code no longer exists.'); + + // Add a new custom mapping. + $edit = array( + 'new_mapping[browser_langcode]' => 'xx', + 'new_mapping[drupal_langcode]' => 'en', + ); + $this->drupalPost('admin/config/regional/language/detection/browser', $edit, t('Save configuration')); + $this->drupalGet('admin/config/regional/language/detection/browser'); + $this->assertField('edit-mappings-xx-browser-langcode', 'xx', 'Browser language code found.'); + $this->assertField('edit-mappings-xx-drupal-langcode', 'en', 'Drupal language code found.'); + + // Add the same custom mapping again. + $this->drupalPost('admin/config/regional/language/detection/browser', $edit, t('Save configuration')); + $this->assertText('Browser language codes must be unique.'); + + // Change browser language code of our custom mapping to zh-sg. + $edit = array( + 'mappings[xx][browser_langcode]' => 'zh-sg', + 'mappings[xx][drupal_langcode]' => 'en', + ); + $this->drupalPost('admin/config/regional/language/detection/browser', $edit, t('Save configuration')); + $this->assertText(t('Browser language codes must be unique.')); + + // Change Drupal language code of our custom mapping to zh-hans. + $edit = array( + 'mappings[xx][browser_langcode]' => 'xx', + 'mappings[xx][drupal_langcode]' => 'zh-hans', + ); + $this->drupalPost('admin/config/regional/language/detection/browser', $edit, t('Save configuration')); + $this->drupalGet('admin/config/regional/language/detection/browser'); + $this->assertField('edit-mappings-xx-browser-langcode', 'xx', 'Browser language code found.'); + $this->assertField('edit-mappings-xx-drupal-langcode', 'zh-hans', 'Drupal language code found.'); + } +} diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageBrowserDetectionUnitTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageBrowserDetectionUnitTest.php deleted file mode 100644 index 80a835d..0000000 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageBrowserDetectionUnitTest.php +++ /dev/null @@ -1,228 +0,0 @@ - 'Browser language detection', - 'description' => 'Tests for the browser language detection.', - 'group' => 'Language', - ); - } - - /** - * Unit tests for the language_from_browser() function. - * - * @see language_from_browser(). - */ - function testLanguageFromBrowser() { - // The order of the languages is only important if the browser language - // codes are having the same qvalue, otherwise the one with the highest - // qvalue is prefered. The automatically generated generic tags are always - // having a lower qvalue. - - $languages = array( - // In our test case, 'en' has priority over 'en-US'. - 'en' => new Language(array( - 'langcode' => 'en', - )), - 'en-US' => new Language(array( - 'langcode' => 'en-US', - )), - // But 'fr-CA' has priority over 'fr'. - 'fr-CA' => new Language(array( - 'langcode' => 'fr-CA', - )), - 'fr' => new Language(array( - 'langcode' => 'fr', - )), - // 'es-MX' is alone. - 'es-MX' => new Language(array( - 'langcode' => 'es-MX', - )), - // 'pt' is alone. - 'pt' => new Language(array( - 'langcode' => 'pt', - )), - // Language codes with more then one dash are actually valid. - // eh-oh-laa-laa is the official language code of the Teletubbies. - 'eh-oh-laa-laa' => new Language(array( - 'langcode' => 'eh-oh-laa-laa', - )), - // Chinese languages. - 'zh-hans' => new Language(array( - 'langcode' => 'zh-hans', - )), - 'zh-hant' => new Language(array( - 'langcode' => 'zh-hant', - )), - 'zh-hant-tw' => new Language(array( - 'langcode' => 'zh-hant', - )), - ); - - $test_cases = array( - // Equal qvalue for each language, choose the site prefered one. - 'en,en-US,fr-CA,fr,es-MX' => 'en', - 'en-US,en,fr-CA,fr,es-MX' => 'en', - 'fr,en' => 'en', - 'en,fr' => 'en', - 'en-US,fr' => 'en-US', - 'fr,en-US' => 'en-US', - 'fr,fr-CA' => 'fr-CA', - 'fr-CA,fr' => 'fr-CA', - 'fr' => 'fr-CA', - 'fr;q=1' => 'fr-CA', - 'fr,es-MX' => 'fr-CA', - 'fr,es' => 'fr-CA', - 'es,fr' => 'fr-CA', - 'es-MX,de' => 'es-MX', - 'de,es-MX' => 'es-MX', - - // Different cases and whitespace. - 'en' => 'en', - 'En' => 'en', - 'EN' => 'en', - ' en' => 'en', - 'en ' => 'en', - 'en, fr' => 'en', - - // A less specific language from the browser matches a more specific one - // from the website, and the other way around for compatibility with - // some versions of Internet Explorer. - 'es' => 'es-MX', - 'es-MX' => 'es-MX', - 'pt' => 'pt', - 'pt-PT' => 'pt', - 'pt-PT;q=0.5,pt-BR;q=1,en;q=0.7' => 'en', - 'pt-PT;q=1,pt-BR;q=0.5,en;q=0.7' => 'en', - 'pt-PT;q=0.4,pt-BR;q=0.1,en;q=0.7' => 'en', - 'pt-PT;q=0.1,pt-BR;q=0.4,en;q=0.7' => 'en', - - // Language code with several dashes are valid. The less specific language - // from the browser matches the more specific one from the website. - 'eh-oh-laa-laa' => 'eh-oh-laa-laa', - 'eh-oh-laa' => 'eh-oh-laa-laa', - 'eh-oh' => 'eh-oh-laa-laa', - 'eh' => 'eh-oh-laa-laa', - - // Different qvalues. - 'fr,en;q=0.5' => 'fr-CA', - 'fr,en;q=0.5,fr-CA;q=0.25' => 'fr', - - // Silly wildcards are also valid. - '*,fr-CA;q=0.5' => 'en', - '*,en;q=0.25' => 'fr-CA', - 'en,en-US;q=0.5,fr;q=0.25' => 'en', - 'en-US,en;q=0.5,fr;q=0.25' => 'en-US', - - // Unresolvable cases. - '' => FALSE, - 'de,pl' => FALSE, - 'iecRswK4eh' => FALSE, - $this->randomName(10) => FALSE, - - // Chinese langcodes. - 'zh-cn, en-us;q=0.90, en;q=0.80, zh;q=0.70' => 'zh-hans', - 'zh-tw, en-us;q=0.90, en;q=0.80, zh;q=0.70' => 'zh-hant', - 'zh-hant, en-us;q=0.90, en;q=0.80, zh;q=0.70' => 'zh-hant', - 'zh-hans, en-us;q=0.90, en;q=0.80, zh;q=0.70' => 'zh-hans', - 'zh-cn' => 'zh-hans', - 'zh-sg' => 'zh-hans', - 'zh-tw' => 'zh-hant', - 'zh-hk' => 'zh-hant', - 'zh-mo' => 'zh-hant', - 'zh-hans' => 'zh-hans', - 'zh-hant' => 'zh-hant', - 'zh-chs' => 'zh-hans', - 'zh-cht' => 'zh-hant', - ); - - foreach ($test_cases as $accept_language => $expected_result) { - $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $accept_language; - $result = language_from_browser($languages); - $this->assertIdentical($result, $expected_result, format_string("Language selection '@accept-language' selects '@result', result = '@actual'", array('@accept-language' => $accept_language, '@result' => $expected_result, '@actual' => isset($result) ? $result : 'none'))); - } - } - - /** - * Tests for adding, editing and deleting mappings between browser language - * codes and Drupal language codes. - */ - function testUIBrowserLanguageMappings() { - // User to manage languages. - $admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages')); - $this->drupalLogin($admin_user); - - // Check that the configure link exists. - $this->drupalGet('admin/config/regional/language/detection'); - $this->assertLinkByHref('admin/config/regional/language/detection/browser'); - - // Check that defaults are loaded from language.mappings.yml. - $this->drupalGet('admin/config/regional/language/detection/browser'); - $this->assertField('edit-mappings-zh-cn-browser-langcode', 'zh-cn', 'Chinese browser language code found.'); - $this->assertField('edit-mappings-zh-cn-drupal-langcode', 'zh-hans-cn', 'Chinese Drupal language code found.'); - - // Delete zh-cn language code. - $browser_langcode = 'zh-cn'; - $this->drupalGet('admin/config/regional/language/detection/browser/delete/' . $browser_langcode); - $message = t('Are you sure you want to delete @browser_langcode?', array( - '@browser_langcode' => $browser_langcode, - )); - $this->assertRaw($message); - - // Confirm the delete. - $edit = array(); - $this->drupalPost('admin/config/regional/language/detection/browser/delete/' . $browser_langcode, $edit, t('Confirm')); - - // Check that ch-zn no longer exists. - $this->assertNoField('edit-mappings-zh-cn-browser-langcode', 'Chinese browser language code no longer exists.'); - - // Add a new custom mapping. - $edit = array( - 'new_mapping[browser_langcode]' => 'xx', - 'new_mapping[drupal_langcode]' => 'en', - ); - $this->drupalPost('admin/config/regional/language/detection/browser', $edit, t('Save configuration')); - $this->drupalGet('admin/config/regional/language/detection/browser'); - $this->assertField('edit-mappings-xx-browser-langcode', 'xx', 'Browser language code found.'); - $this->assertField('edit-mappings-xx-drupal-langcode', 'en', 'Drupal language code found.'); - - // Add the same custom mapping again. - $this->drupalPost('admin/config/regional/language/detection/browser', $edit, t('Save configuration')); - $this->assertText('Browser language codes must be unique.'); - - // Change browser language code of our custom mapping to zh-sg. - $edit = array( - 'mappings[xx][browser_langcode]' => 'zh-sg', - 'mappings[xx][drupal_langcode]' => 'en', - ); - $this->drupalPost('admin/config/regional/language/detection/browser', $edit, t('Save configuration')); - $this->assertText(t('Browser language codes must be unique.')); - - // Change Drupal language code of our custom mapping to zh-hans. - $edit = array( - 'mappings[xx][browser_langcode]' => 'xx', - 'mappings[xx][drupal_langcode]' => 'zh-hans', - ); - $this->drupalPost('admin/config/regional/language/detection/browser', $edit, t('Save configuration')); - $this->drupalGet('admin/config/regional/language/detection/browser'); - $this->assertField('edit-mappings-xx-browser-langcode', 'xx', 'Browser language code found.'); - $this->assertField('edit-mappings-xx-drupal-langcode', 'zh-hans', 'Drupal language code found.'); - } -} diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleJavascriptTranslation.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleJavascriptTranslation.php deleted file mode 100644 index d8e028f..0000000 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleJavascriptTranslation.php +++ /dev/null @@ -1,101 +0,0 @@ - 'Javascript translation', - 'description' => 'Tests parsing js files for translatable strings', - 'group' => 'Locale', - ); - } - - function testFileParsing() { - - $filename = drupal_get_path('module', 'locale') . '/tests/locale_test.js'; - - // Parse the file to look for source strings. - _locale_parse_js_file($filename); - - // Get all of the source strings that were found. - foreach (locale_storage()->getStrings(array('type' => 'javascript', 'name' => $filename)) as $string) { - $source_strings[$string->source] = $string->context; - } - // List of all strings that should be in the file. - $test_strings = array( - "Standard Call t" => '', - "Whitespace Call t" => '', - - "Single Quote t" => '', - "Single Quote \\'Escaped\\' t" => '', - "Single Quote Concat strings t" => '', - - "Double Quote t" => '', - "Double Quote \\\"Escaped\\\" t" => '', - "Double Quote Concat strings t" => '', - - "Context !key Args t" => "Context string", - - "Context Unquoted t" => "Context string unquoted", - "Context Single Quoted t" => "Context string single quoted", - "Context Double Quoted t" => "Context string double quoted", - - "Standard Call plural" => '', - "Standard Call @count plural" => '', - "Whitespace Call plural" => '', - "Whitespace Call @count plural" => '', - - "Single Quote plural" => '', - "Single Quote @count plural" => '', - "Single Quote \\'Escaped\\' plural" => '', - "Single Quote \\'Escaped\\' @count plural" => '', - - "Double Quote plural" => '', - "Double Quote @count plural" => '', - "Double Quote \\\"Escaped\\\" plural" => '', - "Double Quote \\\"Escaped\\\" @count plural" => '', - - "Context !key Args plural" => "Context string", - "Context !key Args @count plural" => "Context string", - - "Context Unquoted plural" => "Context string unquoted", - "Context Unquoted @count plural" => "Context string unquoted", - "Context Single Quoted plural" => "Context string single quoted", - "Context Single Quoted @count plural" => "Context string single quoted", - "Context Double Quoted plural" => "Context string double quoted", - "Context Double Quoted @count plural" => "Context string double quoted", - ); - - // Assert that all strings were found properly. - foreach ($test_strings as $str => $context) { - $args = array('%source' => $str, '%context' => $context); - - // Make sure that the string was found in the file. - $this->assertTrue(isset($source_strings[$str]), t("Found source string: %source", $args)); - - // Make sure that the proper context was matched. - $this->assertTrue(isset($source_strings[$str]) && $source_strings[$str] === $context, strlen($context) > 0 ? t("Context for %source is %context", $args) : t("Context for %source is blank", $args)); - } - - $this->assertEqual(count($source_strings), count($test_strings), t("Found correct number of source strings.")); - } -} diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleJavascriptTranslationTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleJavascriptTranslationTest.php new file mode 100644 index 0000000..792a496 --- /dev/null +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleJavascriptTranslationTest.php @@ -0,0 +1,101 @@ + 'Javascript translation', + 'description' => 'Tests parsing js files for translatable strings', + 'group' => 'Locale', + ); + } + + function testFileParsing() { + + $filename = drupal_get_path('module', 'locale') . '/tests/locale_test.js'; + + // Parse the file to look for source strings. + _locale_parse_js_file($filename); + + // Get all of the source strings that were found. + foreach (locale_storage()->getStrings(array('type' => 'javascript', 'name' => $filename)) as $string) { + $source_strings[$string->source] = $string->context; + } + // List of all strings that should be in the file. + $test_strings = array( + "Standard Call t" => '', + "Whitespace Call t" => '', + + "Single Quote t" => '', + "Single Quote \\'Escaped\\' t" => '', + "Single Quote Concat strings t" => '', + + "Double Quote t" => '', + "Double Quote \\\"Escaped\\\" t" => '', + "Double Quote Concat strings t" => '', + + "Context !key Args t" => "Context string", + + "Context Unquoted t" => "Context string unquoted", + "Context Single Quoted t" => "Context string single quoted", + "Context Double Quoted t" => "Context string double quoted", + + "Standard Call plural" => '', + "Standard Call @count plural" => '', + "Whitespace Call plural" => '', + "Whitespace Call @count plural" => '', + + "Single Quote plural" => '', + "Single Quote @count plural" => '', + "Single Quote \\'Escaped\\' plural" => '', + "Single Quote \\'Escaped\\' @count plural" => '', + + "Double Quote plural" => '', + "Double Quote @count plural" => '', + "Double Quote \\\"Escaped\\\" plural" => '', + "Double Quote \\\"Escaped\\\" @count plural" => '', + + "Context !key Args plural" => "Context string", + "Context !key Args @count plural" => "Context string", + + "Context Unquoted plural" => "Context string unquoted", + "Context Unquoted @count plural" => "Context string unquoted", + "Context Single Quoted plural" => "Context string single quoted", + "Context Single Quoted @count plural" => "Context string single quoted", + "Context Double Quoted plural" => "Context string double quoted", + "Context Double Quoted @count plural" => "Context string double quoted", + ); + + // Assert that all strings were found properly. + foreach ($test_strings as $str => $context) { + $args = array('%source' => $str, '%context' => $context); + + // Make sure that the string was found in the file. + $this->assertTrue(isset($source_strings[$str]), t("Found source string: %source", $args)); + + // Make sure that the proper context was matched. + $this->assertTrue(isset($source_strings[$str]) && $source_strings[$str] === $context, strlen($context) > 0 ? t("Context for %source is %context", $args) : t("Context for %source is blank", $args)); + } + + $this->assertEqual(count($source_strings), count($test_strings), t("Found correct number of source strings.")); + } +} diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchExpressionInsertExtractTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchExpressionInsertExtractTest.php deleted file mode 100644 index b7ea84a..0000000 --- a/core/modules/search/lib/Drupal/search/Tests/SearchExpressionInsertExtractTest.php +++ /dev/null @@ -1,71 +0,0 @@ - 'Search expression insert/extract', - 'description' => 'Tests the functions search_expression_insert() and search_expression_extract()', - 'group' => 'Search', - ); - } - - function setUp() { - drupal_load('module', 'search'); - parent::setUp(); - } - - /** - * Tests search_expression_insert() and search_expression_extract(). - */ - function testInsertExtract() { - $base_expression = "mykeyword"; - // Build an array of option, value, what should be in the expression, what - // should be retrieved from expression. - $cases = array( - array('foo', 'bar', 'foo:bar', 'bar'), // Normal case. - array('foo', NULL, '', NULL), // Empty value: shouldn't insert. - array('foo', ' ', 'foo:', ''), // Space as value: should insert but retrieve empty string. - array('foo', '', 'foo:', ''), // Empty string as value: should insert but retrieve empty string. - array('foo', '0', 'foo:0', '0'), // String zero as value: should insert. - array('foo', 0, 'foo:0', '0'), // Numeric zero as value: should insert. - ); - - foreach ($cases as $index => $case) { - $after_insert = search_expression_insert($base_expression, $case[0], $case[1]); - if (empty($case[2])) { - $this->assertEqual($after_insert, $base_expression, "Empty insert does not change expression in case $index"); - } - else { - $this->assertEqual($after_insert, $base_expression . ' ' . $case[2], "Insert added correct expression for case $index"); - } - - $retrieved = search_expression_extract($after_insert, $case[0]); - if (!isset($case[3])) { - $this->assertFalse(isset($retrieved), "Empty retrieval results in unset value in case $index"); - } - else { - $this->assertEqual($retrieved, $case[3], "Value is retrieved for case $index"); - } - - $after_clear = search_expression_insert($after_insert, $case[0]); - $this->assertEqual(trim($after_clear), $base_expression, "After clearing, base expression is restored for case $index"); - - $cleared = search_expression_extract($after_clear, $case[0]); - $this->assertFalse(isset($cleared), "After clearing, value could not be retrieved for case $index"); - } - } -} diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchExpressionInsertExtractUnitTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchExpressionInsertExtractUnitTest.php new file mode 100644 index 0000000..3559470 --- /dev/null +++ b/core/modules/search/lib/Drupal/search/Tests/SearchExpressionInsertExtractUnitTest.php @@ -0,0 +1,71 @@ + 'Search expression insert/extract', + 'description' => 'Tests the functions search_expression_insert() and search_expression_extract()', + 'group' => 'Search', + ); + } + + function setUp() { + drupal_load('module', 'search'); + parent::setUp(); + } + + /** + * Tests search_expression_insert() and search_expression_extract(). + */ + function testInsertExtract() { + $base_expression = "mykeyword"; + // Build an array of option, value, what should be in the expression, what + // should be retrieved from expression. + $cases = array( + array('foo', 'bar', 'foo:bar', 'bar'), // Normal case. + array('foo', NULL, '', NULL), // Empty value: shouldn't insert. + array('foo', ' ', 'foo:', ''), // Space as value: should insert but retrieve empty string. + array('foo', '', 'foo:', ''), // Empty string as value: should insert but retrieve empty string. + array('foo', '0', 'foo:0', '0'), // String zero as value: should insert. + array('foo', 0, 'foo:0', '0'), // Numeric zero as value: should insert. + ); + + foreach ($cases as $index => $case) { + $after_insert = search_expression_insert($base_expression, $case[0], $case[1]); + if (empty($case[2])) { + $this->assertEqual($after_insert, $base_expression, "Empty insert does not change expression in case $index"); + } + else { + $this->assertEqual($after_insert, $base_expression . ' ' . $case[2], "Insert added correct expression for case $index"); + } + + $retrieved = search_expression_extract($after_insert, $case[0]); + if (!isset($case[3])) { + $this->assertFalse(isset($retrieved), "Empty retrieval results in unset value in case $index"); + } + else { + $this->assertEqual($retrieved, $case[3], "Value is retrieved for case $index"); + } + + $after_clear = search_expression_insert($after_insert, $case[0]); + $this->assertEqual(trim($after_clear), $base_expression, "After clearing, base expression is restored for case $index"); + + $cleared = search_expression_extract($after_clear, $case[0]); + $this->assertFalse(isset($cleared), "After clearing, value could not be retrieved for case $index"); + } + } +} diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/ColorTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/ColorTest.php deleted file mode 100644 index 2c32b31..0000000 --- a/core/modules/system/lib/Drupal/system/Tests/Common/ColorTest.php +++ /dev/null @@ -1,100 +0,0 @@ - 'Color conversion', - 'description' => 'Tests Color utility class conversions.', - 'group' => 'Common', - ); - } - - /** - * Tests Color::hexToRgb(). - */ - function testHexToRgb() { - // Any invalid arguments should throw an exception. - $values = array('', '-1', '1', '12', '12345', '1234567', '123456789', '123456789a', 'foo'); - // Duplicate all invalid value tests with additional '#' prefix. - // The '#' prefix inherently turns the data type into a string. - foreach ($values as $value) { - $values[] = '#' . $value; - } - // Add invalid data types (hex value must be a string). - $values = array_merge($values, array( - 1, 12, 1234, 12345, 123456, 1234567, 12345678, 123456789, 123456789, - -1, PHP_INT_MAX, PHP_INT_MAX + 1, -PHP_INT_MAX, - 0x0, 0x010, - )); - - foreach ($values as $test) { - $this->assertFalse(Color::validateHex($test), var_export($test, TRUE) . ' is invalid.'); - try { - Color::hexToRgb($test); - $this->fail('Color::hexToRgb(' . var_export($test, TRUE) . ') did not throw an exception.'); - } - catch (\InvalidArgumentException $e) { - $this->pass('Color::hexToRgb(' . var_export($test, TRUE) . ') threw an exception.'); - } - } - - // PHP automatically casts a numeric array key into an integer. - // Since hex values may consist of 0-9 only, they need to be defined as - // array values. - $tests = array( - // Shorthands without alpha. - array('hex' => '#000', 'rgb' => array('red' => 0, 'green' => 0, 'blue' => 0)), - array('hex' => '#fff', 'rgb' => array('red' => 255, 'green' => 255, 'blue' => 255)), - array('hex' => '#abc', 'rgb' => array('red' => 170, 'green' => 187, 'blue' => 204)), - array('hex' => 'cba', 'rgb' => array('red' => 204, 'green' => 187, 'blue' => 170)), - // Full without alpha. - array('hex' => '#000000', 'rgb' => array('red' => 0, 'green' => 0, 'blue' => 0)), - array('hex' => '#ffffff', 'rgb' => array('red' => 255, 'green' => 255, 'blue' => 255)), - array('hex' => '#010203', 'rgb' => array('red' => 1, 'green' => 2, 'blue' => 3)), - ); - foreach ($tests as $test) { - $result = Color::hexToRgb($test['hex']); - $this->assertIdentical($result, $test['rgb']); - } - } - - /** - * Tests Color::rgbToHex(). - */ - function testRgbToHex() { - $tests = array( - '#000000' => array('red' => 0, 'green' => 0, 'blue' => 0), - '#ffffff' => array('red' => 255, 'green' => 255, 'blue' => 255), - '#777777' => array('red' => 119, 'green' => 119, 'blue' => 119), - '#010203' => array('red' => 1, 'green' => 2, 'blue' => 3), - ); - // Input using named RGB array (e.g., as returned by Color::hexToRgb()). - foreach ($tests as $expected => $rgb) { - $this->assertIdentical(Color::rgbToHex($rgb), $expected); - } - // Input using indexed RGB array (e.g.: array(10, 10, 10)). - foreach ($tests as $expected => $rgb) { - $rgb = array_values($rgb); - $this->assertIdentical(Color::rgbToHex($rgb), $expected); - } - // Input using CSS RGB string notation (e.g.: 10, 10, 10). - foreach ($tests as $expected => $rgb) { - $rgb = implode(', ', $rgb); - $this->assertIdentical(Color::rgbToHex($rgb), $expected); - } - } -} diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/ColorUnitTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/ColorUnitTest.php new file mode 100644 index 0000000..5f96f0e --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Common/ColorUnitTest.php @@ -0,0 +1,100 @@ + 'Color conversion', + 'description' => 'Tests Color utility class conversions.', + 'group' => 'Common', + ); + } + + /** + * Tests Color::hexToRgb(). + */ + function testHexToRgb() { + // Any invalid arguments should throw an exception. + $values = array('', '-1', '1', '12', '12345', '1234567', '123456789', '123456789a', 'foo'); + // Duplicate all invalid value tests with additional '#' prefix. + // The '#' prefix inherently turns the data type into a string. + foreach ($values as $value) { + $values[] = '#' . $value; + } + // Add invalid data types (hex value must be a string). + $values = array_merge($values, array( + 1, 12, 1234, 12345, 123456, 1234567, 12345678, 123456789, 123456789, + -1, PHP_INT_MAX, PHP_INT_MAX + 1, -PHP_INT_MAX, + 0x0, 0x010, + )); + + foreach ($values as $test) { + $this->assertFalse(Color::validateHex($test), var_export($test, TRUE) . ' is invalid.'); + try { + Color::hexToRgb($test); + $this->fail('Color::hexToRgb(' . var_export($test, TRUE) . ') did not throw an exception.'); + } + catch (\InvalidArgumentException $e) { + $this->pass('Color::hexToRgb(' . var_export($test, TRUE) . ') threw an exception.'); + } + } + + // PHP automatically casts a numeric array key into an integer. + // Since hex values may consist of 0-9 only, they need to be defined as + // array values. + $tests = array( + // Shorthands without alpha. + array('hex' => '#000', 'rgb' => array('red' => 0, 'green' => 0, 'blue' => 0)), + array('hex' => '#fff', 'rgb' => array('red' => 255, 'green' => 255, 'blue' => 255)), + array('hex' => '#abc', 'rgb' => array('red' => 170, 'green' => 187, 'blue' => 204)), + array('hex' => 'cba', 'rgb' => array('red' => 204, 'green' => 187, 'blue' => 170)), + // Full without alpha. + array('hex' => '#000000', 'rgb' => array('red' => 0, 'green' => 0, 'blue' => 0)), + array('hex' => '#ffffff', 'rgb' => array('red' => 255, 'green' => 255, 'blue' => 255)), + array('hex' => '#010203', 'rgb' => array('red' => 1, 'green' => 2, 'blue' => 3)), + ); + foreach ($tests as $test) { + $result = Color::hexToRgb($test['hex']); + $this->assertIdentical($result, $test['rgb']); + } + } + + /** + * Tests Color::rgbToHex(). + */ + function testRgbToHex() { + $tests = array( + '#000000' => array('red' => 0, 'green' => 0, 'blue' => 0), + '#ffffff' => array('red' => 255, 'green' => 255, 'blue' => 255), + '#777777' => array('red' => 119, 'green' => 119, 'blue' => 119), + '#010203' => array('red' => 1, 'green' => 2, 'blue' => 3), + ); + // Input using named RGB array (e.g., as returned by Color::hexToRgb()). + foreach ($tests as $expected => $rgb) { + $this->assertIdentical(Color::rgbToHex($rgb), $expected); + } + // Input using indexed RGB array (e.g.: array(10, 10, 10)). + foreach ($tests as $expected => $rgb) { + $rgb = array_values($rgb); + $this->assertIdentical(Color::rgbToHex($rgb), $expected); + } + // Input using CSS RGB string notation (e.g.: 10, 10, 10). + foreach ($tests as $expected => $rgb) { + $rgb = implode(', ', $rgb); + $this->assertIdentical(Color::rgbToHex($rgb), $expected); + } + } +} diff --git a/core/modules/system/lib/Drupal/system/Tests/DrupalKernel/DrupalKernelTest.php b/core/modules/system/lib/Drupal/system/Tests/DrupalKernel/DrupalKernelTest.php deleted file mode 100644 index 0b08def..0000000 --- a/core/modules/system/lib/Drupal/system/Tests/DrupalKernel/DrupalKernelTest.php +++ /dev/null @@ -1,116 +0,0 @@ - 'DrupalKernel tests', - 'description' => 'Tests DIC compilation to disk.', - 'group' => 'DrupalKernel', - ); - } - - function setUp() { - parent::setUp(); - global $conf; - $conf['php_storage']['service_container']= array( - 'bin' => 'service_container', - 'class' => 'Drupal\Component\PhpStorage\MTimeProtectedFileStorage', - 'directory' => DRUPAL_ROOT . '/' . $this->public_files_directory . '/php', - 'secret' => $GLOBALS['drupal_hash_salt'], - ); - // Use a non-persistent cache to avoid queries to non-existing tables. - $this->settingsSet('cache', array('default' => 'cache.backend.memory')); - } - - /** - * Tests DIC compilation. - */ - function testCompileDIC() { - $classloader = drupal_classloader(); - // @todo: write a memory based storage backend for testing. - $module_enabled = array( - 'system' => 'system', - 'user' => 'user', - ); - $kernel = new DrupalKernel('testing', FALSE, $classloader); - $kernel->updateModules($module_enabled); - $kernel->boot(); - // Instantiate it a second time and we should get the compiled Container - // class. - $kernel = new DrupalKernel('testing', FALSE, $classloader); - $kernel->updateModules($module_enabled); - $kernel->boot(); - $container = $kernel->getContainer(); - $refClass = new ReflectionClass($container); - $is_compiled_container = - $refClass->getParentClass()->getName() == 'Symfony\Component\DependencyInjection\Container' && - !$refClass->isSubclassOf('Symfony\Component\DependencyInjection\ContainerBuilder'); - $this->assertTrue($is_compiled_container); - - // Now use the read-only storage implementation, simulating a "production" - // environment. - global $conf; - $conf['php_storage']['service_container']['class'] = 'Drupal\Component\PhpStorage\FileReadOnlyStorage'; - $kernel = new DrupalKernel('testing', FALSE, $classloader); - $kernel->updateModules($module_enabled); - $kernel->boot(); - $container = $kernel->getContainer(); - $refClass = new ReflectionClass($container); - $is_compiled_container = - $refClass->getParentClass()->getName() == 'Symfony\Component\DependencyInjection\Container' && - !$refClass->isSubclassOf('Symfony\Component\DependencyInjection\ContainerBuilder'); - $this->assertTrue($is_compiled_container); - // Test that our synthetic services are there. - $classloader = $container->get('class_loader'); - $refClass = new ReflectionClass($classloader); - $this->assertTrue($refClass->hasMethod('loadClass'), 'Container has a classloader'); - - // We make this assertion here purely to show that the new container below - // is functioning correctly, i.e. we get a brand new ContainerBuilder - // which has the required new services, after changing the list of enabled - // modules. - $this->assertFalse($container->has('bundle_test_class')); - - // Add another module so that we can test that the new module's bundle is - // registered to the new container. - $module_enabled['bundle_test'] = 'bundle_test'; - $kernel = new DrupalKernel('testing', FALSE, $classloader); - $kernel->updateModules($module_enabled); - $kernel->boot(); - // Instantiate it a second time and we should still get a ContainerBuilder - // class because we are using the read-only PHP storage. - $kernel = new DrupalKernel('testing', FALSE, $classloader); - $kernel->updateModules($module_enabled); - $kernel->boot(); - $container = $kernel->getContainer(); - $refClass = new ReflectionClass($container); - $is_container_builder = $refClass->isSubclassOf('Symfony\Component\DependencyInjection\ContainerBuilder'); - $this->assertTrue($is_container_builder); - // Assert that the new module's bundle was registered to the new container. - $this->assertTrue($container->has('bundle_test_class')); - // Test that our synthetic services are there. - $classloader = $container->get('class_loader'); - $refClass = new ReflectionClass($classloader); - $this->assertTrue($refClass->hasMethod('loadClass'), 'Container has a classloader'); - // Check that the location of the new module is registered. - $modules = $container->getParameter('container.modules'); - $this->assertEqual($modules['bundle_test'], drupal_get_filename('module', 'bundle_test')); - } -} diff --git a/core/modules/system/lib/Drupal/system/Tests/DrupalKernel/DrupalKernelUnitTest.php b/core/modules/system/lib/Drupal/system/Tests/DrupalKernel/DrupalKernelUnitTest.php new file mode 100644 index 0000000..6e6de6a --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/DrupalKernel/DrupalKernelUnitTest.php @@ -0,0 +1,116 @@ + 'DrupalKernel tests', + 'description' => 'Tests DIC compilation to disk.', + 'group' => 'DrupalKernel', + ); + } + + function setUp() { + parent::setUp(); + global $conf; + $conf['php_storage']['service_container']= array( + 'bin' => 'service_container', + 'class' => 'Drupal\Component\PhpStorage\MTimeProtectedFileStorage', + 'directory' => DRUPAL_ROOT . '/' . $this->public_files_directory . '/php', + 'secret' => $GLOBALS['drupal_hash_salt'], + ); + // Use a non-persistent cache to avoid queries to non-existing tables. + $this->settingsSet('cache', array('default' => 'cache.backend.memory')); + } + + /** + * Tests DIC compilation. + */ + function testCompileDIC() { + $classloader = drupal_classloader(); + // @todo: write a memory based storage backend for testing. + $module_enabled = array( + 'system' => 'system', + 'user' => 'user', + ); + $kernel = new DrupalKernel('testing', FALSE, $classloader); + $kernel->updateModules($module_enabled); + $kernel->boot(); + // Instantiate it a second time and we should get the compiled Container + // class. + $kernel = new DrupalKernel('testing', FALSE, $classloader); + $kernel->updateModules($module_enabled); + $kernel->boot(); + $container = $kernel->getContainer(); + $refClass = new ReflectionClass($container); + $is_compiled_container = + $refClass->getParentClass()->getName() == 'Symfony\Component\DependencyInjection\Container' && + !$refClass->isSubclassOf('Symfony\Component\DependencyInjection\ContainerBuilder'); + $this->assertTrue($is_compiled_container); + + // Now use the read-only storage implementation, simulating a "production" + // environment. + global $conf; + $conf['php_storage']['service_container']['class'] = 'Drupal\Component\PhpStorage\FileReadOnlyStorage'; + $kernel = new DrupalKernel('testing', FALSE, $classloader); + $kernel->updateModules($module_enabled); + $kernel->boot(); + $container = $kernel->getContainer(); + $refClass = new ReflectionClass($container); + $is_compiled_container = + $refClass->getParentClass()->getName() == 'Symfony\Component\DependencyInjection\Container' && + !$refClass->isSubclassOf('Symfony\Component\DependencyInjection\ContainerBuilder'); + $this->assertTrue($is_compiled_container); + // Test that our synthetic services are there. + $classloader = $container->get('class_loader'); + $refClass = new ReflectionClass($classloader); + $this->assertTrue($refClass->hasMethod('loadClass'), 'Container has a classloader'); + + // We make this assertion here purely to show that the new container below + // is functioning correctly, i.e. we get a brand new ContainerBuilder + // which has the required new services, after changing the list of enabled + // modules. + $this->assertFalse($container->has('bundle_test_class')); + + // Add another module so that we can test that the new module's bundle is + // registered to the new container. + $module_enabled['bundle_test'] = 'bundle_test'; + $kernel = new DrupalKernel('testing', FALSE, $classloader); + $kernel->updateModules($module_enabled); + $kernel->boot(); + // Instantiate it a second time and we should still get a ContainerBuilder + // class because we are using the read-only PHP storage. + $kernel = new DrupalKernel('testing', FALSE, $classloader); + $kernel->updateModules($module_enabled); + $kernel->boot(); + $container = $kernel->getContainer(); + $refClass = new ReflectionClass($container); + $is_container_builder = $refClass->isSubclassOf('Symfony\Component\DependencyInjection\ContainerBuilder'); + $this->assertTrue($is_container_builder); + // Assert that the new module's bundle was registered to the new container. + $this->assertTrue($container->has('bundle_test_class')); + // Test that our synthetic services are there. + $classloader = $container->get('class_loader'); + $refClass = new ReflectionClass($classloader); + $this->assertTrue($refClass->hasMethod('loadClass'), 'Container has a classloader'); + // Check that the location of the new module is registered. + $modules = $container->getParameter('container.modules'); + $this->assertEqual($modules['bundle_test'], drupal_get_filename('module', 'bundle_test')); + } +} diff --git a/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/DatabaseStorageExpirableTest.php b/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/DatabaseStorageExpirableTest.php deleted file mode 100644 index 9f4d01e..0000000 --- a/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/DatabaseStorageExpirableTest.php +++ /dev/null @@ -1,170 +0,0 @@ - 'Expirable database storage', - 'description' => 'Tests the expirable key-value database storage.', - 'group' => 'Key-value store', - ); - } - - protected function setUp() { - parent::setUp(); - $this->factory = 'keyvalue.expirable'; - module_load_install('system'); - $schema = system_schema(); - db_create_table('key_value_expire', $schema['key_value_expire']); - $this->container - ->register('database', 'Drupal\Core\Database\Connection') - ->setFactoryClass('Drupal\Core\Database\Database') - ->setFactoryMethod('getConnection') - ->addArgument('default'); - $this->container - ->register('keyvalue.expirable.database', 'Drupal\Core\KeyValueStore\KeyValueDatabaseExpirableFactory') - ->addArgument(new Reference('database')); - global $conf; - $conf['keyvalue_expirable_default'] = 'keyvalue.expirable.database'; - } - - protected function tearDown() { - // The DatabaseExpirableStorage class has a destructor which deletes rows - // from the key_value_expire table. We need to make sure the destructor - // runs before the table is deleted. - $this->container->set('keyvalue.expirable', NULL); - db_drop_table('key_value_expire'); - parent::tearDown(); - } - - /** - * Tests CRUD functionality with expiration. - */ - public function testCRUDWithExpiration() { - $stores = $this->createStorage(); - - // Verify that an item can be stored with setWithExpire(). - // Use a random expiration in each test. - $stores[0]->setWithExpire('foo', $this->objects[0], rand(500, 100000)); - $this->assertIdenticalObject($this->objects[0], $stores[0]->get('foo')); - // Verify that the other collection is not affected. - $this->assertFalse($stores[1]->get('foo')); - - // Verify that an item can be updated with setWithExpire(). - $stores[0]->setWithExpire('foo', $this->objects[1], rand(500, 100000)); - $this->assertIdenticalObject($this->objects[1], $stores[0]->get('foo')); - // Verify that the other collection is still not affected. - $this->assertFalse($stores[1]->get('foo')); - - // Verify that the expirable data key is unique. - $stores[1]->setWithExpire('foo', $this->objects[2], rand(500, 100000)); - $this->assertIdenticalObject($this->objects[1], $stores[0]->get('foo')); - $this->assertIdenticalObject($this->objects[2], $stores[1]->get('foo')); - - // Verify that multiple items can be stored with setMultipleWithExpire(). - $values = array( - 'foo' => $this->objects[3], - 'bar' => $this->objects[4], - ); - $stores[0]->setMultipleWithExpire($values, rand(500, 100000)); - $result = $stores[0]->getMultiple(array('foo', 'bar')); - foreach ($values as $j => $value) { - $this->assertIdenticalObject($value, $result[$j]); - } - - // Verify that the other collection was not affected. - $this->assertIdenticalObject($stores[1]->get('foo'), $this->objects[2]); - $this->assertFalse($stores[1]->get('bar')); - - // Verify that all items in a collection can be retrieved. - // Ensure that an item with the same name exists in the other collection. - $stores[1]->set('foo', $this->objects[5]); - $result = $stores[0]->getAll(); - // Not using assertIdentical(), since the order is not defined for getAll(). - $this->assertEqual(count($result), count($values)); - foreach ($result as $key => $value) { - $this->assertEqual($values[$key], $value); - } - // Verify that all items in the other collection are different. - $result = $stores[1]->getAll(); - $this->assertEqual($result, array('foo' => $this->objects[5])); - - // Verify that multiple items can be deleted. - $stores[0]->deleteMultiple(array_keys($values)); - $this->assertFalse($stores[0]->get('foo')); - $this->assertFalse($stores[0]->get('bar')); - $this->assertFalse($stores[0]->getMultiple(array('foo', 'bar'))); - // Verify that the item in the other collection still exists. - $this->assertIdenticalObject($this->objects[5], $stores[1]->get('foo')); - - // Test that setWithExpireIfNotExists() succeeds only the first time. - $key = $this->randomName(); - for ($i = 0; $i <= 1; $i++) { - // setWithExpireIfNotExists() should be TRUE the first time (when $i is - // 0) and FALSE the second time (when $i is 1). - $this->assertEqual(!$i, $stores[0]->setWithExpireIfNotExists($key, $this->objects[$i], rand(500, 100000))); - $this->assertIdenticalObject($this->objects[0], $stores[0]->get($key)); - // Verify that the other collection is not affected. - $this->assertFalse($stores[1]->get($key)); - } - - // Remove the item and try to set it again. - $stores[0]->delete($key); - $stores[0]->setWithExpireIfNotExists($key, $this->objects[1], rand(500, 100000)); - // This time it should succeed. - $this->assertIdenticalObject($this->objects[1], $stores[0]->get($key)); - // Verify that the other collection is still not affected. - $this->assertFalse($stores[1]->get($key)); - - } - - /** - * Tests data expiration. - */ - public function testExpiration() { - $stores = $this->createStorage(); - $day = 604800; - - // Set an item to expire in the past and another without an expiration. - $stores[0]->setWithExpire('yesterday', 'all my troubles seemed so far away', -1 * $day); - $stores[0]->set('troubles', 'here to stay'); - - // Only the non-expired item should be returned. - $this->assertFalse($stores[0]->get('yesterday')); - $this->assertIdentical($stores[0]->get('troubles'), 'here to stay'); - $this->assertIdentical(count($stores[0]->getMultiple(array('yesterday', 'troubles'))), 1); - - // Store items set to expire in the past in various ways. - $stores[0]->setWithExpire($this->randomName(), $this->objects[0], -7 * $day); - $stores[0]->setWithExpireIfNotExists($this->randomName(), $this->objects[1], -5 * $day); - $stores[0]->setMultipleWithExpire( - array( - $this->randomName() => $this->objects[2], - $this->randomName() => $this->objects[3], - ), - -3 * $day - ); - $stores[0]->setWithExpireIfNotExists('yesterday', "you'd forgiven me", -1 * $day); - $stores[0]->setWithExpire('still', "'til we say we're sorry", 2 * $day); - - // Ensure only non-expired items are retrived. - $all = $stores[0]->getAll(); - $this->assertIdentical(count($all), 2); - foreach (array('troubles', 'still') as $key) { - $this->assertTrue(!empty($all[$key])); - } - } - -} diff --git a/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/DatabaseStorageExpirableUnitTest.php b/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/DatabaseStorageExpirableUnitTest.php new file mode 100644 index 0000000..e681b11 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/DatabaseStorageExpirableUnitTest.php @@ -0,0 +1,170 @@ + 'Expirable database storage', + 'description' => 'Tests the expirable key-value database storage.', + 'group' => 'Key-value store', + ); + } + + protected function setUp() { + parent::setUp(); + $this->factory = 'keyvalue.expirable'; + module_load_install('system'); + $schema = system_schema(); + db_create_table('key_value_expire', $schema['key_value_expire']); + $this->container + ->register('database', 'Drupal\Core\Database\Connection') + ->setFactoryClass('Drupal\Core\Database\Database') + ->setFactoryMethod('getConnection') + ->addArgument('default'); + $this->container + ->register('keyvalue.expirable.database', 'Drupal\Core\KeyValueStore\KeyValueDatabaseExpirableFactory') + ->addArgument(new Reference('database')); + global $conf; + $conf['keyvalue_expirable_default'] = 'keyvalue.expirable.database'; + } + + protected function tearDown() { + // The DatabaseExpirableStorage class has a destructor which deletes rows + // from the key_value_expire table. We need to make sure the destructor + // runs before the table is deleted. + $this->container->set('keyvalue.expirable', NULL); + db_drop_table('key_value_expire'); + parent::tearDown(); + } + + /** + * Tests CRUD functionality with expiration. + */ + public function testCRUDWithExpiration() { + $stores = $this->createStorage(); + + // Verify that an item can be stored with setWithExpire(). + // Use a random expiration in each test. + $stores[0]->setWithExpire('foo', $this->objects[0], rand(500, 100000)); + $this->assertIdenticalObject($this->objects[0], $stores[0]->get('foo')); + // Verify that the other collection is not affected. + $this->assertFalse($stores[1]->get('foo')); + + // Verify that an item can be updated with setWithExpire(). + $stores[0]->setWithExpire('foo', $this->objects[1], rand(500, 100000)); + $this->assertIdenticalObject($this->objects[1], $stores[0]->get('foo')); + // Verify that the other collection is still not affected. + $this->assertFalse($stores[1]->get('foo')); + + // Verify that the expirable data key is unique. + $stores[1]->setWithExpire('foo', $this->objects[2], rand(500, 100000)); + $this->assertIdenticalObject($this->objects[1], $stores[0]->get('foo')); + $this->assertIdenticalObject($this->objects[2], $stores[1]->get('foo')); + + // Verify that multiple items can be stored with setMultipleWithExpire(). + $values = array( + 'foo' => $this->objects[3], + 'bar' => $this->objects[4], + ); + $stores[0]->setMultipleWithExpire($values, rand(500, 100000)); + $result = $stores[0]->getMultiple(array('foo', 'bar')); + foreach ($values as $j => $value) { + $this->assertIdenticalObject($value, $result[$j]); + } + + // Verify that the other collection was not affected. + $this->assertIdenticalObject($stores[1]->get('foo'), $this->objects[2]); + $this->assertFalse($stores[1]->get('bar')); + + // Verify that all items in a collection can be retrieved. + // Ensure that an item with the same name exists in the other collection. + $stores[1]->set('foo', $this->objects[5]); + $result = $stores[0]->getAll(); + // Not using assertIdentical(), since the order is not defined for getAll(). + $this->assertEqual(count($result), count($values)); + foreach ($result as $key => $value) { + $this->assertEqual($values[$key], $value); + } + // Verify that all items in the other collection are different. + $result = $stores[1]->getAll(); + $this->assertEqual($result, array('foo' => $this->objects[5])); + + // Verify that multiple items can be deleted. + $stores[0]->deleteMultiple(array_keys($values)); + $this->assertFalse($stores[0]->get('foo')); + $this->assertFalse($stores[0]->get('bar')); + $this->assertFalse($stores[0]->getMultiple(array('foo', 'bar'))); + // Verify that the item in the other collection still exists. + $this->assertIdenticalObject($this->objects[5], $stores[1]->get('foo')); + + // Test that setWithExpireIfNotExists() succeeds only the first time. + $key = $this->randomName(); + for ($i = 0; $i <= 1; $i++) { + // setWithExpireIfNotExists() should be TRUE the first time (when $i is + // 0) and FALSE the second time (when $i is 1). + $this->assertEqual(!$i, $stores[0]->setWithExpireIfNotExists($key, $this->objects[$i], rand(500, 100000))); + $this->assertIdenticalObject($this->objects[0], $stores[0]->get($key)); + // Verify that the other collection is not affected. + $this->assertFalse($stores[1]->get($key)); + } + + // Remove the item and try to set it again. + $stores[0]->delete($key); + $stores[0]->setWithExpireIfNotExists($key, $this->objects[1], rand(500, 100000)); + // This time it should succeed. + $this->assertIdenticalObject($this->objects[1], $stores[0]->get($key)); + // Verify that the other collection is still not affected. + $this->assertFalse($stores[1]->get($key)); + + } + + /** + * Tests data expiration. + */ + public function testExpiration() { + $stores = $this->createStorage(); + $day = 604800; + + // Set an item to expire in the past and another without an expiration. + $stores[0]->setWithExpire('yesterday', 'all my troubles seemed so far away', -1 * $day); + $stores[0]->set('troubles', 'here to stay'); + + // Only the non-expired item should be returned. + $this->assertFalse($stores[0]->get('yesterday')); + $this->assertIdentical($stores[0]->get('troubles'), 'here to stay'); + $this->assertIdentical(count($stores[0]->getMultiple(array('yesterday', 'troubles'))), 1); + + // Store items set to expire in the past in various ways. + $stores[0]->setWithExpire($this->randomName(), $this->objects[0], -7 * $day); + $stores[0]->setWithExpireIfNotExists($this->randomName(), $this->objects[1], -5 * $day); + $stores[0]->setMultipleWithExpire( + array( + $this->randomName() => $this->objects[2], + $this->randomName() => $this->objects[3], + ), + -3 * $day + ); + $stores[0]->setWithExpireIfNotExists('yesterday', "you'd forgiven me", -1 * $day); + $stores[0]->setWithExpire('still', "'til we say we're sorry", 2 * $day); + + // Ensure only non-expired items are retrived. + $all = $stores[0]->getAll(); + $this->assertIdentical(count($all), 2); + foreach (array('troubles', 'still') as $key) { + $this->assertTrue(!empty($all[$key])); + } + } + +} diff --git a/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/DatabaseStorageTest.php b/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/DatabaseStorageTest.php deleted file mode 100644 index a76281a..0000000 --- a/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/DatabaseStorageTest.php +++ /dev/null @@ -1,47 +0,0 @@ - 'Database storage', - 'description' => 'Tests the key-value database storage.', - 'group' => 'Key-value store', - ); - } - - protected function setUp() { - parent::setUp(); - module_load_install('system'); - $schema = system_schema(); - db_create_table('key_value', $schema['key_value']); - $this->container - ->register('database', 'Drupal\Core\Database\Connection') - ->setFactoryClass('Drupal\Core\Database\Database') - ->setFactoryMethod('getConnection') - ->addArgument('default'); - $this->container - ->register('keyvalue.database', 'Drupal\Core\KeyValueStore\KeyValueDatabaseFactory') - ->addArgument(new Reference('database')); - global $conf; - $conf['keyvalue_default'] = 'keyvalue.database'; - } - - protected function tearDown() { - db_drop_table('key_value'); - parent::tearDown(); - } - -} diff --git a/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/DatabaseStorageUnitTest.php b/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/DatabaseStorageUnitTest.php new file mode 100644 index 0000000..d2df26a --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/DatabaseStorageUnitTest.php @@ -0,0 +1,47 @@ + 'Database storage', + 'description' => 'Tests the key-value database storage.', + 'group' => 'Key-value store', + ); + } + + protected function setUp() { + parent::setUp(); + module_load_install('system'); + $schema = system_schema(); + db_create_table('key_value', $schema['key_value']); + $this->container + ->register('database', 'Drupal\Core\Database\Connection') + ->setFactoryClass('Drupal\Core\Database\Database') + ->setFactoryMethod('getConnection') + ->addArgument('default'); + $this->container + ->register('keyvalue.database', 'Drupal\Core\KeyValueStore\KeyValueDatabaseFactory') + ->addArgument(new Reference('database')); + global $conf; + $conf['keyvalue_default'] = 'keyvalue.database'; + } + + protected function tearDown() { + db_drop_table('key_value'); + parent::tearDown(); + } + +} diff --git a/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/GarbageCollectionTest.php b/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/GarbageCollectionTest.php deleted file mode 100644 index 82c52df..0000000 --- a/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/GarbageCollectionTest.php +++ /dev/null @@ -1,80 +0,0 @@ - 'Garbage collection', - 'description' => 'Tests garbage collection for the the expirable key-value database storage.', - 'group' => 'Key-value store', - ); - } - - protected function setUp() { - parent::setUp(); - module_load_install('system'); - $schema = system_schema(); - db_create_table('key_value_expire', $schema['key_value_expire']); - } - - protected function tearDown() { - db_drop_table('key_value_expire'); - parent::tearDown(); - } - - /** - * Tests garbage collection. - */ - public function testGarbageCollection() { - $collection = $this->randomName(); - $store = new DatabaseStorageExpirable($collection, Database::getConnection()); - - // Insert some items and confirm that they're set. - for ($i = 0; $i <= 3; $i++) { - $store->setWithExpire('key_' . $i, $this->randomObject(), rand(500, 100000)); - } - $this->assertIdentical(sizeof($store->getAll()), 4, 'Four items were written to the storage.'); - - // Manually expire the data. - for ($i = 0; $i <= 3; $i++) { - db_merge('key_value_expire') - ->key(array( - 'name' => 'key_' . $i, - 'collection' => $collection, - )) - ->fields(array( - 'expire' => REQUEST_TIME - 1, - )) - ->execute(); - } - - // Perform a new set operation and then manually destruct the object to - // trigger garbage collection. - $store->setWithExpire('autumn', 'winter', rand(500, 1000000)); - $store->destruct(); - - // Query the database and confirm that the stale records were deleted. - $result = db_query( - 'SELECT name, value FROM {key_value_expire} WHERE collection = :collection', - array( - ':collection' => $collection, - ))->fetchAll(); - $this->assertIdentical(sizeof($result), 1, 'Only one item remains after garbage collection'); - - } - -} diff --git a/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/GarbageCollectionUnitTest.php b/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/GarbageCollectionUnitTest.php new file mode 100644 index 0000000..2ea9309 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/GarbageCollectionUnitTest.php @@ -0,0 +1,80 @@ + 'Garbage collection', + 'description' => 'Tests garbage collection for the the expirable key-value database storage.', + 'group' => 'Key-value store', + ); + } + + protected function setUp() { + parent::setUp(); + module_load_install('system'); + $schema = system_schema(); + db_create_table('key_value_expire', $schema['key_value_expire']); + } + + protected function tearDown() { + db_drop_table('key_value_expire'); + parent::tearDown(); + } + + /** + * Tests garbage collection. + */ + public function testGarbageCollection() { + $collection = $this->randomName(); + $store = new DatabaseStorageExpirable($collection, Database::getConnection()); + + // Insert some items and confirm that they're set. + for ($i = 0; $i <= 3; $i++) { + $store->setWithExpire('key_' . $i, $this->randomObject(), rand(500, 100000)); + } + $this->assertIdentical(sizeof($store->getAll()), 4, 'Four items were written to the storage.'); + + // Manually expire the data. + for ($i = 0; $i <= 3; $i++) { + db_merge('key_value_expire') + ->key(array( + 'name' => 'key_' . $i, + 'collection' => $collection, + )) + ->fields(array( + 'expire' => REQUEST_TIME - 1, + )) + ->execute(); + } + + // Perform a new set operation and then manually destruct the object to + // trigger garbage collection. + $store->setWithExpire('autumn', 'winter', rand(500, 1000000)); + $store->destruct(); + + // Query the database and confirm that the stale records were deleted. + $result = db_query( + 'SELECT name, value FROM {key_value_expire} WHERE collection = :collection', + array( + ':collection' => $collection, + ))->fetchAll(); + $this->assertIdentical(sizeof($result), 1, 'Only one item remains after garbage collection'); + + } + +} diff --git a/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/MemoryStorageTest.php b/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/MemoryStorageTest.php deleted file mode 100644 index 5f1f0ba..0000000 --- a/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/MemoryStorageTest.php +++ /dev/null @@ -1,52 +0,0 @@ - 'Memory storage', - 'description' => 'Tests the key-value memory storage.', - 'group' => 'Key-value store', - ); - } - - protected function setUp() { - parent::setUp(); - $this->container - ->register('keyvalue.memory', 'Drupal\Core\KeyValueStore\KeyValueMemoryFactory'); - global $conf; - if (isset($conf['keyvalue_default'])) { - $this->originalKeyValue = $conf['keyvalue_default']; - } - $conf['keyvalue_default'] = 'keyvalue.memory'; - } - - protected function tearDown() { - global $conf; - if (isset($this->originalKeyValue)) { - $conf['keyvalue_default'] = $this->originalKeyValue; - } - else { - unset($conf['keyvalue_default']); - } - parent::tearDown(); - } - -} diff --git a/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/MemoryStorageUnitTest.php b/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/MemoryStorageUnitTest.php new file mode 100644 index 0000000..e8e8505 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/MemoryStorageUnitTest.php @@ -0,0 +1,52 @@ + 'Memory storage', + 'description' => 'Tests the key-value memory storage.', + 'group' => 'Key-value store', + ); + } + + protected function setUp() { + parent::setUp(); + $this->container + ->register('keyvalue.memory', 'Drupal\Core\KeyValueStore\KeyValueMemoryFactory'); + global $conf; + if (isset($conf['keyvalue_default'])) { + $this->originalKeyValue = $conf['keyvalue_default']; + } + $conf['keyvalue_default'] = 'keyvalue.memory'; + } + + protected function tearDown() { + global $conf; + if (isset($this->originalKeyValue)) { + $conf['keyvalue_default'] = $this->originalKeyValue; + } + else { + unset($conf['keyvalue_default']); + } + parent::tearDown(); + } + +} diff --git a/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/StorageTestBase.php b/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/StorageTestBase.php deleted file mode 100644 index 9bd2412..0000000 --- a/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/StorageTestBase.php +++ /dev/null @@ -1,217 +0,0 @@ -container = new ContainerBuilder(); - $this->container - ->register('service_container', 'Symfony\Component\DependencyInjection\ContainerBuilder') - ->setSynthetic(TRUE); - $this->container->set('service_container', $this->container); - $this->container - ->register('keyvalue', 'Drupal\Core\KeyValueStore\KeyValueFactory') - ->addArgument(new Reference('service_container')); - $this->container - ->register('keyvalue.expirable', 'Drupal\Core\KeyValueStore\KeyValueExpirableFactory') - ->addArgument(new Reference('service_container')); - // Define two data collections, - $this->collections = array(0 => 'zero', 1 => 'one'); - - // Create several objects for testing. - for ($i = 0; $i <= 5; $i++) { - $this->objects[$i] = $this->randomObject(); - } - } - - /** - * Tests CRUD operations. - */ - public function testCRUD() { - $stores = $this->createStorage(); - // Verify that each store returns its own collection name. - $this->assertIdentical($stores[0]->getCollectionName(), $this->collections[0]); - $this->assertIdentical($stores[1]->getCollectionName(), $this->collections[1]); - - // Verify that an item can be stored. - $stores[0]->set('foo', $this->objects[0]); - $this->assertIdenticalObject($this->objects[0], $stores[0]->get('foo')); - // Verify that the other collection is not affected. - $this->assertFalse($stores[1]->get('foo')); - - // Verify that an item can be updated. - $stores[0]->set('foo', $this->objects[1]); - $this->assertIdenticalObject($this->objects[1], $stores[0]->get('foo')); - // Verify that the other collection is still not affected. - $this->assertFalse($stores[1]->get('foo')); - - // Verify that a collection/name pair is unique. - $stores[1]->set('foo', $this->objects[2]); - $this->assertIdenticalObject($this->objects[1], $stores[0]->get('foo')); - $this->assertIdenticalObject($this->objects[2], $stores[1]->get('foo')); - - // Verify that an item can be deleted. - $stores[0]->delete('foo'); - $this->assertFalse($stores[0]->get('foo')); - - // Verify that the other collection is not affected. - $this->assertIdenticalObject($this->objects[2], $stores[1]->get('foo')); - $stores[1]->delete('foo'); - $this->assertFalse($stores[1]->get('foo')); - - // Verify that multiple items can be stored. - $values = array( - 'foo' => $this->objects[3], - 'bar' => $this->objects[4], - ); - $stores[0]->setMultiple($values); - - // Verify that multiple items can be retrieved. - $result = $stores[0]->getMultiple(array('foo', 'bar')); - foreach ($values as $j => $value) { - $this->assertIdenticalObject($value, $result[$j]); - } - - // Verify that the other collection was not affected. - $this->assertFalse($stores[1]->get('foo')); - $this->assertFalse($stores[1]->get('bar')); - - // Verify that all items in a collection can be retrieved. - // Ensure that an item with the same name exists in the other collection. - $stores[1]->set('foo', $this->objects[5]); - $result = $stores[0]->getAll(); - // Not using assertIdentical(), since the order is not defined for getAll(). - $this->assertEqual(count($result), count($values)); - foreach ($result as $key => $value) { - $this->assertEqual($values[$key], $value); - } - // Verify that all items in the other collection are different. - $result = $stores[1]->getAll(); - $this->assertEqual($result, array('foo' => $this->objects[5])); - - // Verify that multiple items can be deleted. - $stores[0]->deleteMultiple(array_keys($values)); - $this->assertFalse($stores[0]->get('foo')); - $this->assertFalse($stores[0]->get('bar')); - $this->assertFalse($stores[0]->getMultiple(array('foo', 'bar'))); - // Verify that the item in the other collection still exists. - $this->assertIdenticalObject($this->objects[5], $stores[1]->get('foo')); - - } - - /** - * Tests expected behavior for non-existing keys. - */ - public function testNonExistingKeys() { - - $stores = $this->createStorage(); - - // Verify that a non-existing key returns NULL as value. - $this->assertNull($stores[0]->get('foo')); - - // Verify that a FALSE value can be stored. - $stores[0]->set('foo', FALSE); - $this->assertIdentical($stores[0]->get('foo'), FALSE); - - // Verify that a deleted key returns NULL as value. - $stores[0]->delete('foo'); - $this->assertNull($stores[0]->get('foo')); - - // Verify that a non-existing key is not returned when getting multiple keys. - $stores[0]->set('bar', 'baz'); - $values = $stores[0]->getMultiple(array('foo', 'bar')); - $this->assertFalse(isset($values['foo']), "Key 'foo' not found."); - $this->assertIdentical($values['bar'], 'baz'); - } - - /** - * Tests the setIfNotExists() method. - */ - public function testSetIfNotExists() { - $stores = $this->createStorage(); - - $key = $this->randomName(); - // Test that setIfNotExists() succeeds only the first time. - for ($i = 0; $i <= 1; $i++) { - // setIfNotExists() should be TRUE the first time (when $i is 0) and - // FALSE the second time (when $i is 1). - $this->assertEqual(!$i, $stores[0]->setIfNotExists($key, $this->objects[$i])); - $this->assertIdenticalObject($this->objects[0], $stores[0]->get($key)); - // Verify that the other collection is not affected. - $this->assertFalse($stores[1]->get($key)); - } - - // Remove the item and try to set it again. - $stores[0]->delete($key); - $stores[0]->setIfNotExists($key, $this->objects[1]); - // This time it should succeed. - $this->assertIdenticalObject($this->objects[1], $stores[0]->get($key)); - // Verify that the other collection is still not affected. - $this->assertFalse($stores[1]->get($key)); - } - - /** - * Creates storage objects for each collection defined for this class. - * - * Storing the storage objects in a class member variable causes a fatal - * exception in DatabaseStorageExpirableTest, because in that situation - * garbage collection is not triggered until the test class itself is - * destructed, after tearDown() has deleted the database tables. Instead, - * create the storage objects locally in each test using this method. - * - * @see Drupal\system\Tests\KeyValueStore\DatabaseStorageExpirable - * @see Drupal\Core\KeyValueStore\DatabaseStorageExpirable::garbageCollection() - */ - protected function createStorage() { - $stores = array(); - foreach ($this->collections as $i => $collection) { - $stores[$i] = $this->container->get($this->factory)->get($collection); - } - - return $stores; - } - -} diff --git a/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/StorageUnitTestBase.php b/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/StorageUnitTestBase.php new file mode 100644 index 0000000..d7519d8 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/StorageUnitTestBase.php @@ -0,0 +1,217 @@ +container = new ContainerBuilder(); + $this->container + ->register('service_container', 'Symfony\Component\DependencyInjection\ContainerBuilder') + ->setSynthetic(TRUE); + $this->container->set('service_container', $this->container); + $this->container + ->register('keyvalue', 'Drupal\Core\KeyValueStore\KeyValueFactory') + ->addArgument(new Reference('service_container')); + $this->container + ->register('keyvalue.expirable', 'Drupal\Core\KeyValueStore\KeyValueExpirableFactory') + ->addArgument(new Reference('service_container')); + // Define two data collections, + $this->collections = array(0 => 'zero', 1 => 'one'); + + // Create several objects for testing. + for ($i = 0; $i <= 5; $i++) { + $this->objects[$i] = $this->randomObject(); + } + } + + /** + * Tests CRUD operations. + */ + public function testCRUD() { + $stores = $this->createStorage(); + // Verify that each store returns its own collection name. + $this->assertIdentical($stores[0]->getCollectionName(), $this->collections[0]); + $this->assertIdentical($stores[1]->getCollectionName(), $this->collections[1]); + + // Verify that an item can be stored. + $stores[0]->set('foo', $this->objects[0]); + $this->assertIdenticalObject($this->objects[0], $stores[0]->get('foo')); + // Verify that the other collection is not affected. + $this->assertFalse($stores[1]->get('foo')); + + // Verify that an item can be updated. + $stores[0]->set('foo', $this->objects[1]); + $this->assertIdenticalObject($this->objects[1], $stores[0]->get('foo')); + // Verify that the other collection is still not affected. + $this->assertFalse($stores[1]->get('foo')); + + // Verify that a collection/name pair is unique. + $stores[1]->set('foo', $this->objects[2]); + $this->assertIdenticalObject($this->objects[1], $stores[0]->get('foo')); + $this->assertIdenticalObject($this->objects[2], $stores[1]->get('foo')); + + // Verify that an item can be deleted. + $stores[0]->delete('foo'); + $this->assertFalse($stores[0]->get('foo')); + + // Verify that the other collection is not affected. + $this->assertIdenticalObject($this->objects[2], $stores[1]->get('foo')); + $stores[1]->delete('foo'); + $this->assertFalse($stores[1]->get('foo')); + + // Verify that multiple items can be stored. + $values = array( + 'foo' => $this->objects[3], + 'bar' => $this->objects[4], + ); + $stores[0]->setMultiple($values); + + // Verify that multiple items can be retrieved. + $result = $stores[0]->getMultiple(array('foo', 'bar')); + foreach ($values as $j => $value) { + $this->assertIdenticalObject($value, $result[$j]); + } + + // Verify that the other collection was not affected. + $this->assertFalse($stores[1]->get('foo')); + $this->assertFalse($stores[1]->get('bar')); + + // Verify that all items in a collection can be retrieved. + // Ensure that an item with the same name exists in the other collection. + $stores[1]->set('foo', $this->objects[5]); + $result = $stores[0]->getAll(); + // Not using assertIdentical(), since the order is not defined for getAll(). + $this->assertEqual(count($result), count($values)); + foreach ($result as $key => $value) { + $this->assertEqual($values[$key], $value); + } + // Verify that all items in the other collection are different. + $result = $stores[1]->getAll(); + $this->assertEqual($result, array('foo' => $this->objects[5])); + + // Verify that multiple items can be deleted. + $stores[0]->deleteMultiple(array_keys($values)); + $this->assertFalse($stores[0]->get('foo')); + $this->assertFalse($stores[0]->get('bar')); + $this->assertFalse($stores[0]->getMultiple(array('foo', 'bar'))); + // Verify that the item in the other collection still exists. + $this->assertIdenticalObject($this->objects[5], $stores[1]->get('foo')); + + } + + /** + * Tests expected behavior for non-existing keys. + */ + public function testNonExistingKeys() { + + $stores = $this->createStorage(); + + // Verify that a non-existing key returns NULL as value. + $this->assertNull($stores[0]->get('foo')); + + // Verify that a FALSE value can be stored. + $stores[0]->set('foo', FALSE); + $this->assertIdentical($stores[0]->get('foo'), FALSE); + + // Verify that a deleted key returns NULL as value. + $stores[0]->delete('foo'); + $this->assertNull($stores[0]->get('foo')); + + // Verify that a non-existing key is not returned when getting multiple keys. + $stores[0]->set('bar', 'baz'); + $values = $stores[0]->getMultiple(array('foo', 'bar')); + $this->assertFalse(isset($values['foo']), "Key 'foo' not found."); + $this->assertIdentical($values['bar'], 'baz'); + } + + /** + * Tests the setIfNotExists() method. + */ + public function testSetIfNotExists() { + $stores = $this->createStorage(); + + $key = $this->randomName(); + // Test that setIfNotExists() succeeds only the first time. + for ($i = 0; $i <= 1; $i++) { + // setIfNotExists() should be TRUE the first time (when $i is 0) and + // FALSE the second time (when $i is 1). + $this->assertEqual(!$i, $stores[0]->setIfNotExists($key, $this->objects[$i])); + $this->assertIdenticalObject($this->objects[0], $stores[0]->get($key)); + // Verify that the other collection is not affected. + $this->assertFalse($stores[1]->get($key)); + } + + // Remove the item and try to set it again. + $stores[0]->delete($key); + $stores[0]->setIfNotExists($key, $this->objects[1]); + // This time it should succeed. + $this->assertIdenticalObject($this->objects[1], $stores[0]->get($key)); + // Verify that the other collection is still not affected. + $this->assertFalse($stores[1]->get($key)); + } + + /** + * Creates storage objects for each collection defined for this class. + * + * Storing the storage objects in a class member variable causes a fatal + * exception in DatabaseStorageExpirableTest, because in that situation + * garbage collection is not triggered until the test class itself is + * destructed, after tearDown() has deleted the database tables. Instead, + * create the storage objects locally in each test using this method. + * + * @see Drupal\system\Tests\KeyValueStore\DatabaseStorageExpirable + * @see Drupal\Core\KeyValueStore\DatabaseStorageExpirable::garbageCollection() + */ + protected function createStorage() { + $stores = array(); + foreach ($this->collections as $i => $collection) { + $stores[$i] = $this->container->get($this->factory)->get($collection); + } + + return $stores; + } + +} diff --git a/core/modules/system/lib/Drupal/system/Tests/Module/ModuleEnable.php b/core/modules/system/lib/Drupal/system/Tests/Module/ModuleEnable.php deleted file mode 100644 index b2d08fc..0000000 --- a/core/modules/system/lib/Drupal/system/Tests/Module/ModuleEnable.php +++ /dev/null @@ -1,47 +0,0 @@ - 'Module enable', - 'description' => 'Tests module_enable().', - 'group' => 'Module', - ); - } - - /** - * Tests enabling User module once more. - * - * Regression: The installer might enable a module twice due to automatic - * dependency resolution. A bug caused the stored weight for User module to - * be an array. - */ - function testEnableUserTwice() { - module_enable(array('user'), FALSE); - $this->assertIdentical(config('system.module')->get('enabled.user'), '0'); - } - - /** - * Tests recorded schema versions of early installed modules in the installer. - */ - function testRequiredModuleSchemaVersions() { - $version = drupal_get_installed_schema_version('system', TRUE); - $this->assertTrue($version > 0, 'System module version is > 0.'); - $version = drupal_get_installed_schema_version('user', TRUE); - $this->assertTrue($version > 0, 'User module version is > 0.'); - } - -} diff --git a/core/modules/system/lib/Drupal/system/Tests/Module/ModuleEnableTest.php b/core/modules/system/lib/Drupal/system/Tests/Module/ModuleEnableTest.php new file mode 100644 index 0000000..6d6192d --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Module/ModuleEnableTest.php @@ -0,0 +1,47 @@ + 'Module enable', + 'description' => 'Tests module_enable().', + 'group' => 'Module', + ); + } + + /** + * Tests enabling User module once more. + * + * Regression: The installer might enable a module twice due to automatic + * dependency resolution. A bug caused the stored weight for User module to + * be an array. + */ + function testEnableUserTwice() { + module_enable(array('user'), FALSE); + $this->assertIdentical(config('system.module')->get('enabled.user'), '0'); + } + + /** + * Tests recorded schema versions of early installed modules in the installer. + */ + function testRequiredModuleSchemaVersions() { + $version = drupal_get_installed_schema_version('system', TRUE); + $this->assertTrue($version > 0, 'System module version is > 0.'); + $version = drupal_get_installed_schema_version('user', TRUE); + $this->assertTrue($version > 0, 'User module version is > 0.'); + } + +} diff --git a/core/modules/system/lib/Drupal/system/Tests/Routing/ControllerResolverTest.php b/core/modules/system/lib/Drupal/system/Tests/Routing/ControllerResolverTest.php deleted file mode 100644 index 46ed2a3..0000000 --- a/core/modules/system/lib/Drupal/system/Tests/Routing/ControllerResolverTest.php +++ /dev/null @@ -1,43 +0,0 @@ - 'Controller Resolver tests', - 'description' => 'Tests that the Drupal-extended ControllerResolver is functioning properly.', - 'group' => 'Routing', - ); - } - - /** - * Confirms that a container aware controller gets returned. - */ - function testContainerAware() { - $container = new Container(); - $resolver = new ControllerResolver($container); - - $request = Request::create('/some/path'); - $request->attributes->set('_controller', '\Drupal\system\Tests\Routing\MockController::run'); - - $controller = $resolver->getController($request); - - $this->assertTrue($controller[0] instanceof MockController, 'The correct controller object was returned.'); - } -} diff --git a/core/modules/system/lib/Drupal/system/Tests/Routing/ControllerResolverUnitTest.php b/core/modules/system/lib/Drupal/system/Tests/Routing/ControllerResolverUnitTest.php new file mode 100644 index 0000000..7477e6e --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Routing/ControllerResolverUnitTest.php @@ -0,0 +1,43 @@ + 'Controller Resolver tests', + 'description' => 'Tests that the Drupal-extended ControllerResolver is functioning properly.', + 'group' => 'Routing', + ); + } + + /** + * Confirms that a container aware controller gets returned. + */ + function testContainerAware() { + $container = new Container(); + $resolver = new ControllerResolver($container); + + $request = Request::create('/some/path'); + $request->attributes->set('_controller', '\Drupal\system\Tests\Routing\MockController::run'); + + $controller = $resolver->getController($request); + + $this->assertTrue($controller[0] instanceof MockController, 'The correct controller object was returned.'); + } +} diff --git a/core/modules/system/lib/Drupal/system/Tests/Routing/MatcherDumperTest.php b/core/modules/system/lib/Drupal/system/Tests/Routing/MatcherDumperTest.php deleted file mode 100644 index 7f6f312..0000000 --- a/core/modules/system/lib/Drupal/system/Tests/Routing/MatcherDumperTest.php +++ /dev/null @@ -1,144 +0,0 @@ - 'Dumper tests', - 'description' => 'Confirm that the matcher dumper is functioning properly.', - 'group' => 'Routing', - ); - } - - function __construct($test_id = NULL) { - parent::__construct($test_id); - - $this->fixtures = new RoutingFixtures(); - } - - function setUp() { - parent::setUp(); - } - - /** - * Confirms that the dumper can be instantiated successfuly. - */ - function testCreate() { - $connection = Database::getConnection(); - $dumper= new MatcherDumper($connection); - - $class_name = 'Drupal\Core\Routing\MatcherDumper'; - $this->assertTrue($dumper instanceof $class_name, 'Dumper created successfully'); - } - - /** - * Confirms that we can add routes to the dumper. - */ - function testAddRoutes() { - $connection = Database::getConnection(); - $dumper= new MatcherDumper($connection); - - $route = new Route('test'); - $collection = new RouteCollection(); - $collection->add('test_route', $route); - - $dumper->addRoutes($collection); - - $dumper_routes = $dumper->getRoutes()->all(); - $collection_routes = $collection->all(); - - foreach ($dumper_routes as $name => $route) { - $this->assertEqual($route->getPattern(), $collection_routes[$name]->getPattern(), 'Routes match'); - } - } - - /** - * Confirms that we can add routes to the dumper when it already has some. - */ - function testAddAdditionalRoutes() { - $connection = Database::getConnection(); - $dumper= new MatcherDumper($connection); - - $route = new Route('test'); - $collection = new RouteCollection(); - $collection->add('test_route', $route); - $dumper->addRoutes($collection); - - $route = new Route('test2'); - $collection2 = new RouteCollection(); - $collection2->add('test_route2', $route); - $dumper->addRoutes($collection2); - - // Merge the two collections together so we can test them. - $collection->addCollection(clone $collection2); - - $dumper_routes = $dumper->getRoutes()->all(); - $collection_routes = $collection->all(); - - $success = TRUE; - foreach ($collection_routes as $name => $route) { - if (empty($dumper_routes[$name])) { - $success = FALSE; - $this->fail(t('Not all routes found in the dumper.')); - } - } - - if ($success) { - $this->pass('All routes found in the dumper.'); - } - } - - /** - * Confirm that we can dump a route collection to the database. - */ - public function testDump() { - $connection = Database::getConnection(); - $dumper= new MatcherDumper($connection, 'test_routes'); - - $route = new Route('/test/{my}/path'); - $route->setOption('compiler_class', 'Drupal\Core\Routing\RouteCompiler'); - $collection = new RouteCollection(); - $collection->add('test_route', $route); - - $dumper->addRoutes($collection); - - $this->fixtures->createTables($connection); - - $dumper->dump(array('route_set' => 'test')); - - $record = $connection->query("SELECT * FROM {test_routes} WHERE name= :name", array(':name' => 'test_route'))->fetchObject(); - - $loaded_route = unserialize($record->route); - - $this->assertEqual($record->name, 'test_route', 'Dumped route has correct name.'); - $this->assertEqual($record->pattern, '/test/{my}/path', 'Dumped route has correct pattern.'); - $this->assertEqual($record->pattern_outline, '/test/%/path', 'Dumped route has correct pattern outline.'); - $this->assertEqual($record->fit, 5 /* 101 in binary */, 'Dumped route has correct fit.'); - $this->assertTrue($loaded_route instanceof Route, 'Route object retrieved successfully.'); - - } -} diff --git a/core/modules/system/lib/Drupal/system/Tests/Routing/MatcherDumperUnitTest.php b/core/modules/system/lib/Drupal/system/Tests/Routing/MatcherDumperUnitTest.php new file mode 100644 index 0000000..113d4a0 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Routing/MatcherDumperUnitTest.php @@ -0,0 +1,144 @@ + 'Dumper tests', + 'description' => 'Confirm that the matcher dumper is functioning properly.', + 'group' => 'Routing', + ); + } + + function __construct($test_id = NULL) { + parent::__construct($test_id); + + $this->fixtures = new RoutingFixtures(); + } + + function setUp() { + parent::setUp(); + } + + /** + * Confirms that the dumper can be instantiated successfuly. + */ + function testCreate() { + $connection = Database::getConnection(); + $dumper= new MatcherDumper($connection); + + $class_name = 'Drupal\Core\Routing\MatcherDumper'; + $this->assertTrue($dumper instanceof $class_name, 'Dumper created successfully'); + } + + /** + * Confirms that we can add routes to the dumper. + */ + function testAddRoutes() { + $connection = Database::getConnection(); + $dumper= new MatcherDumper($connection); + + $route = new Route('test'); + $collection = new RouteCollection(); + $collection->add('test_route', $route); + + $dumper->addRoutes($collection); + + $dumper_routes = $dumper->getRoutes()->all(); + $collection_routes = $collection->all(); + + foreach ($dumper_routes as $name => $route) { + $this->assertEqual($route->getPattern(), $collection_routes[$name]->getPattern(), 'Routes match'); + } + } + + /** + * Confirms that we can add routes to the dumper when it already has some. + */ + function testAddAdditionalRoutes() { + $connection = Database::getConnection(); + $dumper= new MatcherDumper($connection); + + $route = new Route('test'); + $collection = new RouteCollection(); + $collection->add('test_route', $route); + $dumper->addRoutes($collection); + + $route = new Route('test2'); + $collection2 = new RouteCollection(); + $collection2->add('test_route2', $route); + $dumper->addRoutes($collection2); + + // Merge the two collections together so we can test them. + $collection->addCollection(clone $collection2); + + $dumper_routes = $dumper->getRoutes()->all(); + $collection_routes = $collection->all(); + + $success = TRUE; + foreach ($collection_routes as $name => $route) { + if (empty($dumper_routes[$name])) { + $success = FALSE; + $this->fail(t('Not all routes found in the dumper.')); + } + } + + if ($success) { + $this->pass('All routes found in the dumper.'); + } + } + + /** + * Confirm that we can dump a route collection to the database. + */ + public function testDump() { + $connection = Database::getConnection(); + $dumper= new MatcherDumper($connection, 'test_routes'); + + $route = new Route('/test/{my}/path'); + $route->setOption('compiler_class', 'Drupal\Core\Routing\RouteCompiler'); + $collection = new RouteCollection(); + $collection->add('test_route', $route); + + $dumper->addRoutes($collection); + + $this->fixtures->createTables($connection); + + $dumper->dump(array('route_set' => 'test')); + + $record = $connection->query("SELECT * FROM {test_routes} WHERE name= :name", array(':name' => 'test_route'))->fetchObject(); + + $loaded_route = unserialize($record->route); + + $this->assertEqual($record->name, 'test_route', 'Dumped route has correct name.'); + $this->assertEqual($record->pattern, '/test/{my}/path', 'Dumped route has correct pattern.'); + $this->assertEqual($record->pattern_outline, '/test/%/path', 'Dumped route has correct pattern outline.'); + $this->assertEqual($record->fit, 5 /* 101 in binary */, 'Dumped route has correct fit.'); + $this->assertTrue($loaded_route instanceof Route, 'Route object retrieved successfully.'); + + } +} diff --git a/core/modules/system/lib/Drupal/system/Tests/Routing/RouteTest.php b/core/modules/system/lib/Drupal/system/Tests/Routing/RouteTest.php deleted file mode 100644 index 6e808e7..0000000 --- a/core/modules/system/lib/Drupal/system/Tests/Routing/RouteTest.php +++ /dev/null @@ -1,60 +0,0 @@ - 'Routes', - 'description' => 'Confirm that route object is functioning properly.', - 'group' => 'Routing', - ); - } - - function setUp() { - parent::setUp(); - } - - /** - * Confirms that a route compiles properly with the necessary data. - */ - public function testCompilation() { - $route = new Route('/test/{something}/more'); - $route->setOption('compiler_class', 'Drupal\Core\Routing\RouteCompiler'); - $compiled = $route->compile(); - - $this->assertEqual($route, $compiled->getRoute(), 'Compiled route has the correct route object.'); - $this->assertEqual($compiled->getFit(), 5 /* That's 101 binary*/, 'The fit was correct.'); - $this->assertEqual($compiled->getPatternOutline(), '/test/%/more', 'The pattern outline was correct.'); - } - - /** - * Confirms that a compiled route with default values has the correct outline. - */ - public function testCompilationDefaultValue() { - // Because "here" has a default value, it should not factor into the outline - // or the fitness. - $route = new Route('/test/{something}/more/{here}', array( - 'here' => 'there', - )); - $route->setOption('compiler_class', 'Drupal\Core\Routing\RouteCompiler'); - $compiled = $route->compile(); - - $this->assertEqual($route, $compiled->getRoute(), 'Compiled route has the correct route object.'); - $this->assertEqual($compiled->getFit(), 5 /* That's 101 binary*/, 'The fit was correct.'); - $this->assertEqual($compiled->getPatternOutline(), '/test/%/more', 'The pattern outline was correct.'); - } - -} diff --git a/core/modules/system/lib/Drupal/system/Tests/Routing/RouteUnitTest.php b/core/modules/system/lib/Drupal/system/Tests/Routing/RouteUnitTest.php new file mode 100644 index 0000000..0538473 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Routing/RouteUnitTest.php @@ -0,0 +1,60 @@ + 'Routes', + 'description' => 'Confirm that route object is functioning properly.', + 'group' => 'Routing', + ); + } + + function setUp() { + parent::setUp(); + } + + /** + * Confirms that a route compiles properly with the necessary data. + */ + public function testCompilation() { + $route = new Route('/test/{something}/more'); + $route->setOption('compiler_class', 'Drupal\Core\Routing\RouteCompiler'); + $compiled = $route->compile(); + + $this->assertEqual($route, $compiled->getRoute(), 'Compiled route has the correct route object.'); + $this->assertEqual($compiled->getFit(), 5 /* That's 101 binary*/, 'The fit was correct.'); + $this->assertEqual($compiled->getPatternOutline(), '/test/%/more', 'The pattern outline was correct.'); + } + + /** + * Confirms that a compiled route with default values has the correct outline. + */ + public function testCompilationDefaultValue() { + // Because "here" has a default value, it should not factor into the outline + // or the fitness. + $route = new Route('/test/{something}/more/{here}', array( + 'here' => 'there', + )); + $route->setOption('compiler_class', 'Drupal\Core\Routing\RouteCompiler'); + $compiled = $route->compile(); + + $this->assertEqual($route, $compiled->getRoute(), 'Compiled route has the correct route object.'); + $this->assertEqual($compiled->getFit(), 5 /* That's 101 binary*/, 'The fit was correct.'); + $this->assertEqual($compiled->getPatternOutline(), '/test/%/more', 'The pattern outline was correct.'); + } + +} diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/RelationshipRepresentativeNode.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/RelationshipRepresentativeNode.php deleted file mode 100644 index dbe4b3e..0000000 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/RelationshipRepresentativeNode.php +++ /dev/null @@ -1,49 +0,0 @@ - 'Taxonomy: Representative Node Relationship', - 'description' => 'Tests the representative node relationship for terms.', - 'group' => 'Views module integration', - ); - } - - /** - * Tests the relationship. - */ - public function testRelationship() { - $view = views_get_view('test_groupwise_term'); - $this->executeView($view); - $map = array('node_taxonomy_term_data_nid' => 'nid', 'tid' => 'tid'); - $expected_result = array( - array( - 'nid' => $this->nodes[1]->nid, - 'tid' => $this->term2->tid, - ), - array( - 'nid' => $this->nodes[1]->nid, - 'tid' => $this->term1->tid, - ), - ); - $this->assertIdenticalResultset($view, $expected_result, $map); - } -} diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/RelationshipRepresentativeNodeTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/RelationshipRepresentativeNodeTest.php new file mode 100644 index 0000000..3f8f9d5 --- /dev/null +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/RelationshipRepresentativeNodeTest.php @@ -0,0 +1,50 @@ + 'Taxonomy: Representative Node Relationship', + 'description' => 'Tests the representative node relationship for terms.', + 'group' => 'Views module integration', + ); + } + + /** + * Tests the relationship. + */ + public function testRelationship() { + $view = views_get_view('test_groupwise_term'); + $this->executeView($view); + $map = array('node_taxonomy_term_data_nid' => 'nid', 'tid' => 'tid'); + $expected_result = array( + array( + 'nid' => $this->nodes[1]->nid, + 'tid' => $this->term2->tid, + ), + array( + 'nid' => $this->nodes[1]->nid, + 'tid' => $this->term1->tid, + ), + ); + $this->assertIdenticalResultset($view, $expected_result, $map); + } +} diff --git a/core/modules/user/lib/Drupal/user/Tests/TempStoreDatabaseTest.php b/core/modules/user/lib/Drupal/user/Tests/TempStoreDatabaseTest.php deleted file mode 100644 index 5fb54e3..0000000 --- a/core/modules/user/lib/Drupal/user/Tests/TempStoreDatabaseTest.php +++ /dev/null @@ -1,148 +0,0 @@ - 'TempStore', - 'description' => 'Tests the temporary object storage system.', - 'group' => 'TempStore', - ); - } - - protected function setUp() { - parent::setUp(); - - // Install system tables to test the key/value storage without installing a - // full Drupal environment. - module_load_install('system'); - $schema = system_schema(); - db_create_table('semaphore', $schema['semaphore']); - db_create_table('key_value_expire', $schema['key_value_expire']); - - // Create several objects for testing. - for ($i = 0; $i <= 3; $i++) { - $this->objects[$i] = $this->randomObject(); - } - - } - - protected function tearDown() { - db_drop_table('key_value_expire'); - db_drop_table('semaphore'); - parent::tearDown(); - } - - /** - * Tests the UserTempStore API. - */ - public function testUserTempStore() { - // Create a key/value collection. - $factory = new TempStoreFactory(Database::getConnection(), new DatabaseLockBackend()); - $collection = $this->randomName(); - - // Create two mock users. - for ($i = 0; $i <= 1; $i++) { - $users[$i] = mt_rand(500, 5000000); - - // Storing the TempStore objects in a class member variable causes a - // fatal exception, because in that situation garbage collection is not - // triggered until the test class itself is destructed, after tearDown() - // has deleted the database tables. Store the objects locally instead. - $stores[$i] = $factory->get($collection, $users[$i]); - } - - $key = $this->randomName(); - // Test that setIfNotExists() succeeds only the first time. - for ($i = 0; $i <= 1; $i++) { - // setIfNotExists() should be TRUE the first time (when $i is 0) and - // FALSE the second time (when $i is 1). - $this->assertEqual(!$i, $stores[0]->setIfNotExists($key, $this->objects[$i])); - $metadata = $stores[0]->getMetadata($key); - $this->assertEqual($users[0], $metadata->owner); - $this->assertIdenticalObject($this->objects[0], $stores[0]->get($key)); - // Another user should get the same result. - $metadata = $stores[1]->getMetadata($key); - $this->assertEqual($users[0], $metadata->owner); - $this->assertIdenticalObject($this->objects[0], $stores[1]->get($key)); - } - - // Remove the item and try to set it again. - $stores[0]->delete($key); - $stores[0]->setIfNotExists($key, $this->objects[1]); - // This time it should succeed. - $this->assertIdenticalObject($this->objects[1], $stores[0]->get($key)); - - // This user can update the object. - $stores[0]->set($key, $this->objects[2]); - $this->assertIdenticalObject($this->objects[2], $stores[0]->get($key)); - // The object is the same when another user loads it. - $this->assertIdenticalObject($this->objects[2], $stores[1]->get($key)); - // Another user can update the object and become the owner. - $stores[1]->set($key, $this->objects[3]); - $this->assertIdenticalObject($this->objects[3], $stores[0]->get($key)); - $this->assertIdenticalObject($this->objects[3], $stores[1]->get($key)); - $metadata = $stores[1]->getMetadata($key); - $this->assertEqual($users[1], $metadata->owner); - - // The first user should be informed that the second now owns the data. - $metadata = $stores[0]->getMetadata($key); - $this->assertEqual($users[1], $metadata->owner); - - // Now manually expire the item (this is not exposed by the API) and then - // assert it is no longer accessible. - db_update('key_value_expire') - ->fields(array('expire' => REQUEST_TIME - 1)) - ->condition('collection', $collection) - ->condition('name', $key) - ->execute(); - $this->assertFalse($stores[0]->get($key)); - $this->assertFalse($stores[1]->get($key)); - } - -} diff --git a/core/modules/user/lib/Drupal/user/Tests/TempStoreDatabaseUnitTest.php b/core/modules/user/lib/Drupal/user/Tests/TempStoreDatabaseUnitTest.php new file mode 100644 index 0000000..a635d62 --- /dev/null +++ b/core/modules/user/lib/Drupal/user/Tests/TempStoreDatabaseUnitTest.php @@ -0,0 +1,148 @@ + 'TempStore', + 'description' => 'Tests the temporary object storage system.', + 'group' => 'TempStore', + ); + } + + protected function setUp() { + parent::setUp(); + + // Install system tables to test the key/value storage without installing a + // full Drupal environment. + module_load_install('system'); + $schema = system_schema(); + db_create_table('semaphore', $schema['semaphore']); + db_create_table('key_value_expire', $schema['key_value_expire']); + + // Create several objects for testing. + for ($i = 0; $i <= 3; $i++) { + $this->objects[$i] = $this->randomObject(); + } + + } + + protected function tearDown() { + db_drop_table('key_value_expire'); + db_drop_table('semaphore'); + parent::tearDown(); + } + + /** + * Tests the UserTempStore API. + */ + public function testUserTempStore() { + // Create a key/value collection. + $factory = new TempStoreFactory(Database::getConnection(), new DatabaseLockBackend()); + $collection = $this->randomName(); + + // Create two mock users. + for ($i = 0; $i <= 1; $i++) { + $users[$i] = mt_rand(500, 5000000); + + // Storing the TempStore objects in a class member variable causes a + // fatal exception, because in that situation garbage collection is not + // triggered until the test class itself is destructed, after tearDown() + // has deleted the database tables. Store the objects locally instead. + $stores[$i] = $factory->get($collection, $users[$i]); + } + + $key = $this->randomName(); + // Test that setIfNotExists() succeeds only the first time. + for ($i = 0; $i <= 1; $i++) { + // setIfNotExists() should be TRUE the first time (when $i is 0) and + // FALSE the second time (when $i is 1). + $this->assertEqual(!$i, $stores[0]->setIfNotExists($key, $this->objects[$i])); + $metadata = $stores[0]->getMetadata($key); + $this->assertEqual($users[0], $metadata->owner); + $this->assertIdenticalObject($this->objects[0], $stores[0]->get($key)); + // Another user should get the same result. + $metadata = $stores[1]->getMetadata($key); + $this->assertEqual($users[0], $metadata->owner); + $this->assertIdenticalObject($this->objects[0], $stores[1]->get($key)); + } + + // Remove the item and try to set it again. + $stores[0]->delete($key); + $stores[0]->setIfNotExists($key, $this->objects[1]); + // This time it should succeed. + $this->assertIdenticalObject($this->objects[1], $stores[0]->get($key)); + + // This user can update the object. + $stores[0]->set($key, $this->objects[2]); + $this->assertIdenticalObject($this->objects[2], $stores[0]->get($key)); + // The object is the same when another user loads it. + $this->assertIdenticalObject($this->objects[2], $stores[1]->get($key)); + // Another user can update the object and become the owner. + $stores[1]->set($key, $this->objects[3]); + $this->assertIdenticalObject($this->objects[3], $stores[0]->get($key)); + $this->assertIdenticalObject($this->objects[3], $stores[1]->get($key)); + $metadata = $stores[1]->getMetadata($key); + $this->assertEqual($users[1], $metadata->owner); + + // The first user should be informed that the second now owns the data. + $metadata = $stores[0]->getMetadata($key); + $this->assertEqual($users[1], $metadata->owner); + + // Now manually expire the item (this is not exposed by the API) and then + // assert it is no longer accessible. + db_update('key_value_expire') + ->fields(array('expire' => REQUEST_TIME - 1)) + ->condition('collection', $collection) + ->condition('name', $key) + ->execute(); + $this->assertFalse($stores[0]->get($key)); + $this->assertFalse($stores[1]->get($key)); + } + +} diff --git a/core/modules/user/lib/Drupal/user/Tests/UserAccountLinksTest.php b/core/modules/user/lib/Drupal/user/Tests/UserAccountLinksTest.php new file mode 100644 index 0000000..266a722 --- /dev/null +++ b/core/modules/user/lib/Drupal/user/Tests/UserAccountLinksTest.php @@ -0,0 +1,130 @@ + 'User account links', + 'description' => 'Test user-account links.', + 'group' => 'User' + ); + } + + /** + * Tests the secondary menu. + */ + function testSecondaryMenu() { + // Create a regular user. + $user = $this->drupalCreateUser(array()); + + // Log in and get the homepage. + $this->drupalLogin($user); + $this->drupalGet(''); + + // For a logged-in user, expect the secondary menu to have links for "My + // account" and "Log out". + $link = $this->xpath('//ul[@id=:menu_id]/li/a[contains(@href, :href) and text()=:text]', array( + ':menu_id' => 'secondary-menu', + ':href' => 'user', + ':text' => 'My account', + )); + $this->assertEqual(count($link), 1, 'My account link is in secondary menu.'); + + $link = $this->xpath('//ul[@id=:menu_id]/li/a[contains(@href, :href) and text()=:text]', array( + ':menu_id' => 'secondary-menu', + ':href' => 'user/logout', + ':text' => 'Log out', + )); + $this->assertEqual(count($link), 1, 'Log out link is in secondary menu.'); + + // Log out and get the homepage. + $this->drupalLogout(); + $this->drupalGet(''); + + // For a logged-out user, expect no secondary links. + $element = $this->xpath('//ul[@id=:menu_id]', array(':menu_id' => 'secondary-menu')); + $this->assertEqual(count($element), 0, 'No secondary-menu for logged-out users.'); + } + + /** + * Tests disabling the 'My account' link. + */ + function testDisabledAccountLink() { + // Create an admin user and log in. + $this->drupalLogin($this->drupalCreateUser(array('access administration pages', 'administer menu'))); + + // Verify that the 'My account' link is enabled. + $this->drupalGet('admin/structure/menu/manage/account'); + $this->assertFieldChecked('edit-links-mlid2-hidden', "The 'My account' link is enabled by default."); + + // Disable the 'My account' link. + $edit = array( + 'links[mlid:2][hidden]' => FALSE, + ); + $this->drupalPost('admin/structure/menu/manage/account', $edit, t('Save')); + + // Get the homepage. + $this->drupalGet(''); + + // Verify that the 'My account' link does not appear when disabled. + $link = $this->xpath('//ul[@id=:menu_id]/li/a[contains(@href, :href) and text()=:text]', array( + ':menu_id' => 'secondary-menu', + ':href' => 'user', + ':text' => 'My account', + )); + $this->assertEqual(count($link), 0, 'My account link is not in the secondary menu.'); + } + + /** + * Tests page title is set correctly on user account tabs. + */ + function testAccountPageTitles() { + // Default page titles are suffixed with the site name - Drupal. + $title_suffix = ' | Drupal'; + + $this->drupalGet('user'); + $this->assertTitle('Log in' . $title_suffix, "Page title of /user is 'Log in'"); + + $this->drupalGet('user/login'); + $this->assertTitle('Log in' . $title_suffix, "Page title of /user/login is 'Log in'"); + + $this->drupalGet('user/register'); + $this->assertTitle('Create new account' . $title_suffix, "Page title of /user/register is 'Create new account' for anonymous users."); + + $this->drupalGet('user/password'); + $this->assertTitle('Request new password' . $title_suffix, "Page title of /user/register is 'Request new password' for anonymous users."); + + // Tests the default fallback title. + $this->drupalGet('user/password/' . $this->randomName()); + $this->assertTitle('User account' . $title_suffix, "Fallback page title for user pages is 'User account' for anonymous users."); + + // Check the page title for registered users is "My Account" in menus. + $this->drupalLogin($this->drupalCreateUser()); + // After login, the client is redirected to /user. + $link = $this->xpath('//a[contains(@class, :class)]', array( + ':class' => 'active-trail', + ) + ); + $this->assertEqual((string) $link[0], 'My account', "Page title of /user is 'My Account' in menus for registered users"); + } + +} diff --git a/core/modules/user/lib/Drupal/user/Tests/UserAccountLinksTests.php b/core/modules/user/lib/Drupal/user/Tests/UserAccountLinksTests.php deleted file mode 100644 index 6780cf7..0000000 --- a/core/modules/user/lib/Drupal/user/Tests/UserAccountLinksTests.php +++ /dev/null @@ -1,130 +0,0 @@ - 'User account links', - 'description' => 'Test user-account links.', - 'group' => 'User' - ); - } - - /** - * Tests the secondary menu. - */ - function testSecondaryMenu() { - // Create a regular user. - $user = $this->drupalCreateUser(array()); - - // Log in and get the homepage. - $this->drupalLogin($user); - $this->drupalGet(''); - - // For a logged-in user, expect the secondary menu to have links for "My - // account" and "Log out". - $link = $this->xpath('//ul[@id=:menu_id]/li/a[contains(@href, :href) and text()=:text]', array( - ':menu_id' => 'secondary-menu', - ':href' => 'user', - ':text' => 'My account', - )); - $this->assertEqual(count($link), 1, 'My account link is in secondary menu.'); - - $link = $this->xpath('//ul[@id=:menu_id]/li/a[contains(@href, :href) and text()=:text]', array( - ':menu_id' => 'secondary-menu', - ':href' => 'user/logout', - ':text' => 'Log out', - )); - $this->assertEqual(count($link), 1, 'Log out link is in secondary menu.'); - - // Log out and get the homepage. - $this->drupalLogout(); - $this->drupalGet(''); - - // For a logged-out user, expect no secondary links. - $element = $this->xpath('//ul[@id=:menu_id]', array(':menu_id' => 'secondary-menu')); - $this->assertEqual(count($element), 0, 'No secondary-menu for logged-out users.'); - } - - /** - * Tests disabling the 'My account' link. - */ - function testDisabledAccountLink() { - // Create an admin user and log in. - $this->drupalLogin($this->drupalCreateUser(array('access administration pages', 'administer menu'))); - - // Verify that the 'My account' link is enabled. - $this->drupalGet('admin/structure/menu/manage/account'); - $this->assertFieldChecked('edit-links-mlid2-hidden', "The 'My account' link is enabled by default."); - - // Disable the 'My account' link. - $edit = array( - 'links[mlid:2][hidden]' => FALSE, - ); - $this->drupalPost('admin/structure/menu/manage/account', $edit, t('Save')); - - // Get the homepage. - $this->drupalGet(''); - - // Verify that the 'My account' link does not appear when disabled. - $link = $this->xpath('//ul[@id=:menu_id]/li/a[contains(@href, :href) and text()=:text]', array( - ':menu_id' => 'secondary-menu', - ':href' => 'user', - ':text' => 'My account', - )); - $this->assertEqual(count($link), 0, 'My account link is not in the secondary menu.'); - } - - /** - * Tests page title is set correctly on user account tabs. - */ - function testAccountPageTitles() { - // Default page titles are suffixed with the site name - Drupal. - $title_suffix = ' | Drupal'; - - $this->drupalGet('user'); - $this->assertTitle('Log in' . $title_suffix, "Page title of /user is 'Log in'"); - - $this->drupalGet('user/login'); - $this->assertTitle('Log in' . $title_suffix, "Page title of /user/login is 'Log in'"); - - $this->drupalGet('user/register'); - $this->assertTitle('Create new account' . $title_suffix, "Page title of /user/register is 'Create new account' for anonymous users."); - - $this->drupalGet('user/password'); - $this->assertTitle('Request new password' . $title_suffix, "Page title of /user/register is 'Request new password' for anonymous users."); - - // Tests the default fallback title. - $this->drupalGet('user/password/' . $this->randomName()); - $this->assertTitle('User account' . $title_suffix, "Fallback page title for user pages is 'User account' for anonymous users."); - - // Check the page title for registered users is "My Account" in menus. - $this->drupalLogin($this->drupalCreateUser()); - // After login, the client is redirected to /user. - $link = $this->xpath('//a[contains(@class, :class)]', array( - ':class' => 'active-trail', - ) - ); - $this->assertEqual((string) $link[0], 'My account', "Page title of /user is 'My Account' in menus for registered users"); - } - -} diff --git a/core/modules/user/lib/Drupal/user/Tests/UserBlocksTest.php b/core/modules/user/lib/Drupal/user/Tests/UserBlocksTest.php new file mode 100644 index 0000000..7870af0 --- /dev/null +++ b/core/modules/user/lib/Drupal/user/Tests/UserBlocksTest.php @@ -0,0 +1,120 @@ + 'User blocks', + 'description' => 'Test user blocks.', + 'group' => 'User', + ); + } + + function setUp() { + parent::setUp(); + + $this->adminUser = $this->drupalCreateUser(array('administer blocks')); + $this->drupalLogin($this->adminUser); + $this->drupalPlaceBlock('user_login_block'); + $this->drupalLogout($this->adminUser); + } + + /** + * Test the user login block. + */ + function testUserLoginBlock() { + // Create a user with some permission that anonymous users lack. + $user = $this->drupalCreateUser(array('administer permissions')); + + // Log in using the block. + $edit = array(); + $edit['name'] = $user->name; + $edit['pass'] = $user->pass_raw; + $this->drupalPost('admin/people/permissions', $edit, t('Log in')); + $this->assertNoText(t('User login'), 'Logged in.'); + + // Check that we are still on the same page. + $this->assertEqual(url('admin/people/permissions', array('absolute' => TRUE)), $this->getUrl(), 'Still on the same page after login for access denied page'); + + // Now, log out and repeat with a non-403 page. + $this->drupalLogout(); + $this->drupalPost('filter/tips', $edit, t('Log in')); + $this->assertNoText(t('User login'), 'Logged in.'); + $this->assertPattern('!!', 'Still on the same page after login for allowed page'); + + // Check that the user login block is not vulnerable to information + // disclosure to third party sites. + $this->drupalLogout(); + $this->drupalPost('http://example.com/', $edit, t('Log in'), array('external' => FALSE)); + // Check that we remain on the site after login. + $this->assertEqual(url('user/' . $user->uid, array('absolute' => TRUE)), $this->getUrl(), 'Redirected to user profile page after login from the frontpage'); + } + + /** + * Test the Who's Online block. + */ + function testWhosOnlineBlock() { + $block = $this->drupalPlaceBlock('user_online_block'); + $config = $block->get('settings'); + + // Generate users. + $user1 = $this->drupalCreateUser(array()); + $user2 = $this->drupalCreateUser(array()); + $user3 = $this->drupalCreateUser(array()); + + // Update access of two users to be within the active timespan. + $this->updateAccess($user1->uid); + $this->updateAccess($user2->uid, REQUEST_TIME + 1); + + // Insert an inactive user who should not be seen in the block, and ensure + // that the admin user used in setUp() does not appear. + $inactive_time = REQUEST_TIME - $config['seconds_online'] - 1; + $this->updateAccess($user3->uid, $inactive_time); + $this->updateAccess($this->adminUser->uid, $inactive_time); + + // Test block output. + $content = entity_view($block, 'block'); + $this->drupalSetContent(render($content)); + $this->assertRaw(t('2 users'), 'Correct number of online users (2 users).'); + $this->assertText($user1->name, 'Active user 1 found in online list.'); + $this->assertText($user2->name, 'Active user 2 found in online list.'); + $this->assertNoText($user3->name, 'Inactive user not found in online list.'); + $this->assertTrue(strpos($this->drupalGetContent(), $user1->name) > strpos($this->drupalGetContent(), $user2->name), 'Online users are ordered correctly.'); + } + + /** + * Updates the access column for a user. + */ + private function updateAccess($uid, $access = REQUEST_TIME) { + db_update('users') + ->condition('uid', $uid) + ->fields(array('access' => $access)) + ->execute(); + } +} diff --git a/core/modules/user/lib/Drupal/user/Tests/UserBlocksTests.php b/core/modules/user/lib/Drupal/user/Tests/UserBlocksTests.php deleted file mode 100644 index 052c254..0000000 --- a/core/modules/user/lib/Drupal/user/Tests/UserBlocksTests.php +++ /dev/null @@ -1,120 +0,0 @@ - 'User blocks', - 'description' => 'Test user blocks.', - 'group' => 'User', - ); - } - - function setUp() { - parent::setUp(); - - $this->adminUser = $this->drupalCreateUser(array('administer blocks')); - $this->drupalLogin($this->adminUser); - $this->drupalPlaceBlock('user_login_block'); - $this->drupalLogout($this->adminUser); - } - - /** - * Test the user login block. - */ - function testUserLoginBlock() { - // Create a user with some permission that anonymous users lack. - $user = $this->drupalCreateUser(array('administer permissions')); - - // Log in using the block. - $edit = array(); - $edit['name'] = $user->name; - $edit['pass'] = $user->pass_raw; - $this->drupalPost('admin/people/permissions', $edit, t('Log in')); - $this->assertNoText(t('User login'), 'Logged in.'); - - // Check that we are still on the same page. - $this->assertEqual(url('admin/people/permissions', array('absolute' => TRUE)), $this->getUrl(), 'Still on the same page after login for access denied page'); - - // Now, log out and repeat with a non-403 page. - $this->drupalLogout(); - $this->drupalPost('filter/tips', $edit, t('Log in')); - $this->assertNoText(t('User login'), 'Logged in.'); - $this->assertPattern('!!', 'Still on the same page after login for allowed page'); - - // Check that the user login block is not vulnerable to information - // disclosure to third party sites. - $this->drupalLogout(); - $this->drupalPost('http://example.com/', $edit, t('Log in'), array('external' => FALSE)); - // Check that we remain on the site after login. - $this->assertEqual(url('user/' . $user->uid, array('absolute' => TRUE)), $this->getUrl(), 'Redirected to user profile page after login from the frontpage'); - } - - /** - * Test the Who's Online block. - */ - function testWhosOnlineBlock() { - $block = $this->drupalPlaceBlock('user_online_block'); - $config = $block->get('settings'); - - // Generate users. - $user1 = $this->drupalCreateUser(array()); - $user2 = $this->drupalCreateUser(array()); - $user3 = $this->drupalCreateUser(array()); - - // Update access of two users to be within the active timespan. - $this->updateAccess($user1->uid); - $this->updateAccess($user2->uid, REQUEST_TIME + 1); - - // Insert an inactive user who should not be seen in the block, and ensure - // that the admin user used in setUp() does not appear. - $inactive_time = REQUEST_TIME - $config['seconds_online'] - 1; - $this->updateAccess($user3->uid, $inactive_time); - $this->updateAccess($this->adminUser->uid, $inactive_time); - - // Test block output. - $content = entity_view($block, 'block'); - $this->drupalSetContent(render($content)); - $this->assertRaw(t('2 users'), 'Correct number of online users (2 users).'); - $this->assertText($user1->name, 'Active user 1 found in online list.'); - $this->assertText($user2->name, 'Active user 2 found in online list.'); - $this->assertNoText($user3->name, 'Inactive user not found in online list.'); - $this->assertTrue(strpos($this->drupalGetContent(), $user1->name) > strpos($this->drupalGetContent(), $user2->name), 'Online users are ordered correctly.'); - } - - /** - * Updates the access column for a user. - */ - private function updateAccess($uid, $access = REQUEST_TIME) { - db_update('users') - ->condition('uid', $uid) - ->fields(array('access' => $access)) - ->execute(); - } -} diff --git a/core/modules/views/lib/Drupal/views/Tests/PluginTypeListTest.php b/core/modules/views/lib/Drupal/views/Tests/PluginTypeListTest.php deleted file mode 100644 index 807ccb6..0000000 --- a/core/modules/views/lib/Drupal/views/Tests/PluginTypeListTest.php +++ /dev/null @@ -1,55 +0,0 @@ - 'Plugin list', - 'description' => 'Tests that list of plugin is correct.', - 'group' => 'Views', - ); - } - - /** - * Tests the plugins list is correct. - */ - public function testPluginList() { - $plugin_list = array( - 'access', - 'area', - 'argument', - 'argument_default', - 'argument_validator', - 'cache', - 'display_extender', - 'display', - 'exposed_form', - 'field', - 'filter', - 'join', - 'pager', - 'query', - 'relationship', - 'row', - 'sort', - 'style', - 'wizard', - ); - - $diff = array_diff($plugin_list, ViewExecutable::getPluginTypes()); - $this->assertTrue(empty($diff), 'The plugin list is correct'); - } - -} diff --git a/core/modules/views/lib/Drupal/views/Tests/PluginTypeListUnitTest.php b/core/modules/views/lib/Drupal/views/Tests/PluginTypeListUnitTest.php new file mode 100644 index 0000000..0e0b1af --- /dev/null +++ b/core/modules/views/lib/Drupal/views/Tests/PluginTypeListUnitTest.php @@ -0,0 +1,55 @@ + 'Plugin list', + 'description' => 'Tests that list of plugin is correct.', + 'group' => 'Views', + ); + } + + /** + * Tests the plugins list is correct. + */ + public function testPluginList() { + $plugin_list = array( + 'access', + 'area', + 'argument', + 'argument_default', + 'argument_validator', + 'cache', + 'display_extender', + 'display', + 'exposed_form', + 'field', + 'filter', + 'join', + 'pager', + 'query', + 'relationship', + 'row', + 'sort', + 'style', + 'wizard', + ); + + $diff = array_diff($plugin_list, ViewExecutable::getPluginTypes()); + $this->assertTrue(empty($diff), 'The plugin list is correct'); + } + +} diff --git a/core/tests/Drupal/Tests/Core/Cache/NullBackendTest.php b/core/tests/Drupal/Tests/Core/Cache/NullBackendTest.php deleted file mode 100644 index fc3a700..0000000 --- a/core/tests/Drupal/Tests/Core/Cache/NullBackendTest.php +++ /dev/null @@ -1,41 +0,0 @@ - 'Cache NullBackend test', - 'description' => 'Tests the cache NullBackend.', - 'group' => 'Cache', - ); - } - - /** - * Tests that the NullBackend does not actually store variables. - */ - function testNullBackend() { - $null_cache = new NullBackend('test'); - - $key = $this->randomName(); - $value = $this->randomName(); - - $null_cache->set($key, $value); - $this->assertTrue($null_cache->isEmpty()); - $this->assertFalse($null_cache->get($key)); - } -} diff --git a/core/tests/Drupal/Tests/Core/Cache/NullBackendUnitTest.php b/core/tests/Drupal/Tests/Core/Cache/NullBackendUnitTest.php new file mode 100644 index 0000000..ed02960 --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Cache/NullBackendUnitTest.php @@ -0,0 +1,42 @@ + 'Cache NullBackend test', + 'description' => 'Tests the cache NullBackend.', + 'group' => 'Cache', + ); + } + + /** + * Tests that the NullBackend does not actually store variables. + */ + function testNullBackend() { + $null_cache = new NullBackend('test'); + + $key = $this->randomName(); + $value = $this->randomName(); + + $null_cache->set($key, $value); + $this->assertTrue($null_cache->isEmpty()); + $this->assertFalse($null_cache->get($key)); + } +} diff --git a/core/vendor/symfony-cmf/routing/Symfony/Cmf/Component/Routing/Tests/NestedMatcher/NestedMatcherTest.php b/core/vendor/symfony-cmf/routing/Symfony/Cmf/Component/Routing/Tests/NestedMatcher/NestedMatcherTest.php deleted file mode 100644 index 2bcee0e..0000000 --- a/core/vendor/symfony-cmf/routing/Symfony/Cmf/Component/Routing/Tests/NestedMatcher/NestedMatcherTest.php +++ /dev/null @@ -1,134 +0,0 @@ -provider = $this->buildMock("Symfony\\Cmf\\Component\\Routing\\RouteProviderInterface"); - $this->routeFilter1 = $this->buildMock('Symfony\\Cmf\\Component\\Routing\\NestedMatcher\\RouteFilterInterface'); - $this->routeFilter2 = $this->buildMock('Symfony\\Cmf\\Component\\Routing\\NestedMatcher\\RouteFilterInterface'); - $this->finalMatcher = $this->buildMock('Symfony\\Cmf\\Component\\Routing\\NestedMatcher\\FinalMatcherInterface'); - } - - public function testNestedMatcher() - { - $request = Request::create('/path/one'); - $routeCollection = new RouteCollection(); - $route = $this->getMockBuilder('Symfony\\Component\\Routing\\Route')->disableOriginalConstructor()->getMock(); - $routeCollection->add('route', $route); - - $this->provider->expects($this->once()) - ->method('getRouteCollectionForRequest') - ->with($request) - ->will($this->returnValue($routeCollection)) - ; - $this->routeFilter1->expects($this->once()) - ->method('filter') - ->with($routeCollection, $request) - ->will($this->returnValue($routeCollection)) - ; - $this->routeFilter2->expects($this->once()) - ->method('filter') - ->with($routeCollection, $request) - ->will($this->returnValue($routeCollection)) - ; - $this->finalMatcher->expects($this->once()) - ->method('finalMatch') - ->with($routeCollection, $request) - ->will($this->returnValue(array('foo' => 'bar'))) - ; - - $matcher = new NestedMatcher($this->provider); - $matcher->addRouteFilter($this->routeFilter1); - $matcher->addRouteFilter($this->routeFilter2); - $matcher->setFinalMatcher($this->finalMatcher); - - $attributes = $matcher->matchRequest($request); - - $this->assertEquals(array('foo' => 'bar'), $attributes); - } - - /** - * Test priorities and exception handling - */ - public function testNestedMatcherPriority() - { - $request = Request::create('/path/one'); - $routeCollection = new RouteCollection(); - $route = $this->getMockBuilder('Symfony\\Component\\Routing\\Route')->disableOriginalConstructor()->getMock(); - $routeCollection->add('route', $route); - - $wrongProvider = $this->buildMock("Symfony\\Cmf\\Component\\Routing\\RouteProviderInterface"); - $wrongProvider->expects($this->never()) - ->method('getRouteCollectionForRequest') - ; - $this->provider->expects($this->once()) - ->method('getRouteCollectionForRequest') - ->with($request) - ->will($this->returnValue($routeCollection)) - ; - $this->routeFilter1->expects($this->once()) - ->method('filter') - ->with($routeCollection, $request) - ->will($this->throwException(new ResourceNotFoundException())) - ; - $this->routeFilter2->expects($this->never()) - ->method('filter') - ; - $this->finalMatcher->expects($this->never()) - ->method('finalMatch') - ; - - $matcher = new NestedMatcher($wrongProvider); - $matcher->setRouteProvider($this->provider); - $matcher->addRouteFilter($this->routeFilter2, 10); - $matcher->addRouteFilter($this->routeFilter1, 20); - $matcher->setFinalMatcher($this->finalMatcher); - - try { - $matcher->matchRequest($request); - fail('nested matcher is eating exception'); - } catch(ResourceNotFoundException $e) - { - // expected - } - } - - public function testProviderNoMatch() - { - $request = Request::create('/path/one'); - $routeCollection = new RouteCollection(); - $this->provider->expects($this->once()) - ->method('getRouteCollectionForRequest') - ->with($request) - ->will($this->returnValue($routeCollection)) - ; - $this->finalMatcher->expects($this->never()) - ->method('finalMatch') - ; - - $matcher = new NestedMatcher($this->provider); - $matcher->setFinalMatcher($this->finalMatcher); - - $this->setExpectedException('Symfony\\Component\\Routing\\Exception\\ResourceNotFoundException'); - $matcher->matchRequest($request); - } - -} diff --git a/core/vendor/symfony-cmf/routing/Symfony/Cmf/Component/Routing/Tests/NestedMatcher/NestedMatcherUnitTest.php b/core/vendor/symfony-cmf/routing/Symfony/Cmf/Component/Routing/Tests/NestedMatcher/NestedMatcherUnitTest.php new file mode 100644 index 0000000..c527e32 --- /dev/null +++ b/core/vendor/symfony-cmf/routing/Symfony/Cmf/Component/Routing/Tests/NestedMatcher/NestedMatcherUnitTest.php @@ -0,0 +1,130 @@ +provider = $this->buildMock("Symfony\\Cmf\\Component\\Routing\\RouteProviderInterface"); + $this->routeFilter1 = $this->buildMock('Symfony\\Cmf\\Component\\Routing\\NestedMatcher\\RouteFilterInterface'); + $this->routeFilter2 = $this->buildMock('Symfony\\Cmf\\Component\\Routing\\NestedMatcher\\RouteFilterInterface'); + $this->finalMatcher = $this->buildMock('Symfony\\Cmf\\Component\\Routing\\NestedMatcher\\FinalMatcherInterface'); + } + + public function testNestedMatcher() + { + $request = Request::create('/path/one'); + $routeCollection = new RouteCollection(); + $route = $this->getMockBuilder('Symfony\\Component\\Routing\\Route')->disableOriginalConstructor()->getMock(); + $routeCollection->add('route', $route); + + $this->provider->expects($this->once()) + ->method('getRouteCollectionForRequest') + ->with($request) + ->will($this->returnValue($routeCollection)) + ; + $this->routeFilter1->expects($this->once()) + ->method('filter') + ->with($routeCollection, $request) + ->will($this->returnValue($routeCollection)) + ; + $this->routeFilter2->expects($this->once()) + ->method('filter') + ->with($routeCollection, $request) + ->will($this->returnValue($routeCollection)) + ; + $this->finalMatcher->expects($this->once()) + ->method('finalMatch') + ->with($routeCollection, $request) + ->will($this->returnValue(array('foo' => 'bar'))) + ; + + $matcher = new NestedMatcher($this->provider); + $matcher->addRouteFilter($this->routeFilter1); + $matcher->addRouteFilter($this->routeFilter2); + $matcher->setFinalMatcher($this->finalMatcher); + + $attributes = $matcher->matchRequest($request); + + $this->assertEquals(array('foo' => 'bar'), $attributes); + } + + /** + * Test priorities and exception handling + */ + public function testNestedMatcherPriority() + { + $request = Request::create('/path/one'); + $routeCollection = new RouteCollection(); + $route = $this->getMockBuilder('Symfony\\Component\\Routing\\Route')->disableOriginalConstructor()->getMock(); + $routeCollection->add('route', $route); + + $wrongProvider = $this->buildMock("Symfony\\Cmf\\Component\\Routing\\RouteProviderInterface"); + $wrongProvider->expects($this->never()) + ->method('getRouteCollectionForRequest') + ; + $this->provider->expects($this->once()) + ->method('getRouteCollectionForRequest') + ->with($request) + ->will($this->returnValue($routeCollection)) + ; + $this->routeFilter1->expects($this->once()) + ->method('filter') + ->with($routeCollection, $request) + ->will($this->throwException(new ResourceNotFoundException())) + ; + $this->routeFilter2->expects($this->never()) + ->method('filter') + ; + $this->finalMatcher->expects($this->never()) + ->method('finalMatch') + ; + + $matcher = new NestedMatcher($wrongProvider); + $matcher->setRouteProvider($this->provider); + $matcher->addRouteFilter($this->routeFilter2, 10); + $matcher->addRouteFilter($this->routeFilter1, 20); + $matcher->setFinalMatcher($this->finalMatcher); + + try { + $matcher->matchRequest($request); + fail('nested matcher is eating exception'); + } catch(ResourceNotFoundException $e) + { + // expected + } + } + + public function testProviderNoMatch() + { + $request = Request::create('/path/one'); + $routeCollection = new RouteCollection(); + $this->provider->expects($this->once()) + ->method('getRouteCollectionForRequest') + ->with($request) + ->will($this->returnValue($routeCollection)) + ; + $this->finalMatcher->expects($this->never()) + ->method('finalMatch') + ; + + $matcher = new NestedMatcher($this->provider); + $matcher->setFinalMatcher($this->finalMatcher); + + $this->setExpectedException('Symfony\\Component\\Routing\\Exception\\ResourceNotFoundException'); + $matcher->matchRequest($request); + } + +}