. * */ namespace OCA\News\Bl; require_once(__DIR__ . "/../classloader.php"); use \OCA\News\Db\Item; class ItemBlTest extends \OCA\AppFramework\Utility\TestUtility { protected $api; protected $mapper; protected $bl; protected $user; protected $response; protected function setUp(){ $this->api = $this->getAPIMock(); $this->mapper = $this->getMockBuilder('\OCA\News\Db\ItemMapper') ->disableOriginalConstructor() ->getMock(); $this->bl = new ItemBl($this->mapper); $this->user = 'jack'; $response = 'hi'; } /* public function testFindAll(){ $this->mapper->expects($this->once()) ->method('findAll') ->with($this->equalTo($this->user)) ->will($this->returnValue($this->response)); $result = $this->bl->findAllFromUser($this->user); $this->assertEquals($this->response, $result); } */ public function testStarredCount(){ $star = 18; $this->mapper->expects($this->once()) ->method('starredCount') ->with($this->equalTo($this->user)) ->will($this->returnValue($star)); $result = $this->bl->starredCount($this->user); $this->assertEquals($star, $result); } public function testStar(){ $itemId = 3; $item = new Item(); $item->setStatus(128); $item->setId($itemId); $this->mapper->expects($this->once()) ->method('find') ->with($this->equalTo($itemId), $this->equalTo($this->user)) ->will($this->returnValue($item)); $this->mapper->expects($this->once()) ->method('update') ->with($this->equalTo($item)); $this->bl->star($itemId, false, $this->user); $this->assertTrue($item->isUnstarred()); } public function testRead(){ $itemId = 3; $item = new Item(); $item->setStatus(128); $item->setId($itemId); $this->mapper->expects($this->once()) ->method('find') ->with($this->equalTo($itemId), $this->equalTo($this->user)) ->will($this->returnValue($item)); $this->mapper->expects($this->once()) ->method('update') ->with($this->equalTo($item)); $this->bl->read($itemId, false, $this->user); $this->assertTrue($item->isUnread()); } public function testReadFeed(){ $feedId = 3; $this->mapper->expects($this->once()) ->method('readFeed') ->with($this->equalTo($feedId), $this->equalTo($this->user)); $this->bl->readFeed($feedId, $this->user); } public function testCreate(){ $item = new Item(); $this->mapper->expects($this->once()) ->method('insert') ->with($this->equalTo($item)); $this->bl->create($item, $this->user); } }