diff options
-rw-r--r-- | program/lib/Roundcube/rcube_result_index.php | 19 | ||||
-rw-r--r-- | program/lib/Roundcube/rcube_result_thread.php | 2 | ||||
-rw-r--r-- | tests/Framework/ResultIndex.php | 47 | ||||
-rw-r--r-- | tests/Framework/ResultThread.php | 2 |
4 files changed, 50 insertions, 20 deletions
diff --git a/program/lib/Roundcube/rcube_result_index.php b/program/lib/Roundcube/rcube_result_index.php index 5f592c54f..058f25c6f 100644 --- a/program/lib/Roundcube/rcube_result_index.php +++ b/program/lib/Roundcube/rcube_result_index.php @@ -231,29 +231,13 @@ class rcube_result_index /** - * Filters data set. Removes elements listed in $ids list. + * Filters data set. Removes elements not listed in $ids list. * * @param array $ids List of IDs to remove. */ public function filter($ids = array()) { $data = $this->get(); - $data = array_diff($data, $ids); - - $this->meta = array(); - $this->meta['count'] = count($data); - $this->raw_data = implode(self::SEPARATOR_ELEMENT, $data); - } - - - /** - * Filters data set. Removes elements not listed in $ids list. - * - * @param array $ids List of IDs to keep. - */ - public function intersect($ids = array()) - { - $data = $this->get(); $data = array_intersect($data, $ids); $this->meta = array(); @@ -332,6 +316,7 @@ class rcube_result_index if (empty($this->raw_data)) { return array(); } + return explode(self::SEPARATOR_ELEMENT, $this->raw_data); } diff --git a/program/lib/Roundcube/rcube_result_thread.php b/program/lib/Roundcube/rcube_result_thread.php index c7f21db53..ceaaf59a6 100644 --- a/program/lib/Roundcube/rcube_result_thread.php +++ b/program/lib/Roundcube/rcube_result_thread.php @@ -453,7 +453,7 @@ class rcube_result_thread // when sorting search result it's good to make the index smaller if ($index->count() != $this->count_messages()) { - $index->intersect($this->get()); + $index->filter($this->get()); } $result = array_fill_keys($index->get(), null); diff --git a/tests/Framework/ResultIndex.php b/tests/Framework/ResultIndex.php index efbba6da7..da1cc628f 100644 --- a/tests/Framework/ResultIndex.php +++ b/tests/Framework/ResultIndex.php @@ -17,4 +17,51 @@ class Framework_ResultIndex extends PHPUnit_Framework_TestCase $this->assertInstanceOf('rcube_result_index', $object, "Class constructor"); } + + /** + * thread parser test + */ + function test_parse() + { + $text = "* SORT 2001 2002 2035 2036 2037 2038 2044 2046 2043 2045 2226 2225 2224 2223"; + $object = new rcube_result_index('INBOX', $text); + + $this->assertSame(false, $object->is_empty(), "Object is empty"); + $this->assertSame(false, $object->is_error(), "Object is error"); + $this->assertSame(2226, $object->max(), "Max message UID"); + $this->assertSame(2001, $object->min(), "Min message UID"); + $this->assertSame(14, $object->count_messages(), "Messages count"); + $this->assertSame(14, $object->count(), "Messages count"); + $this->assertSame(1, $object->exists(2002, true), "Message exists"); + $this->assertSame(true, $object->exists(2002), "Message exists (bool)"); + $this->assertSame(2001, $object->get_element('FIRST'), "Get first element"); + $this->assertSame(2223, $object->get_element('LAST'), "Get last element"); + $this->assertSame(2035, (int) $object->get_element(2), "Get specified element"); + $this->assertSame("2001:2002,2035:2038,2043:2046,2223:2226", $object->get_compressed(), "Get compressed index"); + $this->assertSame('INBOX', $object->get_parameters('MAILBOX'), "Get parameter"); + + $clone = clone $object; + $clone->filter(array(2035, 2002)); + + $this->assertSame(2, $clone->count(), "Messages count (filtered)"); + $this->assertSame(2002, $clone->get_element('FIRST'), "Get first element (filtered)"); + + $clone = clone $object; + $clone->revert(); + + $this->assertSame(14, $clone->count(), "Messages count (reverted)"); + $this->assertSame(12, $clone->exists(2002, true), "Message exists (reverted)"); + $this->assertSame(true, $clone->exists(2002), "Message exists (bool) (reverted)"); + $this->assertSame(2223, $clone->get_element('FIRST'), "Get first element (reverted)"); + $this->assertSame(2001, $clone->get_element('LAST'), "Get last element (reverted)"); + $this->assertSame(2225, (int) $clone->get_element(2), "Get specified element (reverted)"); + + $clone = clone $object; + $clone->slice(2, 3); + + $this->assertSame(3, $clone->count(), "Messages count (sliced)"); + $this->assertSame(2035, $clone->get_element('FIRST'), "Get first element (sliced)"); + $this->assertSame(2037, $clone->get_element('LAST'), "Get last element (sliced)"); + } + } diff --git a/tests/Framework/ResultThread.php b/tests/Framework/ResultThread.php index 8f5c5092f..55fca4c6a 100644 --- a/tests/Framework/ResultThread.php +++ b/tests/Framework/ResultThread.php @@ -55,7 +55,5 @@ class Framework_ResultThread extends PHPUnit_Framework_TestCase $object->filter(array(784)); $this->assertSame(118, $object->count_messages(), "Messages filter"); $this->assertSame(1, $object->count(), "Messages filter (count)"); - -//echo $object->get_compressed(); } } |