Пример #1
0
 /**
  * test primitive variables
  */
 function testPrimitiveVars()
 {
     // 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());
     // check vars
     $this->assertTrue($vars = $w->epGetVars());
     // x, a, o are in vars
     $this->assertTrue(array_key_exists("x", $vars));
     $this->assertTrue(array_key_exists("a", $vars));
     $this->assertTrue(array_key_exists("o", $vars));
     // y protected is not in vars
     $this->assertFalse(array_key_exists("y", $vars));
     $this->assertFalse(array_key_exists("z", $vars));
     /**
      * test primitive vars
      */
     // test epGet('x') against direct object property access ($o->x)
     $this->assertTrue($w->epGet('x') === $o->x);
     // test epSet('x'), epGet('x'), and $w->x (overloading __get())
     $value = md5($w->epGet('x'));
     $this->assertTrue($w->epSet('x', $value));
     $this->assertTrue($o->x === $value);
     $this->assertTrue($w->epGet('x') === $o->x);
     $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);
     // test getter/setter (overloading __call())
     $value = md5($w->epGet('x'));
     $this->assertTrue($w->setX($value));
     $this->assertTrue($w->getX() === $o->x);
     $this->assertTrue($w->getX() === $value);
     // check which 'x' is in modified list
     $this->assertTrue($modified = $w->epGetModifiedVars());
     $this->assertTrue(array_key_exists('x', $modified));
     $this->assertTrue($modified['x'] === $value);
     // check magic method __get() and __set()
     $this->assertTrue($w->x === $value);
     $value = md5($w->x);
     $this->assertTrue($w->x = $value);
     $this->assertTrue($w->x === $value);
     // getting protected 'y' gets exception
     try {
         $this->assertTrue($w->epGet('y') === false);
     } catch (Exception $e) {
         // !!!simpletest seem to ignore assert in catch block
         $this->assertTrue($e instanceof epExceptionObject);
     }
     // setting protected 'y' gets exception
     try {
         $this->assertTrue($w->epSet('y', 'YYY|YYY') === false);
     } 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->epGet('z') === false);
     } catch (Exception $e) {
         // !!!simpletest seem to ignore assert in catch block
         $this->assertTrue($e instanceof epExceptionObject);
     }
     // setting protected 'z' gets exception
     try {
         $this->assertTrue($w->epSet('z', 'ZZZ|ZZZ') === false);
     } catch (Exception $e) {
         // !!!simpletest seem to ignore assert in catch block
         $this->assertTrue($e instanceof epExceptionObject);
     }
 }