예제 #1
0
파일: LinkTest.php 프로젝트: reliv/rcm-user
 public function test()
 {
     $link = new Link();
     $link->setHelp('TESThelp');
     $link->setTitle('TESTtitle');
     $link->setType('TESTtype');
     $link->setUrl('TESTurl');
     $linkData = ['help' => 'TEST2help', 'title' => 'TEST2title', 'type' => 'TEST2type', 'url' => 'TEST2url'];
     $this->assertEquals('TESThelp', $link->getHelp());
     $this->assertEquals('TESTtitle', $link->getTitle());
     $this->assertEquals('TESTtype', $link->getType());
     $this->assertEquals('TESTurl', $link->getUrl());
     $this->assertJson(json_encode($link));
     $link2 = new Link();
     $link2->populate($linkData);
     $this->assertEquals($linkData['url'], $link2->getUrl());
     $link2->populate($link);
     $this->assertEquals($link->getUrl(), $link2->getUrl());
     try {
         $link2->populate('nope');
     } catch (\RcmUser\Exception\RcmUserException $e) {
         $this->assertInstanceOf('\\RcmUser\\Exception\\RcmUserException', $e);
         return;
     }
     $this->fail("Expected exception not thrown");
 }
예제 #2
0
 public function test()
 {
     $link = new Link();
     $link->setHelp('TESThelp');
     $link->setTitle('TESTtitle');
     $link->setType('TESTtype');
     $link->setUrl('TESTurl');
     $linksData = [$link];
     $links = new Links($linksData);
     $this->assertEquals($link, $links->getLinks()[0]);
     $links->addLink($link);
     $this->assertEquals(2, count($links->getLinks()));
     $this->assertInstanceOf('\\ArrayIterator', $links->getIterator());
     $this->assertJson(json_encode($links));
 }
예제 #3
0
파일: Link.php 프로젝트: reliv/rcm-user
 /**
  * populate
  *
  * @param array|Link $data data to populate this object with
  *
  * @return void
  * @throws RcmUserException
  */
 public function populate($data = [])
 {
     if ($data instanceof Link) {
         $this->setType($data->getType());
         $this->setTitle($data->getTitle());
         $this->setUrl($data->getUrl());
         $this->setHelp($data->getHelp());
         return;
     }
     if (is_array($data)) {
         if (isset($data['type'])) {
             $this->setType($data['type']);
         }
         if (isset($data['title'])) {
             $this->setTitle($data['title']);
         }
         if (isset($data['url'])) {
             $this->setUrl($data['url']);
         }
         if (isset($data['help'])) {
             $this->setHelp($data['help']);
         }
         return;
     }
     throw new RcmUserException('Link data could not be populated, date format not supported');
 }