public function testCreate() { // Abort if we use a read only token if (!ACCESS_TOKEN && ACCESS_TOKEN_PERMISSION == 'r') { $this->markTestSkipped('This test need an ACCESS_TOKEN_PERMISSION with read and write permission.'); } $tag = $this->stack->instance('tag', DEFAULT_TAG_ID, false); $filter = $this->stack->instance('filter'); $filter->name = 'Test filter ' . $this->uniqId; $filter->enabled = Filter::ENABLE_HIDDEN; $filter->sort = Filter::SORT_LATEST; $filter->orders = 11; // random number $filter->addTag($tag); $filter->addMedia(Filter::MEDIA_IMAGE); $filter->addMedia(Filter::MEDIA_TEXT); $filter->addNetwork(Stackla::NETWORK_TWITTER); $filter->addNetwork(Stackla::NETWORK_INSTAGRAM); $filter->addNetwork(Stackla::NETWORK_STACKLA); $validations = $filter->validate(); if (count($validations)) { foreach ($validations as $validation) { echo $validation['property'] . " -- " . $validation['message'] . "\n"; } throw new \Exception("invalid properties"); } $res = $filter->create(); if ($res) { $this->assertGreaterThan(0, $filter->id, "Filter created without any ID"); $this->assertEquals(0, count($filter->errors), "Error: " . json_encode($filter->errors)); } if ($filter->id) { $request = new Request($this->credentials, API_HOST, API_STACK); $jsonContent = $request->sendGet('filters/' . $filter->id); $resFilter = json_decode($jsonContent, true); if (count($resFilter['errors'])) { // $this->assertEmpty($resFilter['errors'], sprintf("Filter with ID '%s' is not exist", $filter->id)); } else { // validating all fields $this->assertEquals($filter->name, $resFilter['data']['name'], 'Filter\'s name is different from the post request value'); $this->assertEquals($filter->sort, $resFilter['data']['sort'], 'Filter\'s sorting is different from the post request value'); $this->assertEquals($filter->orders, $resFilter['data']['orders'], 'Filter\'s orders is different from the post request value'); $this->assertEquals($filter->enabled, $resFilter['data']['enabled'], 'Filter\'s enabled is different from the post request value'); $this->assertEquals($filter->media, $resFilter['data']['media'], 'Filter\'s media are different from the post request value'); $this->assertEquals($filter->networks, $resFilter['data']['networks'], 'Filter\'s network are different from the post request value'); } } return $filter; }
public function testCreate() { // Abort if we use a read only token if (!ACCESS_TOKEN && ACCESS_TOKEN_PERMISSION == 'r') { $this->markTestSkipped('This test need an ACCESS_TOKEN_PERMISSION with read and write permission.'); } $tile = $this->stack->instance('tile'); $tile->name = 'Test tile\'s name'; $tile->message = 'Test tile\'s message #testtile ' . date('Y-m-d h:i:s'); $tile->term_id = STACKLA_POST_TERM_ID; $tile->image_url = 'https://scontent-syd2-1.cdninstagram.com/t51.2885-15/e35/14374061_652837251542826_5176014892573917184_n.jpg'; $validations = $tile->validate(); if (count($validations)) { foreach ($validations as $validation) { echo $validation['property'] . " -- " . $validation['message'] . ";\n"; } throw new \Exception("Invalid data for Tile"); } $res = $tile->create(); if ($res) { $this->assertEquals(200, $tile->getResponseCode(), "Need to be 200"); $this->assertNotEmpty($tile->sta_feed_id, "Tile created without any ID"); $this->assertNotEmpty($tile->created_at, "Tile created without any create time"); $this->assertEquals(0, count($tile->errors), "Error: " . json_encode($tile->errors)); } // wait 15 seconds for content to be ingested sleep(15); if ($tile->sta_feed_id) { $request = new Request($this->credentials, API_HOST, API_STACK); $jsonContent = $request->sendGet('tiles/guid:' . $tile->sta_feed_id); if ($jsonContent === false) { $response = $request->getResponse(); $jsonContent = $response->getBody(true); } $resTile = json_decode($jsonContent, true); if (!count($resTile['errors'])) { // $this->assertEmpty($resTile['errors'], sprintf("Tile with ID '%s' is not exist", $tile->sta_feed_id)); } else { // validating all fields $this->assertEquals($tile->name, $resTile['data']['name'], 'Tile\'s name is different from the post request value'); $this->assertEquals($tile->message, $resTile['data']['message'], 'Tile\'s message is different from the post request value'); $this->assertEquals($tile->image_url, $resTile['data']['image_url'], 'Tile\'s image_url is different from the post request value'); } } return $tile; }
public function testCreate() { // Abort if we use a read only token if (!ACCESS_TOKEN && ACCESS_TOKEN_PERMISSION == 'r') { $this->markTestSkipped('This test need an ACCESS_TOKEN_PERMISSION with read and write permission.'); } $tag = $this->stack->instance('Tag'); $tag->tag = 'Test tag ' . $this->uniqId; $tag->slug = 'Test tag slug ' . $this->uniqId; $tag->type = Tag::TYPE_CONTENT; $tag->custom_url = 'http://stackla.com/'; $tag->publicly_visible = Tag::VISIBLE; $validations = $tag->validate(); if (count($validations)) { foreach ($validations as $validation) { echo $validation['property'] . " -- " . $validation['message'] . "\n"; } throw new \Exception("invalid properties"); } $res = $tag->create(); if ($res) { $this->assertGreaterThan(0, $tag->id, "Tag created without any ID"); $this->assertNotEmpty($tag->created_at, "Tag created without any timestamp"); $this->assertEquals(0, count($tag->errors), "Error: " . json_encode($tag->errors)); } if ($tag->id) { $request = new Request($this->credentials, API_HOST, API_STACK); $jsonContent = $request->sendGet('tags/' . $tag->id); $resTag = json_decode($jsonContent, true); if (count($resTag['errors'])) { // $this->assertEmpty($resTag['errors'], sprintf("Tag with ID '%s' is not exist", $tag->id)); } else { // validating all fields $this->assertEquals($tag->type, $resTag['data']['type'], 'Tag\'s type is different from the post request value'); $this->assertEquals($tag->tag, $resTag['data']['tag'], 'Tag\'s name is different from the post request value'); $this->assertEquals($tag->slug, $resTag['data']['slug'], 'Tag\'s slug is different from the post request value'); $this->assertEquals($tag->custom_url, $resTag['data']['custom_url'], 'Tag\'s custom url is different from the post request value'); } } return $tag; }
public function testCreate() { // Abort if we use a read only token if (!ACCESS_TOKEN && ACCESS_TOKEN_PERMISSION == 'r') { $this->markTestSkipped('This test need an ACCESS_TOKEN_PERMISSION with read and write permission.'); } $widget = $this->stack->instance('Widget'); $widget->name = 'Test widget ' . $this->uniqId; $widget->type_style = Widget::STYLE_BASE_WATERFALL; $widget->filter_id = (int) DEFAULT_FILTER_ID; $validations = $widget->validate(); if (count($validations) > 0) { foreach ($validations as $val) { echo $val['property'] . " -- " . $val['message']; echo ";\n"; } } $res = $widget->create(); if ($res) { $this->assertGreaterThan(0, $widget->id, "Widget created without any ID"); $this->assertEquals(0, count($widget->errors), "Error: " . json_encode($widget->errors)); } if ($widget->id) { $request = new Request($this->credentials, API_HOST, API_STACK); $jsonContent = $request->sendGet('widgets/' . $widget->id); $resWidget = json_decode($jsonContent, true); if (count($resWidget['errors'])) { // $this->assertEmpty($resWidget['errors'], sprintf("Widget with ID '%s' is not exist", $widget->id)); } else { // validating all fields $this->assertEquals($widget->type, $resWidget['data']['style']['type'], 'Widget\'s type is different from the post request value '); $this->assertEquals($widget->type_style, $resWidget['data']['style']['style'], 'Widget\'s type style is different from the post request value'); $this->assertEquals($widget->name, $resWidget['data']['style']['name'], 'Widget\'s name is different from the post request value'); $this->assertEquals($widget->filter_id, $resWidget['data']['filter_id'], 'Widget\'s filter id is different from the post request value'); } } return $widget; }
public function getResponseCode() { return $this->request->status(); }
public function testCreateFacebookTerm() { // Abort if we use a read only token if (!ACCESS_TOKEN && ACCESS_TOKEN_PERMISSION == 'r') { $this->markTestSkipped('This test need an ACCESS_TOKEN_PERMISSION with read and write permission.'); } $term = $this->stack->instance('term'); $term->name = 'Test user type term'; $term->display_name = 'Test user term'; $term->active = 1; $term->num_of_backfill = 0; $term->term = 'CNCASYum'; $term->type = Term::TYPE_USER; $term->filter = ''; $term->network = Stackla::NETWORK_FACEBOOK; $res = $term->create(); if ($res) { $this->assertGreaterThan(0, $term->id, "Term created without any ID"); // $this->assertNotEmpty($term->created, "Term created without any create time"); $this->assertEquals(0, count($term->errors), "Error: " . json_encode($term->errors)); } if ($term->id) { $request = new Request($this->credentials, API_HOST, API_STACK); $jsonContent = $request->sendGet('terms/' . $term->id); if ($jsonContent === false) { $response = $request->getResponse(); $jsonContent = $response->getBody(true); } $resTerm = json_decode($jsonContent, true); if (!count($resTerm['errors'])) { // $this->assertEmpty($resTerm['errors'], sprintf("Term with ID '%s' is not exist", $term->id)); } else { // validating all fields $this->assertEquals($term->source_user_id, $resTerm['data']['source_user_id'], 'Term\'s source_user_id is different from the post request value'); $this->assertEquals($term->term, $resTerm['data']['term'], 'Term\'s term is different from the post request value'); $this->assertEquals($term->network, $resTerm['data']['network'], 'Term\'s network is different from the post request value'); $this->assertEquals($term->filter, $resTerm['data']['filter'], 'Term\'s filter is different from the post request value'); $this->assertEquals($term->display_name, $resTerm['data']['displat_name'], 'Term\'s display name is different from the post request value'); $this->assertEquals($term->type, $resTerm['data']['type'], 'Term\'s type is different from the post request value'); $this->assertEquals($term->name, $resTerm['data']['name'], 'Term\'s name is different from the post request value'); } $term->delete(); } }