Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add tests for JTableLanguage

  • Loading branch information...
commit 0628339ce71920ba84cf23d5ba486480c7ead966 1 parent 4686e89
@mbabker mbabker authored
View
6 tests/schema/ddl.sql
@@ -175,10 +175,16 @@ CREATE TABLE `jos_languages` (
`description` TEXT NOT NULL DEFAULT '',
`metakey` TEXT NOT NULL DEFAULT '',
`metadesc` TEXT NOT NULL DEFAULT '',
+ `sitename` varchar(1024) NOT NULL default '',
`published` INTEGER NOT NULL DEFAULT '0',
+ `ordering` int(11) NOT NULL default '0',
CONSTRAINT `idx_languages_sef` UNIQUE (`sef`)
+ CONSTRAINT `idx_languages_image` UNIQUE (`image`)
+ CONSTRAINT `idx_languages_lang_code` UNIQUE (`lang_code`)
);
+CREATE INDEX `idx_languages_ordering` ON `jos_languages` (`ordering`);
+
-- --------------------------------------------------------
--
View
99 tests/suites/unit/joomla/table/JTableLanguageTest.php
@@ -13,25 +13,106 @@
* Test class for JTableLanguage.
* Generated by PHPUnit on 2011-12-06 at 03:29:18.
*/
-class JTableLanguageTest extends PHPUnit_Framework_TestCase
+class JTableLanguageTest extends TestCaseDatabase
{
/**
- * @covers JTableLanguage::check
- * @todo Implement testCheck().
+ * @var JTableLanguage
+ */
+ protected $object;
+
+ /**
+ * Sets up the fixture, for example, opens a network connection.
+ * This method is called before a test is executed.
+ */
+ protected function setUp()
+ {
+ parent::setUp();
+
+ // Get the mocks
+ $this->saveFactoryState();
+
+ JFactory::$session = $this->getMockSession();
+
+ $this->object = new JTableLanguage(self::$driver);
+ }
+
+ /**
+ * Tears down the fixture, for example, closes a network connection.
+ * This method is called after a test is executed.
+ */
+ protected function tearDown()
+ {
+ $this->restoreFactoryState();
+
+ parent::tearDown();
+ }
+
+ /**
+ * Gets the data set to be loaded into the database during setup
+ *
+ * @return CSV database tables
+ *
+ * @since 12.1
+ */
+ protected function getDataSet()
+ {
+ $dataSet = new PHPUnit_Extensions_Database_DataSet_CsvDataSet(',', "'", '\\');
+
+ $dataSet->addTable('jos_languages', __DIR__ . '/stubs/jos_languages.csv');
+
+ return $dataSet;
+ }
+
+ /**
+ * Tests JTableLanguage::check
+ *
+ * @return void
+ *
+ * @since 12.1
*/
public function testCheck()
{
- // Remove the following lines when you implement this test.
- $this->markTestIncomplete('This test has not been implemented yet.');
+ $table = $this->object;
+
+ $this->assertThat(
+ $table->check(),
+ $this->isFalse(),
+ 'Line: '.__LINE__.' Checking an empty table should fail.'
+ );
+
+ $table->title = 'English (UK)';
+ $this->assertThat(
+ $table->check(),
+ $this->isTrue(),
+ 'Line: '.__LINE__.' The check function should complete without issue.'
+ );
}
/**
- * @covers JTableLanguage::store
- * @todo Implement testStore().
+ * Tests JTableLanguage::store
+ *
+ * @return void
+ *
+ * @since 12.1
*/
public function testStore()
{
- // Remove the following lines when you implement this test.
- $this->markTestIncomplete('This test has not been implemented yet.');
+ $table = $this->object;
+
+ // Store a new language
+ $table->lang_id = null;
+ $table->title = 'English (US)';
+ $table->title_native = 'English (US)';
+ $table->sef = 'en';
+ $this->assertFalse($table->store(), 'Line: ' . __LINE__ . ' Table store should fail due to a duplicated sef field.');
+ $table->sef = 'us';
+ $table->image = 'en';
+ $this->assertFalse($table->store(), 'Line: ' . __LINE__ . ' Table store should fail due to a duplicated image field.');
+ $table->image = 'us';
+ $table->lang_code = 'en-GB';
+ $this->assertFalse($table->store(), 'Line: ' . __LINE__ . ' Table store should fail due to a duplicated lang_code field.');
+ $table->lang_code = 'en-US';
+ $this->assertTrue($table->store(), 'Line: ' . __LINE__ . ' Table store should successfully insert a record for English (US).');
}
+
}
View
2  tests/suites/unit/joomla/table/stubs/jos_languages.csv
@@ -0,0 +1,2 @@
+'lang_id','lang_code','title','title_native','sef','image','description','metakey','metadesc','sitename','published','ordering'
+'1','en-GB','English (UK)','English (UK)','en','en','','','','','1','1'
Please sign in to comment.
Something went wrong with that request. Please try again.