Пример #1
0
 /**
  * test array access
  */
 function testArrayAccess()
 {
     // make an eptTest object
     $this->assertTrue($o = new eptTest("XXX", "YYY", "ZZZ"));
     // wrap it with epObject
     $this->assertTrue($w = new epObject($o));
     // test new object is not dirty
     $this->assertFalse($w->epIsDirty());
     // test epGet('x') against direct object property access ($o->x)
     $this->assertTrue($w['x'] === $o->x);
     // test epSet('x'), epGet('x'), and $w->x (overloading __get())
     $value = md5($w['x']);
     $this->assertTrue($w['x'] = $value);
     $this->assertTrue($o->x === $value);
     $this->assertTrue($w['x'] === $o->x);
     $this->assertTrue($w->epIsDirty());
     // check if 'x' is in modified list
     $this->assertTrue($modified = $w->epGetModifiedVars());
     $this->assertTrue(array_key_exists('x', $modified));
     $this->assertTrue($modified['x'] === $value);
     // getting protected 'y' gets exception
     try {
         $this->assertTrue($w['y'] === false);
     } catch (Exception $e) {
         // !!!simpletest seem to ignore assert in catch block
         $this->assertTrue($e instanceof epExceptionObject);
     }
     // setting protected 'y' gets exception
     try {
         $w['y'] = 'YYY|YYY';
     } catch (Exception $e) {
         // !!!simpletest seem to ignore assert in catch block
         $this->assertTrue($e instanceof epExceptionObject);
     }
     // getting protected 'z' gets exception
     try {
         $this->assertTrue($w['z'] === false);
     } catch (Exception $e) {
         // !!!simpletest seem to ignore assert in catch block
         $this->assertTrue($e instanceof epExceptionObject);
     }
     // setting protected 'z' gets exception
     try {
         $w['z'] = 'ZZZ|ZZZ';
     } catch (Exception $e) {
         // !!!simpletest seem to ignore assert in catch block
         $this->assertTrue($e instanceof epExceptionObject);
     }
     // test foreach
     $vars = array();
     foreach ($w as $var => $value) {
         $vars[$var] = $value;
     }
     // check var number
     $this->assertTrue(count($vars) == $w->count());
 }