public function testActionCode() { $expected = 'LOGIN'; $this->assertNull($this->action->getActionCode()); $this->assertSame($this->action, $this->action->setActionCode($expected)); $this->assertEquals($expected, $this->action->getActionCode()); }
public function testNotifySeveralActionsWithCategories() { $history = new History(); $this->client->getEmitter()->attach($history); $this->subscriber->addResponse(new Response(200, [], new Stream(fopen('data://text/plain,[]', 'r')))); $item = new Item(); $item->setItemId('the-item'); $actionLogin = new Action(); $actionLogin->setActionCode('LOGIN')->setItem($item); $actionSignup = new Action(); $actionSignup->setActionCode('SIGNUP')->setCategories(['foo', 'bar']); $this->client->notifySeveralActions('12345', [$actionLogin, $actionSignup]); $contents = $history->getLastRequest()->getBody()->__toString(); $request = json_decode($contents, true); $this->assertEquals(['userId' => '12345', 'actions' => [['actionCode' => 'LOGIN', 'item' => ['id' => 'the-item', 'title' => null, 'description' => null, 'author' => null]], ['actionCode' => 'SIGNUP', 'categories' => ['foo', 'bar']]]], $request); }
/** * Performs an action notification from certain user * * @param User|string $user A User model or userId * @param array $actions array of Action objects or strings * @return void */ public function notifySeveralActions($user, array $actions) { // Prepare request body $requestData = ['userId' => $user instanceof User ? $user->getUserId() : $user, 'actions' => []]; foreach ($actions as $action) { if (is_string($action)) { $actionCode = $action; $action = new Action(); $action->setActionCode($actionCode); } if ($action instanceof Action) { $requestData['actions'][] = $action->toArray(); } } // Perform request $this->connect('POST', self::ACTION_NOTIFY_SEVERAL_ROUTE, ['json' => $requestData]); }