Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/roundcube/roundcubemail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2022-05-01 12:43:28 +0300
committerAleksander Machniak <alec@alec.pl>2022-05-01 12:43:28 +0300
commit71d151dba977481651452d0c64bba853861bc7c0 (patch)
treef8e01f6f30db985de3e719281b51e22ac9e918a5
parenta040d63ff5a783882375edc6f3534bd184573790 (diff)
Add some tests and fix flaky test
-rw-r--r--tests/ActionTestCase.php4
-rw-r--r--tests/Actions/Mail/Search.php81
-rw-r--r--tests/Actions/Settings/Index.php10
-rw-r--r--tests/bootstrap.php18
4 files changed, 109 insertions, 4 deletions
diff --git a/tests/ActionTestCase.php b/tests/ActionTestCase.php
index 1068a60f3..091504367 100644
--- a/tests/ActionTestCase.php
+++ b/tests/ActionTestCase.php
@@ -141,11 +141,15 @@ class ActionTestCase extends PHPUnit\Framework\TestCase
/**
* Set the $rcmail->storage property
+ *
+ * @return StorageMock The storage object
*/
public static function initStorage()
{
$rcmail = rcmail::get_instance();
$rcmail->storage = new StorageMock();
+
+ return $rcmail->storage;
}
/**
diff --git a/tests/Actions/Mail/Search.php b/tests/Actions/Mail/Search.php
index 31127acad..b67a31a37 100644
--- a/tests/Actions/Mail/Search.php
+++ b/tests/Actions/Mail/Search.php
@@ -58,7 +58,59 @@ class Actions_Mail_Search extends ActionTestCase
*/
function test_search_non_empty_result()
{
- $this->markTestIncomplete();
+ $action = new rcmail_action_mail_search;
+ $output = $this->initOutput(rcmail_action::MODE_AJAX, 'mail', 'search');
+
+ $_GET = [
+ '_q' => 'test',
+ '_mbox' => 'INBOX',
+ ];
+
+ $index = new rcube_result_index('INBOX', 'SEARCH 10');
+
+ // Set expected storage function calls/results
+ self::initStorage()
+ ->registerFunction('set_page')
+ ->registerFunction('set_search_set')
+ ->registerFunction('search',)
+ ->registerFunction('get_search_set', ['SEARCH HEADER SUBJECT test', $index, 'UTF-8', '', false])
+ ->registerFunction('get_search_set', ['SEARCH HEADER SUBJECT test', $index, 'UTF-8', '', false])
+ ->registerFunction('get_pagesize', 10)
+ ->registerFunction('get_pagesize', 10)
+ ->registerFunction('get_folder', 'INBOX')
+ ->registerFunction('list_messages', [
+ 10 => rcube_message_header::from_array([
+ 'id' => 42,
+ 'uid' => 10,
+ 'subject' => 'test message',
+ 'from' => 'test1@test.com',
+ 'to' => 'Test <test2@test.com>',
+ 'date' => 'Sun, 13 Mar 2022 17:08:18 +0100',
+ 'size' => 889,
+ 'content-type' => 'text/plain',
+ ])
+ ])
+ ->registerFunction('get_threading', false)
+ ->registerFunction('get_threading', false)
+ ->registerFunction('get_threading', false)
+ ->registerFunction('count', 1)
+ ->registerFunction('count', 1)
+ ->registerFunction('count', 1)
+ ->registerFunction('folder_data', [])
+ ->registerFunction('get_quota', false);
+
+ $this->runAndAssert($action, OutputJsonMock::E_EXIT);
+
+ $result = $output->getOutput();
+
+ $this->assertSame(['Content-Type: application/json; charset=UTF-8'], $output->headers);
+ $this->assertSame('search', $result['action']);
+ $this->assertSame(1, $result['env']['messagecount']);
+ $this->assertSame(1, $result['env']['pagecount']);
+ $this->assertSame(1, $result['env']['exists']);
+ $this->assertTrue(strpos($result['exec'], 'this.display_message("1 messages found.","confirmation",0);') !== false);
+ $this->assertTrue(strpos($result['exec'], 'this.set_rowcount("Messages 1 to 1 of 1","INBOX");') !== false);
+ $this->assertTrue(strpos($result['exec'], 'this.set_pagetitle("Roundcube Webmail :: Search result");') !== false);
}
/**
@@ -102,10 +154,33 @@ class Actions_Mail_Search extends ActionTestCase
}
/**
+ * Test data for test_search_interval_criteria()
+ */
+ function data_search_interval_criteria()
+ {
+ $week = new DateInterval('P1W');
+ $month = new DateInterval('P1M');
+ $year = new DateInterval('P1Y');
+
+ return [
+ ['', null],
+ ['1W', 'SINCE ' . (new DateTime('now'))->sub($week)->format('j-M-Y')],
+ ['1M', 'SINCE ' . (new DateTime('now'))->sub($month)->format('j-M-Y')],
+ ['1Y', 'SINCE ' . (new DateTime('now'))->sub($year)->format('j-M-Y')],
+ ['-1W', 'BEFORE ' . (new DateTime('now'))->sub($week)->format('j-M-Y')],
+ ['-1M', 'BEFORE ' . (new DateTime('now'))->sub($month)->format('j-M-Y')],
+ ['-1Y', 'BEFORE ' . (new DateTime('now'))->sub($year)->format('j-M-Y')],
+ ];
+ }
+
+ /**
* Test search_interval_criteria() method
+ *
+ * @dataProvider data_search_interval_criteria
*/
- function test_search_interval_criteria()
+ function test_search_interval_criteria($input, $output)
{
- $this->markTestIncomplete();
+ $result = rcmail_action_mail_search::search_interval_criteria($input);
+ $this->assertSame($output, $result);
}
}
diff --git a/tests/Actions/Settings/Index.php b/tests/Actions/Settings/Index.php
index 3ba015cf4..d777a38c3 100644
--- a/tests/Actions/Settings/Index.php
+++ b/tests/Actions/Settings/Index.php
@@ -58,7 +58,15 @@ class Actions_Settings_Index extends ActionTestCase
function test_settings_tabs()
{
$result = rcmail_action_settings_index::settings_tabs([]);
- $this->assertTrue(strpos($result, '<span id="settingstabpreferences" class="preferences selected"><a title="Edit user preferences" href="./?_task=settings&amp;_action=preferences"') === 0);
+ $nodes = getHTMLNodes($result, "//span[@id='settingstabpreferences']");
+
+ $this->assertCount(1, $nodes);
+ $this->assertSame('preferences selected', $nodes[0]->getAttribute('class'));
+ $this->assertCount(1, $nodes[0]->childNodes);
+ $link = $nodes[0]->firstChild;
+ $this->assertSame('a', $link->nodeName);
+ $this->assertSame('Edit user preferences', $link->getAttribute('title'));
+ $this->assertStringEndsWith('?_task=settings&_action=preferences', $link->getAttribute('href'));
}
/**
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 0766cfac9..e0204d589 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -110,3 +110,21 @@ function setProperty($object, $name, $value, $class = null)
$property->setValue($object, $value);
}
+
+/**
+ * Parse HTML content and extract nodes by XPath query
+ *
+ * @param string $html HTML content
+ * @param string $xpath_query XPath query
+ *
+ * @return DOMNodeList List of nodes found
+ */
+function getHTMLNodes($html, $xpath_query)
+{
+ $html5 = new Masterminds\HTML5(['disable_html_ns' => true]);
+ $doc = $html5->loadHTML($html);
+
+ $xpath = new DOMXPath($doc);
+
+ return $xpath->query($xpath_query);
+}