array.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. include_once 'config.php';
  3. __p::load_plugin('array');
  4. class pQueryArrayTest extends PHPUnit_Framework_TestCase {
  5. var $variable;
  6. var $arr;
  7. function setUp() {
  8. $this->variable = array('test');
  9. $this->arr = _arr($this->variable);
  10. }
  11. function test_constructor() {
  12. $this->assertTrue($this->arr instanceof pQueryArray, 'constructor does not return pQueryArray object.');
  13. $this->assertEquals($this->arr->variable, $this->variable, 'variable is not set correctly.');
  14. }
  15. function test_get_simple() {
  16. $this->assertEquals($this->arr->get(0), $this->variable[0]);
  17. }
  18. function test_get_non_existent() {
  19. $this->assertNull($this->arr->get(count($this->variable)), 'non-existent index should yield NULL.');
  20. }
  21. function test_is_empty_empty() {
  22. $this->assertTrue(_arr(array())->is_empty());
  23. }
  24. function test_is_empty_non_empty() {
  25. $this->assertFalse($this->arr->is_empty());
  26. }
  27. function test_reverse() {
  28. $orginal = range(1, 4);
  29. $reverse = range(4, 1, -1);
  30. $arr = _arr($orginal);
  31. $this->assertEquals($arr->reverse()->variable, $reverse, 'reverse is not really reverse...');
  32. }
  33. function test_call_count() {
  34. $this->assertEquals($this->arr->count(), count($this->variable));
  35. }
  36. function test_call_sort() {
  37. $arr = range(1, 8);
  38. shuffle($arr);
  39. $this->assertEquals(_arr($arr)->sort()->variable, range(1, 8));
  40. }
  41. }
  42. ?>