- <?php
- * @file
- * SimpleTests for dbtng_example module.
- */
-
- * Default test case for the dbtng_example module.
- *
- * @ingroup dbtng_example
- */
- class DBTNGExampleUnitTestCase extends BackdropWebTestCase {
-
-
- * {@inheritdoc}
- */
- public function setUp() {
- parent::setUp('dbtng_example');
- }
-
-
- * Test default module installation, two entries in the database table.
- */
- public function testInstall() {
- $result = dbtng_example_entry_load();
- $this->assertEqual(
- count($result),
- 2,
- 'Found two entries in the table after installing the module.'
- );
- }
-
-
-
- * Test the UI.
- */
- public function testUI() {
-
- $this->backdropGet('examples/dbtng');
- $this->assertPattern("/John[td\/<>\w]+Doe/", "Text 'John Doe' found in table");
-
-
-
- $this->backdropPost('examples/dbtng/add',
- array(
- 'name' => 'Some',
- 'surname' => 'Anonymous',
- 'age' => 33,
- ),
- t('Add')
- );
- cache('page')->flush();
-
- $this->backdropGet('examples/dbtng');
- $this->assertPattern("/Some[td\/<>\w]+Anonymous/", "Text 'Some Anonymous' found in table");
-
-
-
- $result = dbtng_example_entry_load(array('surname' => 'Anonymous'));
- $this->backdropGet("examples/dbtng");
- $this->assertEqual(
- count($result),
- 1,
- 'Found one entry in the table with surname = "Anonymous".'
- );
- $entry = $result[0];
- unset($entry->uid);
- $entry->name = 'NewFirstName';
- $this->backdropPost('examples/dbtng/update', (array) $entry, t('Update'));
- cache('page')->flush();
-
- $this->backdropGet('examples/dbtng');
- $this->assertPattern("/NewFirstName[td\/<>\w]+Anonymous/", "Text 'NewFirstName Anonymous' found in table");
-
-
- $this->backdropGet('examples/dbtng/advanced');
- $rows = $this->xpath("//*[contains(@class, 'l-content')]/table[1]/tbody/tr");
- $this->assertEqual(count($rows), 1, "One row found in advanced view");
- $this->assertFieldByXPath("//*[contains(@class, 'l-content')]/table[1]/tbody/tr/td[4]", "Roe", "Name 'Roe' Exists in advanced list");
- }
-
-
- * Test several combinations, adding entries, updating and deleting.
- */
- public function testAPIExamples() {
-
- $entry = array(
- 'name' => 'James',
- 'surname' => 'Doe',
- 'age' => 23,
- );
- dbtng_example_entry_insert($entry);
-
-
- $entry = array(
- 'name' => 'Jane',
- 'surname' => 'NotDoe',
- 'age' => 19,
- );
- dbtng_example_entry_insert($entry);
-
-
- $result = dbtng_example_entry_load();
- $this->assertEqual(
- count($result),
- 4,
- 'Found a total of four entries in the table after creating two additional entries.'
- );
-
-
- $result = dbtng_example_entry_load(array('surname' => 'Doe'));
- $this->assertEqual(
- count($result),
- 2,
- 'Found two entries in the table with surname = "Doe".'
- );
-
-
- $result = dbtng_example_entry_load(array('surname' => 'NotDoe'));
- $this->assertEqual(
- count($result),
- 1,
- 'Found one entry in the table with surname "NotDoe');
-
- $entry = $result[0];
- $entry->surname = "NowDoe";
- dbtng_example_entry_update((array) $entry);
-
- $result = dbtng_example_entry_load(array('surname' => 'NowDoe'));
- $this->assertEqual(
- count($result),
- 1,
- "Found renamed 'NowDoe' surname");
-
-
- $result = dbtng_example_entry_load(array('name' => 'John', 'surname' => 'Doe'));
- $this->assertEqual(
- count($result),
- 1,
- 'Found one entry for John Doe.'
- );
-
- $entry = (array) end($result);
-
- $entry['age'] = 45;
-
- dbtng_example_entry_update((array) $entry);
-
-
-
- $result = dbtng_example_entry_load(array('surname' => 'NowDoe'));
- $this->assertEqual(
- count($result),
- 1,
- 'Found one entry with surname = Nowdoe.'
- );
-
-
- $entry = (array) end($result);
- $this->assertEqual(
- $entry['name'],
- 'Jane',
- 'The name Jane is found in the entry'
- );
- $this->assertEqual(
- $entry['surname'],
- 'NowDoe',
- 'The surname NowDoe is found in the entry'
- );
-
-
- dbtng_example_entry_delete($entry);
-
-
- $result = dbtng_example_entry_load();
- $this->assertEqual(
- count($result),
- 3,
- 'Found only three records, a record was deleted.'
- );
- }
- }