/**
  *
  */
 public function testAdvertiserImages()
 {
     // Download an example image from the internet.
     $test_data = file_get_contents('https://www.drupal.org/sites/all/modules/drupalorg/drupalorg/images/qmark-400x684-2x.png');
     // Save the file to the temporary scheme, let's save it as a .txt so the validation fails...
     $image_file = file_save_data($test_data, 'temporary://test_test_test.txt', FILE_EXISTS_REPLACE);
     $image_file_uri = $image_file->getFileUri();
     // Create an entity and set the image file..
     $entity = Advertiser::create(['advertiser_image' => $image_file_uri]);
     $violations = $entity->validate();
     $this->assertEqual(count($violations), 1, 'Violation found when non-image filename.');
 }
Exemplo n.º 2
0
 /**
  * Saves an advertiser & makes sure the body field is set.
  */
 public function testAdvertiserBody()
 {
     $body = 'A reasonably long chunk of text representing a description of this particular advertiser. A bit like the blurb on the back of a book.';
     // Create an entity.
     $entity = Advertiser::create(['advertiser_body' => $body]);
     // Save it.
     $entity->save();
     // Get the id.
     $id = $entity->id();
     // Load the saved entity.
     $saved_entity = Advertiser::load($id);
     // Get the website address from the website.
     $advertiser_body = $saved_entity->getBody();
     // Check the website field matches.
     $this->assertEqual($body, $advertiser_body, 'Body field successfully set', 'body');
 }