test_array.php 1.3 KB

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