Skip to content

Commit

Permalink
Use data provider
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Aug 15, 2014
1 parent bf0740f commit 3983231
Show file tree
Hide file tree
Showing 5 changed files with 251 additions and 244 deletions.
46 changes: 27 additions & 19 deletions framework/Imap_Client/test/Horde/Imap/Client/Ids/Pop3Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,45 @@
*/
class Horde_Imap_Client_Ids_Pop3Test extends PHPUnit_Framework_TestCase
{
public function testPop3SequenceStringGenerate()
/**
* @dataProvider pop3SequenceStringGenerateProvider
*/
public function testPop3SequenceStringGenerate($in, $expected)
{
$this->assertEquals(
'ABCDEFGHIJ ABCDE',
strval(new Horde_Imap_Client_Ids_Pop3(array('ABCDEFGHIJ', 'ABCDE')))
);

$this->assertEquals(
'ABCDEFGHIJ',
strval(new Horde_Imap_Client_Ids_Pop3('ABCDEFGHIJ'))
$expected,
strval(new Horde_Imap_Client_Ids_Pop3($in))
);
}

public function testPop3SequenceStringParse()
public function pop3SequenceStringGenerateProvider()
{
$ids = new Horde_Imap_Client_Ids_Pop3('ABCDEFGHIJ ABCDE');
$this->assertEquals(
array('ABCDEFGHIJ', 'ABCDE'),
$ids->ids
return array(
array(array('ABCDEFGHIJ', 'ABCDE'), 'ABCDEFGHIJ ABCDE'),
array('ABCDEFGHIJ', 'ABCDEFGHIJ')
);
}

$ids = new Horde_Imap_Client_Ids_Pop3('ABCDEFGHIJ ABC ABCDE');
/**
* @dataProvider pop3SequenceStringParseProvider
*/
public function testPop3SequenceStringParse($in, $expected)
{
$ids = new Horde_Imap_Client_Ids_Pop3($in);
$this->assertEquals(
array('ABCDEFGHIJ', 'ABC', 'ABCDE'),
$expected,
$ids->ids
);
}

$ids = new Horde_Imap_Client_Ids_Pop3('10:12');
$this->assertEquals(
array('10:12'),
$ids->ids
public function pop3SequenceStringParseProvider()
{
return array(
array('ABCDEFGHIJ ABCDE', array('ABCDEFGHIJ', 'ABCDE')),
array('ABCDEFGHIJ ABC ABCDE', array('ABCDEFGHIJ', 'ABC', 'ABCDE')),
array('ABCDEFGHIJ', array('ABCDEFGHIJ')),
// This is not a range in POP3 IDs
array('10:12', array('10:12'))
);
}

Expand Down
66 changes: 27 additions & 39 deletions framework/Imap_Client/test/Horde/Imap/Client/IdsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,27 +154,25 @@ public function testSorting()
);
}

public function testSpecialIdValueStringRepresentations()
/**
* @dataProvider specialIdValueStringRepresentationsProvider
*/
public function testSpecialIdValueStringRepresentations($in, $expected)
{
$ids = new Horde_Imap_Client_Ids(Horde_Imap_Client_Ids::ALL);
$ids = new Horde_Imap_Client_Ids($in);

$this->assertEquals(
'1:*',
$expected,
$ids->tostring
);
}

$ids = new Horde_Imap_Client_Ids(Horde_Imap_Client_Ids::SEARCH_RES);

$this->assertEquals(
'$',
$ids->tostring
);

$ids = new Horde_Imap_Client_Ids(Horde_Imap_Client_Ids::LARGEST);

$this->assertEquals(
'*',
$ids->tostring
public function specialIdValueStringRepresentationsProvider()
{
return array(
array(Horde_Imap_Client_Ids::ALL, '1:*'),
array(Horde_Imap_Client_Ids::SEARCH_RES, '$'),
array(Horde_Imap_Client_Ids::LARGEST, '*')
);
}

Expand Down Expand Up @@ -277,39 +275,29 @@ public function testRemove()
);
}

public function testMinAndMax()
/**
* @dataProvider minAndMaxProvider
*/
public function testMinAndMax($in, $min, $max)
{
$ids = new Horde_Imap_Client_Ids(array(1));
$ids = new Horde_Imap_Client_Ids($in);

$this->assertEquals(
1,
$min,
$ids->min
);
$this->assertEquals(
1,
$max,
$ids->max
);
}

$ids2 = new Horde_Imap_Client_Ids(array(1, 2));

$this->assertEquals(
1,
$ids2->min
);
$this->assertEquals(
2,
$ids2->max
);

$ids3 = new Horde_Imap_Client_Ids(array(1, 5, 3));

$this->assertEquals(
1,
$ids3->min
);
$this->assertEquals(
5,
$ids3->max
public function minAndMaxProvider()
{
return array(
array(array(1), 1, 1),
array(array(1, 2), 1, 2),
array(array(1, 5, 3), 1, 5)
);
}

Expand Down
143 changes: 75 additions & 68 deletions framework/Imap_Client/test/Horde/Imap/Client/MapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,100 +99,107 @@ public function testUpdate()
);
}

public function testLookup()
/**
* @dataProvider lookupProvider
*/
public function testLookup($range, $expected = null)
{
$map = clone $this->map;

$this->assertEquals(
array(
2 => 5,
4 => 10,
6 => 15
),
$map->lookup(new Horde_Imap_Client_Ids('5:15'))
$expected ?: $map->map,
$map->lookup($range)
);
}

$this->assertEquals(
public function lookupProvider()
{
return array(
array(
2 => 5,
4 => 10,
6 => 15
new Horde_Imap_Client_Ids('5:15'),
array(
2 => 5,
4 => 10,
6 => 15
)
),
$map->lookup(new Horde_Imap_Client_Ids('2:6', true))
);

$this->assertEquals(
$map->map,
$map->lookup(new Horde_Imap_Client_Ids(Horde_Imap_Client_Ids::ALL))
array(
new Horde_Imap_Client_Ids('2:6', true),
array(
2 => 5,
4 => 10,
6 => 15
)
),
array(
new Horde_Imap_Client_Ids(Horde_Imap_Client_Ids::ALL)
)
);
}

public function testRemove()
/**
* @dataProvider removeProvider
*/
public function testRemove($range, $expected)
{
$map = clone $this->map;
$map->remove(new Horde_Imap_Client_Ids('10'));
$map->remove($range);

$this->assertEquals(
array(
2 => 5,
5 => 15,
7 => 20,
9 => 25,
11 => 30
),
$expected,
$map->map
);
}

$map = clone $this->map;
$map->remove(new Horde_Imap_Client_Ids('4', true));

$this->assertEquals(
public function removeProvider()
{
return array(
array(
2 => 5,
5 => 15,
7 => 20,
9 => 25,
11 => 30
new Horde_Imap_Client_Ids('10'),
array(
2 => 5,
5 => 15,
7 => 20,
9 => 25,
11 => 30
)
),
$map->map
);

$map = clone $this->map;
$map->remove(new Horde_Imap_Client_Ids('10:15,25'));

$this->assertEquals(
array(
2 => 5,
6 => 20,
9 => 30
new Horde_Imap_Client_Ids('4', true),
array(
2 => 5,
5 => 15,
7 => 20,
9 => 25,
11 => 30
)
),
$map->map
);

// Efficient sequence number remove.
$map = clone $this->map;
$map->remove(new Horde_Imap_Client_Ids(array('10', '6', '4'), true));

$this->assertEquals(
array(
2 => 5,
6 => 20,
9 => 30
new Horde_Imap_Client_Ids('10:15,25'),
array(
2 => 5,
6 => 20,
9 => 30
)
),
$map->map
);

// Inefficient sequence number remove.
$map = clone $this->map;
$map->remove(new Horde_Imap_Client_Ids(array('4', '5', '8'), true));

$this->assertEquals(
// Efficient sequence number remove.
array(
2 => 5,
6 => 20,
9 => 30
new Horde_Imap_Client_Ids(array('10', '6', '4'), true),
array(
2 => 5,
6 => 20,
9 => 30
)
),
$map->map
// Inefficient sequence number remove.
array(
new Horde_Imap_Client_Ids(array('4', '5', '8'), true),
array(
2 => 5,
6 => 20,
9 => 30
)
)
);
}

Expand Down

0 comments on commit 3983231

Please sign in to comment.